function isValidImage(imagename)
{
imagefile_value = imagename;
var checking = imagefile_value.toLowerCase();
if (!checking.match(/(\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG|\.jpeg|\.JPEG)$/))
{
return false;
}
else
{
return true;
}
}
Pages
Tuesday, August 28, 2012
Javascript Image Validation
Dummy Data Generator tool
GenerateData is a free, open source script written in JavaScript, PHP and MySQL that lets you quickly generate large volumes of custom data in a variety of formats for use in testing software, populating databases.
Datagenerator
Datagenerator is a library and GUI for generating rule based test data for various databases like Mysql, Firebird, Interbase, MSSQL, Oracle, SQLite and PostgreSQL.
dgMaster
Data generator tool which supports many data types (primitive data types,but also names,addresses,post codes,etc.) and generates data in various formats (text,xml,db).It provides a GUI and is extensible by means of plugging-in new data-generator classes.
Spawner Data Generator
Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
DBMonster
DBMonster is a tool that generates random test data and inserts it into SQL database.
Sunday, August 26, 2012
for each statements with arrays in php
$birds= array('Parrots' =>
array('Kakapo','Kea ','Vernal Hanging Parrot'),
'Cuckoos and Turacos'=>
array('Purple-crested Turaco','Grey Go-away-bird','Great Blue Turaco'));
//display all
print_r($birds);
//for new line
echo '<br><br><br>';
// with foreach() display only main array
foreach($birds as $category => $sub){
echo '<b>'.$category.'<br></b>';
}
//for new line
echo '<br><br>';
// with foreach() display main array and sub arrays
foreach($birds as $category => $sub1){
echo '<b>'.$category.'<br></b>';
foreach($sub1 as $sub2)
echo $sub2.'<br>';
}
?>
output ;
Array ( [Parrots] => Array ( [0] => Kakapo [1] => Kea [2] => Vernal Hanging Parrot ) [Cuckoos and Turacos] => Array ( [0] => Purple-crested Turaco [1] => Grey Go-away-bird [2] => Great Blue Turaco ) )
Parrots
Cuckoos and Turacos
Parrots
Kakapo
Kea
Vernal Hanging Parrot
Cuckoos and Turacos
Purple-crested Turaco
Grey Go-away-bird
Great Blue Turaco
Saturday, August 25, 2012
Image-Resize class for PHP
To use, just include image.class.php to your PHP file or where you are using resizing function. Then create new variable with an iresize() class object then use functions which comes with Image-resize class.
Example usage;
<?php
require "image.class.php";
$resize = new iresize();
$resize->img("test.jpg")->size("500x500")->render("test-resized.jpg");
?>
Explaination;
iresize->img($source_filename) is where we are loading image to resize
->size("500x500") is for entering desired image size
->render("test-resized.jpg") is for final result. emptry/filename with extension
Download / Source
PHP comments
Friday, August 24, 2012
Propel NestedSet inheritance problem
Fatal error: Uncaught exception 'PropelException' with message 'Call to undefined method: makeRoot' in /usr/share/php/propel/om/BaseObject.php:325
You need to replace inheritance classes for nested set. In your model class, find and replace.
class Contents extends BaseContents
with this
class Contents extends BaseContentsNestedSet
also find and replace
class ContentsPeer extends BaseContentsPeer
with this
class ContentsPeer extends BaseContentsNestedSetPeer
You are now good to go.
Thursday, August 23, 2012
crack facebook password facebook
BTW, I found another website which is providing for free a free facebook hacking software and other one specialized in hack into someone's facebook password, hack facebook account id number.
Jordan N. Wilson, New York
US
Related articles:
crack facebook password facebook
Contact Us
Removing Cache from the page
1. Using the PHP Header. Use the following code before rendering any output to the browser.
<?php
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header("Cache-Control: post-check=0, pre-check=0", false);
header('Pragma: no-cache');
header('Expires: Mon,26 Jul 1980 05:00:00 GMT');
header("Last-Modified: Tue,01 Jan 2000 00:00:00 GMT");
?>
2. Using the HTML Meta tag.
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Monday, August 20, 2012
Java Script Page Loading....
set Cookies in php
/*
symtax:
setcookie(name, value, expire, path, domain);
*/
//it expires after 5 seconds
setcookie("user", "human", time()+5);
//it expires after 60 sec or 1 min
setcookie("user", "human", time()+60);
//it expires after 3600 sec or 1 hour
setcookie("user", "human", time()+3600);
//expire using varable
//it expires after 10 seconds
$time=10;
setcookie("visitor", "humans", time()+$time);
// note : normally "echo" not use in "setcookies" file
?>
output :
note :
1)no output display here
Sunday, August 19, 2012
associative arrays in php
$alphabate=array('A'=>'APPLE','a'=>'apple','B'=>'BALL','b'=>'ball','C'=>'CAT','c'=>'cat','D'=>'DOLL','d'=>'doll','E'=>'ELEPHANT','e'=>'elephant');
print_r($alphabate);
// '<BR>' USE FOR NEW LINE
// 'A' is not equal to 'a' in arrays index
// '.' use for concatenation
echo '<br><br><br>'.
$alphabate['A'].'<br>';
echo $alphabate['a'].'<br>';
echo $alphabate['B'].'<br>';
echo $alphabate['b'].'<br>';
echo $alphabate['C'].'<br>';
echo $alphabate['c'].'<br>';
echo $alphabate['D'].'<br>';
echo $alphabate['d'].'<br>';
echo $alphabate['E'].'<br>';
echo $alphabate['e'].'<br>';
?>
output :
Array ( [A] => APPLE [a] => apple [B] => BALL [b] => ball [C] => CAT [c] => cat [D] => DOLL [d] => doll [E] => ELEPHANT [e] => elephant )
APPLE
apple
BALL
ball
CAT
cat
DOLL
doll
ELEPHANT
elephant
PHP increment and decrement operators
($x++) Post-increment :It first return $x value and then increment the value of $x.
(--$x) Pre-decrement : It first decrement $x value one and then return the value of $x.
($x--) Post-decrement : It return $x value and then decrement one.
Now we want to see an example that describe how actually works PHP increment and decrement operators.
<?php
$a=20;
echo ++$a;
echo "<br>";
echo $a++;
echo "<br>";
$b=30;
echo --$b;
echo "<br>";
echo $b--;
?>
Output:
21
21
29
29
Thursday, August 16, 2012
FindProxyForURL - Parse a PAC (proxy auto config) file in PHP
Here's a working example of using the php_spidermonkey extension to run a proxy auto config script (javascript) in PHP.
All you need is a PAC file to test it. You can write your own following instructions across the web, here is a guide: http://www.ee.ed.ac.uk/%7Emfg/work/proxy-live.html
There is more information and Windows builds of php_spidermonkey in this article: Javascript in PHP on Windows with php_spidermonkey. Install the extension dll in PHP in the usual way.
Here is a snippet of code that uses the class 'CProxy' (defined underneath) which executes the Javascript PAC function FindProxyForURL:
use DEMO\PAC\CProxy; // namespace, if required.
$proxy = new CProxy();
$proxy->LoadPAC('C:\proxy.pac'); // pac file is usually a URL
$test = $proxy->FindProxyForAddress('http://www.google.com/', true);
echo $test;
/*
Assuming your PAC file contained something like this:
function FindProxyForURL(url, host)
{
if ( shExpMatch(host, "*.google.*") )
{
return "PROXY 10.20.30.40:8000; DIRECT";
}
return "DIRECT";
}
this snippet would print:
PROXY 10.20.30.40:8000; DIRECT
*/
Definition of class CProxy - it utilises and demonstrates some of the following:
- PHP 5.4 - uses namespaces to show how they work in this scenario, and traits.
- php_spidermonkey javascript interpreter
- PAC (proxy-auto-config) functions
<?php
/* This example uses a namespace, just to show how it works inside namespaces.
Namespace can be removed. */
namespace DEMO\PAC;
use \JSContext, \Exception;
if ( !defined('JSVERSION_DEFAULT') )
{
error_log(__FILE__ . 'CProxy not loaded, php_spidermonkey extension not detected!');
return;
}
// global function to escape javascript strings: function js($str, $quotes = '\'"')
{
return addcslashes($str,"\\$quotes\n\r<>");
}
class CProxy
{
use PACFunctions; // include traits in this class, defined below.
private $pac, $js, $proxyconfig;
function __construct($pacfile=NULL, $strictJavascript=false)
{
// requires php_spidermonkey.dll extension.
$js = new JSContext();
if ( $strictJavascript )
{
$opts = $js->getOptions() | JSOPTION_STRICT | JSOPTION_WERROR;
$prev = $js->setOptions($opts);
}
$js->registerFunction(__NAMESPACE__.'\CProxy::myIpAddress', 'myIpAddress');
$js->registerFunction(__NAMESPACE__.'\CProxy::isPlainHostName', 'isPlainHostName');
$js->registerFunction(__NAMESPACE__.'\CProxy::dnsDomainIs', 'dnsDomainIs');
$js->registerFunction(__NAMESPACE__.'\CProxy::localHostOrDomainIs', 'localHostOrDomainIs');
$js->registerFunction(__NAMESPACE__.'\CProxy::isResolvable', 'isResolvable');
$js->registerFunction(__NAMESPACE__.'\CProxy::isInNet', 'isInNet');
$js->registerFunction(__NAMESPACE__.'\CProxy::dnsResolve', 'dnsResolve');
$js->registerFunction(__NAMESPACE__.'\CProxy::dnsDomainLevels', 'dnsDomainLevels');
$js->registerFunction(__NAMESPACE__.'\CProxy::shExpMatch', 'shExpMatch');
$js->registerFunction(__NAMESPACE__.'\CProxy::weekdayRange', 'weekdayRange');
$js->registerFunction(__NAMESPACE__.'\CProxy::dateRange', 'dateRange');
$js->registerFunction(__NAMESPACE__.'\CProxy::timeRange', 'timeRange');
// I don't know what ProxyConfig is used for:
$this->proxyconfig = new \stdClass();
$this->proxyconfig->bindings = array();
$js->assign('ProxyConfig', $this->proxyconfig);
$this->js = $js;
$this->LoadPAC($pacfile);
}
function FindProxyForAddress($address, $raw=false)
{
/* returns an array of proxy servers
(from preg_match_all),
or, if $raw is true, returns
the original string returned by
FindProxyForURL function. */
if ( !$this->pac )
return false;
$parts = parse_url($address);
$url = $address;
if ( !isset($parts['port']) )
{
$port = '';
}
else if ( ($port=$parts['port']) )
{
$port = ':' . $port;
}
if ( !isset($parts['host']) )
{
/* $address is badly formed, not sure if this is right, but
* return it from the beginning to the first slash. */
if ( !isset($parts['path']) )
return false;
$parts['host'] = preg_replace('/(.*?)(?>\/.*$|$)/', '$1', $parts['path']);
}
$host = $parts['host'] . $port;
try
{
if ( !($rv=$this->js->evaluateScript('FindProxyForURL(\'' . js($url) . '\', \'' . js($host) . '\');', 'FindProxyForURL')) || $raw )
{
return $rv;
}
}
catch ( Exception $ex )
{
return false;
}
return self::ReadPacResult($rv);
}
function LoadPAC($pac)
{
if ( $this->pac )
{
return NULL; // already loaded
}
if ( $pac === NULL || !$this->js )
{
return false; // param error or not initialised properly
}
if ( !($script = file_get_contents($pac)) )
{
return false; // cannot read PAC file
}
try
{
$rv = $this->js->evaluateScript($script, $pac);
}
catch ( Exception $ex )
{
return false;
}
$this->pac = $script;
return true;
}
public static function ReadPacResult($pacres)
{
if ( !$pacres )
return false;
// $pacres should be something like
// PROXY 1.2.3.4:8080; PROXY 1.2.3.5:8080; DIRECT
if ( !preg_match_all('/(PROXY|SOCKS|DIRECT)\s*([^;]*|.*?$)/ui', $pacres, $matches, PREG_SET_ORDER) )
{
return false;
}
return $matches;
}
}
?>
<?php
/* Define the PAC traits used in class CProxy, above. */
namespace DEMO\PAC;
use \DateTime, \DateTimeZone, \Exception;
trait PACFunctions
{
private static $s_myIP;
/*
* PAC functions:
* 'global' functions to replicate javascript PAC environment...
*/
static function myIpAddress()
{
if ( self::$s_myIP )
{
return self::$s_myIP;
}
$vars = array('SERVER_ADDR', 'LOCAL_ADDR');
$ip = NULL;
$bestip = '0.0.0.0';
foreach ( $vars as $var )
{
if ( isset($_SERVER[$var]) )
{
$ip = $_SERVER[$var];
if ( !empty($ip) )
{
if ( $ip != '127.0.0.1' )
{
return (self::$s_myIP = $ip);
}
$bestip = $ip;
}
}
}
if ( ($hn = gethostname()) && ($ip = gethostbyname($hn)) && $ip !== $hn )
{
return (self::$s_myIP=$ip);
}
return (self::$s_myIP=$bestip);
}
static function isPlainHostName( $host )
{
return strpos($host, '.')===false;
}
static function shExpMatch($host, $pattern)
{
$parts = explode('*', $pattern);
$pattern = '';
foreach( $parts as $part )
{
if ( $part === '' )
{
$pattern .= '.*?';
}
else
{
$pattern .= preg_quote($part, '/');
}
}
return preg_match('/^'.$pattern.'$/ui', $host)===1;
}
static function isResolvable($host)
{
if ( ip2long($host) !== false )
{
return true;
}
$test = gethostbyname($host);
return $test && ip2long($test) !== false;
}
static function isInNet($host, $ip, $subnet)
{
if ( ($longhost = ip2long($host)) === false )
{
$host = gethostbyname($host);
if ( ($longhost = ip2long($host))===false )
{
return false;
}
}
$longip = ip2long($ip);
$longsub = ip2long($subnet);
return ($longhost&$longsub) == $longip;
}
static function dnsDomainIs($host, $domain)
{
$len = strlen($domain);
return $len <= strlen($host) && substr($host, -$len)==$domain;
}
static function localHostOrDomainIs($host, $domain)
{
return strcasecmp($domain, substr($host, 0, strlen($domain)))===0;
}
static function dnsResolve($host)
{
return gethostbyname($host);
}
static function dnsDomainLevels($host)
{
return substr_count($host, '.');
}
static function weekdayRange($fr, $to=NULL, $gmt=NULL)
{
$days = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
$fr = strtolower(substr($fr,0,3));
if ( $gmt )
$gmt = strtoupper($gmt);
if ( $to === NULL )
$to = $fr;
else if ( strcasecmp($to, 'GMT')==0 )
{
$to = $fr;
$gmt = 'GMT';
}
else
$to = strtolower(substr($to,0,3));
if ( $gmt == 'GMT' )
{
$tzn = 'UTC';
}
else if ( !($tzn = ini_get('date.timezone')) )
{
$tzn = 'Europe/London';
}
$tz = new DateTimeZone($tzn);
$today = strtolower( (new DateTime('now',$tz))->format('D') );
foreach ( $days as $wd=>$day )
{
if ( $fr == $day )
$fr = $wd+1;
if ( $to == $day )
$to = $wd+1;
if ( $today == $day )
$today = $wd+1;
}
if ( !(int)$today || !(int)$fr || !(int)$to )
return false;
// FRI = 5
// MON = 1
// THU = 4
// is THU in FRI - MON ??
if ( $fr > $to )
{
return $today >= $fr || $today <= $to;
}
return $today >= $fr && $today <= $to;
}
static function dateRange($day1, $month1=NULL, $year1=NULL, $day2=NULL, $month2=NULL, $year2=NULL, $gmt=NULL)
{
$args = array($day1, $month1, $year1, $day2, $month2, $year2, $gmt);
$RationaliseArgs = function(&$arg)
{
$isgmt = 0;
for ( $ct=0 ; $ct < 6 ; $ct += 3 )
{
if ( (int)$arg[$ct] > 31 )
{
// 1st arg is a year, insert blank day and month
array_splice($arg, $ct, 0, array(0,''));
}
else if ( (int)$arg[$ct] )
{
// 1st arg is day
if ( (int)$arg[$ct+1] )
{
// 2nd arg must be a day. 2nd arg can't be year if 1st arg is a day.
array_splice($arg, $ct+1, 0, array('',0)); // insert blank month and year
}
else if ( $arg[$ct+1]===NULL || strcasecmp($arg[$ct+1], 'GMT')==0 )
{
// nothing else after the day.
array_splice($arg, $ct+1, 0, array('',0)); // insert blank month and year.
}
else if ( (int)$arg[$ct+2] && (int)$arg[$ct+2] <= 31 ) // month supplied, test what's after month
{
// month followed by day... insert blank year...
array_splice($arg, $ct+2, 0, array(0)); // insert empty year1 and shift arg2 to 2nd date.
}
}
else if ( is_string($arg[$ct]) )
{
if ( strcasecmp($arg[$ct], 'GMT')==0 )
{
if ( !$ct )
{
return false; // error, 1st arg cannot be 'GMT'.
}
break;
}
// 1st arg is month
array_splice($arg, $ct, 0, array(0)); // insert a blank day.
if ( (int)$arg[$ct+2] <= 31 ) // month not followed by a year
{
// insert a blank year...
array_splice($arg, $ct+2, 0, array(0));
}
}
else
{
if ( $ct && $arg[$ct] === NULL ) // only 1 date supplied. ok.
return 1;
return false; // error
}
}
if ( strcasecmp($arg[$ct], 'GMT')==0 )
{
$isgmt = 1;
$arg[$ct] = 'GMT';
}
array_splice($arg, 7);
return $ct/3;
};
if ( !($cd = $RationaliseArgs($args, $gmt)) )
{
return false;
}
list($day1, $month1, $year1, $day2, $month2, $year2, $gmt) = $args;
if ( $gmt == 'GMT' )
{
$tzn = 'UTC';
}
else if ( !($tzn = ini_get('date.timezone')) )
{
$tzn = 'Europe/London';
}
$tz = new DateTimeZone($tzn);
$now = new DateTime('now',$tz);
$thisyear = $now->format('Y');
$thismonth = 'Jan'; // a month with 31 days.
$thisday = $now->format('d');
try
{
$from = new \DateTime(($year1 ? $year1 : $thisyear) . '-' . ($month1 ? $month1 : $thismonth) . '-' . ($day1 ? $day1 : $thisday), $tz);
if ( !$day1 )
$day2 = 0;
if ( !$month1 )
$month2 = '';
if ( !$year1 )
$year2 = 0;
if ( $day2 || $month2 || $year2 )
{
$to = new \DateTime(($year2 ? $year2 : $thisyear) . '-' . ($month2 ? $month2 : $thismonth) . '-' . ($day2 ? $day2 : $thisday), $tz);
}
else
$to = NULL;
}
catch ( Exception $ex )
{
return false; // data error, an arg is incorrect
}
$dateformat = ($year1 ? 'Y' : '') . ($month1 ? 'm' : '') . ($day1 ? 'd' : '');
$test = $now->format($dateformat);
$lhs = $from->format($dateformat);
if ( !$to )
{
return $test == $lhs;
}
$rhs = $to->format($dateformat);
if ( $rhs < $lhs && $dateformat{0} != 'Y' )
{
return $test >= $lhs || $test <= $rhs;
}
return $test >= $lhs && $test <= $rhs;
}
static function timeRange($hour1, $min1=NULL, $sec1=NULL, $hour2=NULL, $min2=NULL, $sec2=NULL, $gmt=NULL)
{
$args = array($hour1, $min1, $sec1, $hour2, $min2, $sec2, $gmt);
for ( $ct=0 ; $ct < count($args) && $args[$ct] !== NULL && strcasecmp($args[$ct], 'GMT') ; ++$ct ) ;
if ( !$ct )
return false; // arg error
if ( ($gmt = (strcasecmp($args[$ct], 'GMT')==0)) )
{
$tzn = 'UTC';
}
else if ( !($tzn = ini_get('date.timezone')) )
{
$tzn = 'Europe/London';
}
$tz = new DateTimeZone($tzn);
$now = new DateTime('now',$tz);
/* $ct is the number of args (excluding any 'GMT' value).
* if 6 args supplied, full time specified, else... */
if ( $ct == 4 ) // range of hours+minutes
{
// hour and minute supplied
$min2 = $hour2;
$hour2 = $sec1;
$sec1 = $sec2 = 0;
$fmt = 'Hi';
}
else if ( $ct < 3 ) // range of hours (1 or 2)
{
$hour2 = ($ct==2 ? $min1 : $hour1);
$min1 = $sec1 = $min2 = $sec2 = 0;
$fmt = 'H';
}
else if ( $ct == 6 )
{
$fmt = 'His';
}
else
{
return false; // parameters not specified properly
}
try
{
$lhs = new \DateTime( ($dt=$now->format('Y-m-d')) . ' ' . (int)$hour1 . ':' . (int)$min1 . ':' . $sec1, $tz);
$rhs = (( $ct == 1 ) ? NULL : new \DateTime( $dt . ' ' . (int)$hour2 . ':' . (int)$min2 . ':' . $sec2, $tz));
}
catch ( Exception $ex )
{
// datetime not recognised, so parameter probably out of range
return false;
}
$nowtime = $now->format($fmt);
$ltime = $lhs->format($fmt);
if ( $rhs === NULL )
{
return $nowtime == $ltime;
}
$rtime = $rhs->format($fmt);
if ( $ltime > $rtime )
{
return $nowtime >= $ltime || $nowtime <= $rtime;
}
return $nowtime >= $ltime && $nowtime <= $rtime;
}
}
?>Saturday, August 11, 2012
ADODB with PHP and oracle
An example to connect php with oracle using ADODB library is as follows.
include"/path/to/adodb.inc.php";The Execute( ) function returns a recordset object, and you can retrieve the rows returned using $recordset->FetchRow( ).
$db = NewADOConnection("oci8");
$db->Connect($tnsName, "scott", "tiger");
$rs = $db->Execute("select * from emp where empno>:emp order by empno",
array('emp' => 7900));
while ($arr = $rs->FetchRow())
{
print_r($arr);
}
You can also query the database using the standard Microsoft ADO MoveNext( ) metaphor. The data array for the current row is stored in the fields property of the recordset object, $rs. MoveNext( ) offers the highest performance among all the techniques for iterating through a recordset:
$rs = $db->Execute("select * from emp where empno>:emp", array('emp' => 7900));
while (!$rs->EOF) {
print_r($rs->fields);
$rs->MoveNext();
}
For easy pagination support, we provide the SelectLimit function. The following will perform a select query, limiting it to 100 rows, starting from row 201 (row 1 being the 1st row):
$offset = 200; $limitrows = 100;
$rs = $db->SelectLimit('select * from table', $limitrows, $offset);
Caching
You can define a database cache directory using $ADODB_CACHE_DIR, and cache the results of frequently used queries that rarely change. This is particularly useful for SQL with complex where clauses and group-by's and order-by's. It is also good for relieving heavily-loaded database servers.The following example will cache the following select statement for 7200 seconds
$ADODB_CACHE_DIR = '/var/tmp';Using Prepare statements
$rs = $db->CacheExecute(7200, "select names from allcountries order by 1");
Prepare( ) is for compiling frequently used SQL statement for reuse. For example, suppose we have a large array which needs to be inserted into an Oracle database. The following will result in a massive speedup in query execution (at least 20-40%), as the SQL statement only needs to be compiled once:
