0 )
if( strcmp($t,substr(date("G:i:s"),0,strlen($t))) == 0 ||
strcmp($t,substr(date("H:i:s"),0,strlen($t))) == 0 )
return true;
}
return false;
}
//-----------------------------------------------------
// InsertDate()
// - - - - - -
// Prints the current date.
//
// $offset - Hours difference between the displayed
// date and the web server's date.
// $format - "SHORT" or "LONG".
//-----------------------------------------------------
function InsertDate($offset=0, $format="long")
{
$kHour = 60*60;
if( strcasecmp($format,"long") == 0 )
print date("l, F j, Y",time()+$offset*$kHour);
else
print date("m/d/y",time()+$offset*$kHour);
}
//-----------------------------------------------------
// ShowDate($begin,$end)
// - - - - - - - -
// Returns true if the current date and time is after
// or including $begin and before $end.
//
// Both $begin and $end should be formatted as:
// "m/d/y[@H[:i[:s]]]"
//
// If $begin equals 0 or "*", the function returns true
// if the current date is before $end.
//
// If $end equals 0 or "*", the function returns true
// if the current date is after $begin.
//
//
// Example: ShowDate("1/1/00","1/1/01") returns true
// during the year 2000.
//-----------------------------------------------------
function ShowDate( $begin, $end = 0 )
{
if( $end == 0 )
{
$list = explode(" ",trim($begin));
$begin = $list[0];
$end = $list[sizeof($list)-1];
if( $end == "" )
$end = 0;
}
$list = array( "begin", "end" );
while( list($key,$value) = each($list) )
{
if( is_string( $$value ) && strcmp($$value,"*") != 0 )
{
list($date,$time) = explode("@",$$value);
list($month,$day,$year) = explode("/",$date);
list($hour,$min,$sec) = explode(":",$time);
$$value = mktime($hour,$min,$sec,$month,$day,$year<80 ? 2000+$year : $year);
}
else if( is_string( $$value ) && strcmp($$value,"*") == 0 )
$$value = 0;
}
return( $begin <= time() && ($end == 0 || time() < $end) );
}
//-----------------------------------------------------
// HideDate($begin,$end)
// - - - - - - - -
// Returns false if the $begin <= current date < $end.
//
// See: ShowDate().
//-----------------------------------------------------
function HideDate( $begin, $end )
{
return !ShowDate($begin,$end);
}
//-----------------------------------------------------
// InsertCountdown($dateTime)
// - - - - - - - -
// Prints the number of weeks, days, hours, and minutes
// between the current time() and $dateTime.
//
// $dateTime should be formatted as:
// "m/d/y[@H[:i[:s]]]"
//
// Example: Countdown to Halloween Festivities!
// InsertCountdown("10/31/2000@19:30")
//-----------------------------------------------------
//function InsertCountdown( $dateTime, $sWeek = "Week",
// $sDay = "Day",
// $sHour = "Hour",
// $sMin = "Minute",
// $sSec = "" )
//{
// print Countdown( $dateTime, $sWeek, $sDay, $sHour, $sMin, $sSec );
//}
//-----------------------------------------------------
// Countdown($dateTime)
// - - - - - - - -
// Returns a string representing the difference between
// the current time and the input time.
//
// $dateTime should be formatted as:
// "m/d/y[@H[:i[:s]]]"
//
// Example: Countdown to Halloween Festivities!
// InsertCountdown("10/31/2000@19:30")
//-----------------------------------------------------
function InsertCountdown( $dateTime, $sWeek = "Week",
$sDay = "Day",
$sHour = "Hour",
$sMin = "Minute",
$sSec = "" )
{
$kSec = 1;
$kMin = 60*$kSec;
$kHour = 60*$kMin;
$kDay = 24*$kHour;
$kWeek = 7*$kDay;
list($date,$time) = explode("@",$dateTime);
list($month,$day,$year) = explode("/",$date);
list($hour,$min,$sec) = explode(":",$time);
$inTime = mktime($hour,$min,$sec,$month,$day,$year<80 ? 2000+$year : $year);
$time_difference = abs(time()-$inTime);
$weeks = ( empty($sWeek) ? 0 : floor($time_difference / $kWeek) ); $time_difference -= $weeks * $kWeek;
$days = ( empty($sDay) ? 0 : floor($time_difference / $kDay) ); $time_difference -= $days * $kDay;
$hours = ( empty($sHour) ? 0 : floor($time_difference / $kHour) ); $time_difference -= $hours * $kHour;
$mins = ( empty($sMin) ? 0 : floor($time_difference / $kMin) ); $time_difference -= $mins * $kMin;
$secs = ( empty($sSec) ? 0 : floor($time_difference / $kSec) );
$out = ( $weeks == 0 ? "" : "$weeks $sWeek" . ($weeks>1?"s":"") );
$out .= ( $days == 0 ? "" : (empty($out)?"":", ") . "$days $sDay" . ( $days>1?"s":"") );
$out .= ( $hours == 0 ? "" : (empty($out)?"":", ") . "$hours $sHour" . ($hours>1?"s":"") );
$out .= ( $mins == 0 ? "" : (empty($out)?"":", ") . "$mins $sMin" . ( $mins>1?"s":"") );
$out .= ( $secs == 0 ? "" : (empty($out)?"":", ") . "$secs $sSec" . ( $secs>1?"s":"") );
print $out;
}
//-----------------------------------------------------
// InsertDay()
// - - - - - -
// Prints the day of the week.
//
// $offset - Hours difference between the displayed
// day and the web server's day.
// $format - "SHORT" or "LONG".
//-----------------------------------------------------
function InsertDay($offset=0, $format="long")
{
$kHour = 60*60;
if( strcasecmp($format,"long") == 0 )
print date("l",time()+$offset*$kHour);
else
print date("D",time()+$offset*$kHour);
}
//-----------------------------------------------------
// ShowDay($days)
// - - - - - - - -
// Returns true if today is in the list of days.
//
// $days should be formatted:
// "day1 day2 day3 ..."
//
// i.e.:
// "MON TUE WED"
//-----------------------------------------------------
function ShowDay( $days )
{
if( !is_array($days) )
$days = explode(" ",$days);
while( $day = each($days) )
{
$d = trim($day[value]);
if( strlen($d) > 0 && stristr(date("l"),$d) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideDay($days)
// - - - - - - - -
// Returns false if today is in the list of days.
//
// $day should be formatted:
// "day1 day2 day3 ..."
//
// i.e.:
// "MON TUE WED"
//-----------------------------------------------------
function HideDay( $days )
{
return !ShowDay($days);
}
//=======================================
// Counters
// = = = = =
// void InsertCount ( string file[, boolean increment] );
// int GetCount ( string file[, boolean increment] );
// boolean ShowCount ( int lowvalue, int highvalue, string file );
// boolean HideCount ( int lowvalue, int highvalue, string file );
//
// int GetCounterTime ( string file );
// void InsertCounterDate( string file[, int hour_offset[, "long"|"short"]] );
// void InsertCounterTime( string file[, int hour_offset[, "long"|"short"]] );
//=======================================
//-----------------------------------------------------
// InsertCount($file,$increment)
// - - - - - - - - - - - - - - -
// Increments the count by 1 in the file $counter
// unless $increment is false.
// Prints the counter value.
//
// PHP Example:
//
// echo 'The page has been accessed ';
// InsertCount("counter.txt");
// echo ' times.';
//
// See: GetCount()
//-----------------------------------------------------
function InsertCount( $file, $increment = true )
{
print GetCount( $file, $increment );
}
//-----------------------------------------------------
// GetCount($file,$increment)
// - - - - - - - - - - - -
// Increments the count by 1 in the file $counter
// unless $increment is false.
// Returns the counter value.
//
// PHP Example:
//
// $count = Count("counter.txt");
// if( $count < 50 )
// print "You are a visiting a new page.";
// else
// print "You are visitor #$count.";
//-----------------------------------------------------
function GetCount( $file, $increment = true )
{
if( !($fp = fopen( $file, "r" )) )
{
print "\nError reading counter file: $file.\n";
$count = 0;
}
else
{
$count = strtok(fgets($fp,80), " ");
$time = strtok(" ");
fclose($fp);
}
if( !$increment )
return $count;
$count++;
if( !$time )
$time = time();
if( !($fp = fopen( $file, "w" )) )
{
print "\nError writing counter file: $file.\n";
}
else
{
fwrite($fp, sprintf( "%d %d", $count, $time ));
fclose($fp);
}
return $count;
}
//-----------------------------------------------------
// ShowCount($lowvalue,$highvalue,$file)
// - - - - - - - - - - - - - - - - - - - -
// Returns true if the counter value is between
// $lowvalue and $highvalue.
//
// See: GetCount()
//-----------------------------------------------------
function ShowCount($lowvalue,$highvalue,$file)
{
$count = GetCount($file,false);
return ($lowvalue <= $count && $count <= $highvalue);
}
//-----------------------------------------------------
// HideCount($lowvalue,$highvalue,$file)
// - - - - - - - - - - - - - - - - - - - -
// Returns false if the counter value is between
// $lowvalue and $highvalue.
//
// See: Count()
//-----------------------------------------------------
function HideCount($lowvalue,$highvalue,$file)
{
$count = Count($file,false);
return ($count > $highvalue || $lowvalue > $count);
}
//-----------------------------------------------------
// GetCounterTime($file)
// - - - - - - - - - - - - - - - - - - - -
// Returns the UNIX timestamp for when the counter file
// was created.
//
// On error, returns "" or 0.
//-----------------------------------------------------
function GetCounterTime($file)
{
if( !($fp = fopen( $file, "r" )) )
{
print "\nError reading counter file: $file.\n";
$count = 0;
}
else
{
$count = strtok(fgets($fp,80), " ");
$time = strtok(" ");
fclose($fp);
}
return $time;
}
//-----------------------------------------------------
// InsertCounterDate($file,$offset,$format)
// - - - - - - - - - - - - - - - - - - - -
// Prints the date the counter was created.
//
// See: GetCounterTime()
//-----------------------------------------------------
function InsertCounterDate($file, $offset=0, $format="long")
{
$kHour = 60*60;
$time = GetCounterTime($file);
if( strcasecmp($format,"long") )
print date("l, F j, Y",$time+$offset*$kHour);
else
print date("m/d/y" ,$time+$offset*$kHour);
}
//-----------------------------------------------------
// InsertCounterTime($file,$offset,$format)
// - - - - - - - - - - - - - - - - - - - -
// Prints the time of day the counter was created.
//
// See: GetCounterTime()
//-----------------------------------------------------
function InsertCounterTime($file, $offset=0, $format="long")
{
$kHour = 60*60;
$time = GetCounterTime($file);
if( strcasecmp($format,"long") )
print date("g:i:s A",$time+$offset*$kHour);
else
print date("g:i A" ,$time+$offset*$kHour);
}
//=======================================
// Security
// = = = = =
// void InsertDomain ( void );
// boolean ShowDomain ( string domains );
// boolean HideDomain ( string domains );
//
// void InsertUsername ( void );
// boolean ShowUsername ( string users );
// boolean HideUsername ( string users );
//
// void InsertPassword ( void );
// boolean ShowPassword ( string passes );
// boolean HidePassword ( string passes );
//
// void RequestPassword ( string realm, string userpass );
//=======================================
//-----------------------------------------------------
// InsertDomain()
// - - - - - - -
// Prints the IP address of the remote user.
//-----------------------------------------------------
function InsertDomain()
{
print $GLOBALS[REMOTE_ADDR];
}
//-----------------------------------------------------
// ShowDomain($domains)
// - - - - - - -
// Returns true if the specified domains match the
// remote user's IP address.
//
// $domains - a string containing subdomains seperated
// by spaces: "domain1 domain2 domain3 ..."
//-----------------------------------------------------
function ShowDomain( $domains )
{
if( !is_array($domains) )
$domains = explode(" ",trim($domains));
$checkByName = (isset($GLOBALS[REMOTE_HOST]) &&
strcmp($GLOBALS[REMOTE_HOST],$GLOBALS[REMOTE_ADDR]) );
while( $domain = each($domains) )
{
$d = trim($domain[value]);
if( strlen($d) > 0 )
if( strcmp(substr($GLOBALS[REMOTE_ADDR],0,strlen($d)), $d ) == 0 ||
($checkByName && stristr($GLOBALS[REMOTE_HOST],$d) ) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideDomain($domains)
// - - - - - - -
// Returns false if the specified domains match the
// remote user's IP address.
//
// $domains - a string containing subdomains seperated
// by spaces: "domain1 domain2 domain3 ..."
//
// See: ShowDomain()
//-----------------------------------------------------
function HideDomain( $domains )
{
return !ShowDomain($domains);
}
//-----------------------------------------------------
// InsertUsername()
// - - - - - - -
// Prints the username of the current user.
//
// See: RequestPassword()
//-----------------------------------------------------
function InsertUsername()
{
print $GLOBALS[PHP_AUTH_USER];
}
//-----------------------------------------------------
// ShowUsername($users)
// - - - - - - -
// Returns true if the current user's username is in
// the list $users.
//
// $users - a string containing usernames seperated
// by spaces: "user1 user2 user3 ...".
//
// See: RequestPassword()
//-----------------------------------------------------
function ShowUsername( $users )
{
if( !is_array($users) )
$users = explode(" ",trim($users));
while( $user = each($users) )
{
$u = trim($user[value]);
if( strlen($u) > 0 )
if( strcasecmp($GLOBALS[PHP_AUTH_USER], $u) == 0 )
return true;
}
return false;
}
//-----------------------------------------------------
// HideUsername($users)
// - - - - - - -
// Returns false if the current user's username is in
// the list $users.
//
// $users - a string containing usernames seperated
// by spaces: "user1 user2 user3 ...".
//
// See: ShowUsername()
// RequestPassword()
//-----------------------------------------------------
function HideUsername( $users )
{
return !ShowUsername($users);
}
//-----------------------------------------------------
// InsertPassword()
// - - - - - - -
// Prints the password of the current user.
//
// See: RequestPassword()
//-----------------------------------------------------
function InsertPassword()
{
print $GLOBALS[PHP_AUTH_PW];
}
//-----------------------------------------------------
// ShowPassword($passes)
// - - - - - - -
// Returns true if the password is in the list $passes.
//
// $passes - a string containing passwords seperated
// by spaces: "password1 password2 ...".
//
// See: RequestPassword()
//-----------------------------------------------------
function ShowPassword( $passes )
{
if( !is_array($passes) )
$passes = explode(" ",trim($passes));
while( $pass = each($passes) )
{
$p = trim($pass[value]);
if( strlen($p) > 0 )
if( strcasecmp($GLOBALS[PHP_AUTH_PW], $p) == 0 )
return true;
}
return false;
}
//-----------------------------------------------------
// HidePassword($passes)
// - - - - - - -
// Returns false if the password is in the list $passes.
//
// $passes - a string containing passwords seperated
// by spaces: "password1 password2 ...".
//
// See: ShowPassword()
// RequestPassword()
//-----------------------------------------------------
function HidePassword( $passes )
{
return !ShowPassword($passes);
}
//-----------------------------------------------------
// RequestPassword($realm,$userpass)
// - - - - - - -
// Forms an authorization request. Will only allow
// access to the page if the attempted user/pass
// is defined in $userpass.
//
// $realm - a string displayed to the user when
// entering the username and password:
// 'Enter username for $realm at domain.'
//
// $userpass - a string containing usernames and
// passwords seperated by spaces:
// "user1,pass1 user2,pass2 ...".
//-----------------------------------------------------
function RequestPassword( $realm, $userpass )
{
if( !is_array($userpass) )
$userpass = explode(" ",trim($userpass));
for( $i=0; isset($userpass[$i]); $i++ )
{
list($user[$i],$pass[$i]) = explode(",",$userpass[$i]);
}
if( !isset($PHP_AUTH_USER) )
{
$h = getAllHeaders();
$GLOBALS["PHP_AUTH_TYPE"] = strtok($h["Authorization"]," ");
$GLOBALS["PHP_AUTH_USER"] = strtok(base64_decode(strtok("")),":");
$GLOBALS["PHP_AUTH_PW"] = strtok("");
}
$match = false;
for( $i = 0; !$match && isset($user[$i]); $i++ )
{
$match = ( strcmp($GLOBALS["PHP_AUTH_USER"],$user[$i]) == 0 &&
strcmp($GLOBALS["PHP_AUTH_PW"] ,$pass[$i]) == 0 );
}
if( !$match )
{
Header("WWW-Authenticate: Basic realm=\"$realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo 'You do not have access to this page.
';
exit;
}
}
//=======================================
// Client Type
// = = = = = =
// void InsertClient ( void );
// boolean ShowClient ( string clients );
// boolean HideClient ( string clients );
//=======================================
//-----------------------------------------------------
// InsertClient()
// - - - - - - - -
// Prints the client information.
//-----------------------------------------------------
function InsertClient()
{
print $GLOBALS[HTTP_USER_AGENT];
}
//-----------------------------------------------------
// ShowClient($clients)
// - - - - - - - -
// Returns true if any words in $clients match any part
// of the remote user's browser information.
//
// $clients should be formatted:
// "client1 client2 client3 ..."
//-----------------------------------------------------
function ShowClient( $clients )
{
if( !is_array($clients) )
$clients = explode(" ",trim($clients));
while( $client = each($clients) )
{
$c = trim($client[value]);
if( strlen($c) > 0 )
if( stristr($GLOBALS[HTTP_USER_AGENT], $c) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideClient($clients)
// - - - - - - - -
// Returns false if any words in $clients match any
// part of the remote user's browser information.
//
// $clients should be formatted:
// "client1 client2 client3 ..."
//-----------------------------------------------------
function HideClient( $clients )
{
return !ShowClient($clients);
}
//=======================================
// Random
// = = = =
// int Randomize ( int range );
//
// void InsertRandom ( int range );
// boolean ShowRandom ( int threshold, int range );
// boolean HideRandom ( int threshold, int range );
//
// void InsertSamerand ( void );
// boolean ShowSamerand ( int threshold );
// boolean HideSamerand ( int threshold );
//=======================================
//-----------------------------------------------------
// Randomize($range)
// - - - - - - - - -
// Set the global variables for a new random variable
// in the range: 1 - $range.
//
// Returns the value of the new random variable.
//
// $GLOBALS[RandomVar] - contains the value for the
// current random variable.
// $GLOBALS[RandomThresh] - contains the sum of the
// thresholds called using
// Show/HideSameRand().
//-----------------------------------------------------
function Randomize( $range ) {
if(empty($GLOBALS[RandomVar])) mt_srand(time());
$GLOBALS[RandomThresh] = 0;
return $GLOBALS[RandomVar] = mt_rand( 1, $range );
}
//-----------------------------------------------------
// InsertRandom($range)
// - - - - - - - - - -
// Print the value of a new random variable in the
// range: 1 - $range.
//
// See Randomize().
//-----------------------------------------------------
function InsertRandom($range) {
print Randomize($range);
}
//-----------------------------------------------------
// ShowRandom($threshold,$range)
// - - - - - - - - - - - - - - -
// Set the random varible to a random number in the
// range: 1 - $range.
//
// Returns true if the random variable is less than or
// equal to $threshold.
//-----------------------------------------------------
function ShowRandom( $threshold, $range )
{
return( Randomize($range) <= ($GLOBALS[RandomThresh] = $threshold) );
}
//-----------------------------------------------------
// HideRandom($threshold,$range)
// - - - - - - - - - - - - - - -
// Set the random varible to a random number in the
// range: 1 - $range.
//
// Returns false if the random variable is less than or
// equal to $threshold.
//-----------------------------------------------------
function HideRandom( $threshold, $range )
{
return !ShowRandom($threshold, $range);
}
//-----------------------------------------------------
// InsertSamerand()
// - - - - - - - -
// Print the value of the current random variable.
//-----------------------------------------------------
function InsertSamerand() {
print $GLOBALS[RandomVar];
}
//-----------------------------------------------------
// ShowSamerand($threshold)
// - - - - - - - - - - - -
// Returns true if the random variable is greater than
// the sum of the previous thresholds and less than
// or equal to the sum plus $threshold.
//-----------------------------------------------------
function ShowSamerand( $threshold )
{
return ( $GLOBALS[RandomThresh] < $GLOBALS[RandomVar] &&
$GLOBALS[RandomVar] <= ($GLOBALS[RandomThresh]+=$threshold) );
}
//-----------------------------------------------------
// HideSamerand($threshold)
// - - - - - - - - - - - -
// Returns false if the random variable is greater
// than the sum of the previous thresholds and less
// than or equal to the sum plus $threshold.
//-----------------------------------------------------
function HideSamerand( $threshold )
{
return !ShowSamerand($threshold);
}
//=======================================
// File Information
// = = = = = = = = =
// void InsertModified ( string file [, int offset [, "long"|"short"] ] );
// void InsertFilesize ( string file [, "B"|"K"|"M" ] );
// int GetFilesize ( string file [, "B"|"K"|"M" ] );
//=======================================
//-----------------------------------------------------
// InsertModified($file,$offset,$format)
// - - - - - - - -
// Prints the date the file was last modifed.
//
// See InsertDate().
//-----------------------------------------------------
function InsertModified( $file, $offset=0, $format="long" )
{
$kHour = 60*60;
if( strcasecmp($format,"long") == 0 )
print date("l, F j, Y",filemtime("manual.zip")+$offset*$kHour);
else
print date("m/d/y",filemtime("manual.zip")+$offset*$kHour);
}
//-----------------------------------------------------
// InsertFilesize($file,$sizeSpec)
// - - - - - - - - - - - - - - - -
// Prints the size of the file according to $sizeSpec.
//
// $sizeSpec = "B" - size printed in bytes.
// = "K" - size printed in kilobytes.
// = "M" - size printed in megabytes.
//
// See GetFilesize().
//-----------------------------------------------------
function InsertFilesize( $file, $sizeSpec = "B" )
{
print GetFilesize($file,$sizeSpec);
}
//-----------------------------------------------------
// GetFilesize($file,$sizeSpec)
// - - - - - - - - - - - - - -
// Returns the size of the file according to $sizeSpec.
//
// $sizeSpec = "B" - size printed in bytes.
// = "K" - size printed in kilobytes.
// = "M" - size printed in megabytes.
//-----------------------------------------------------
function GetFilesize( $file, $sizeSpec = "B" )
{
if( strcmp($sizeSpec,"B") == 0 )
return filesize($file);
else if( strcmp($sizeSpec,"K") == 0 )
return floor(filesize("manual.zip")/1024);
else if( strcmp($sizeSpec,"M") == 0 )
return sprintf("%.1f",filesize("manual.zip")/1024/1024);
}
//=======================================
// Server Information
// = = = = = = = = = =
// void InsertHost ( void );
// boolean ShowHost ( string hosts );
// boolean HideHost ( string hosts );
//
// void InsertHeader ( void );
// boolean ShowHeader ( string text );
// boolean HideHeader ( string text );
//
// void InsertReferrer ( void );
// boolean ShowReferrer ( string referrers );
// boolean HideReferrer ( string referrers );
//
// void InsertThisURL ( void );
// boolean ShowThisURL ( string urls );
// boolean HideThisURL ( string urls );
//
// void InsertPath ( void );
// string GetPath ( void );
// boolean ShowPath ( [string paths] );
// boolean HidePath ( [string paths] );
//
// void InsertSearch ( void );
// string GetSearch ( void );
// boolean ShowSearch ( [string search] );
// boolean HideSearch ( [string search] );
//=======================================
//-----------------------------------------------------
// InsertHost()
// - - - - - -
// Print the host name of the server as specified in
// the HTTP header.
//-----------------------------------------------------
function InsertHost() {
print $GLOBALS[SERVER_NAME];
}
//-----------------------------------------------------
// ShowHost($hosts)
// - - - - - - - - -
// Returns true if any of the hosts match the host as
// requested in the HTTP header.
//
// $hosts - a string containing partial host names
// seperated by spaces: "host1 host2 ..."
//
// Note: This function does not currently support wildcards (*).
//-----------------------------------------------------
function ShowHost( $hosts )
{
if( !is_array($hosts) )
$hosts = explode(" ",trim($hosts));
while( $host = each($hosts) )
{
$h = trim($host[value]);
if( strlen($h) > 0 )
if( stristr($GLOBALS[SERVER_NAME],$h) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideHost($hosts)
// - - - - - - - - -
// Returns false if any of the hosts match the host as
// requested in the HTTP header.
//
// $hosts - a string containing partial host names
// seperated by spaces: "host1 host2 ..."
//-----------------------------------------------------
function HideHost( $hosts )
{
return !ShowHost($hosts);
}
//-----------------------------------------------------
// InsertHeader()
// - - - - - - -
// Print all of the HTTP header information.
//-----------------------------------------------------
function InsertHeader() {
print "$REQUEST_METHOD $REQUEST_URI $SERVER_PROTOCOL\n";
$h=getallheaders();
while( list($key,$value) = each($h) )
print "$key: $value\n";
print "\n";
}
//-----------------------------------------------------
// ShowHeader($text)
// - - - - - - - - -
// Returns true if the text is anywhere in the header.
//
// $text - a string.
//-----------------------------------------------------
function ShowHeader( $text )
{
return stristr(GetHeader(),$text);
}
//-----------------------------------------------------
// HideHeader($text)
// - - - - - - - - -
// Returns false if the text is anywhere in the header.
//
// $text - a string.
//-----------------------------------------------------
function HideHeader( $text )
{
return !ShowHeader($text);
}
//-----------------------------------------------------
// InsertReferrer()
// - - - - - - -
// Print the URL of the referring page.
//-----------------------------------------------------
function InsertReferrer() {
print $GLOBALS[HTTP_REFERER];
}
function InsertReferer() { return InsertReferrer(); }
//-----------------------------------------------------
// ShowReferrer($referrers)
// - - - - - - - - - - - -
// Returns true if any of the elements in $referrers
// are part of the referring page.
//
// $referrers - a string containing partial path names
// seperated by spaces:
// "referrer1 referrer2 ..."
//-----------------------------------------------------
function ShowReferrer( $referrers = 0 )
{
if( empty($referrers) )
return !empty($GLOBALS[HTTP_REFERER]);
if( !is_array($referrers) )
$referrers = explode(" ",trim($referrers));
while( $referrer = each($referrers) )
{
$r = trim($referrer[value]);
if( strlen($r) > 0 )
if( stristr($GLOBALS[HTTP_REFERER],$r) )
return true;
}
return false;
}
function ShowReferer($r = 0) { return ShowReferrer($r); }
//-----------------------------------------------------
// HideReferrer($referrers)
// - - - - - - - - - - - -
// Returns false if any of the elements in $referrers
// are part of the referring page.
//
// $referrers - a string containing partial path names
// seperated by spaces:
// "referrer1 referrer2 ..."
//-----------------------------------------------------
function HideReferrer( $referrers )
{
return !ShowReferrer($referrers);
}
function HideReferer($r = 0) { return HideReferrer($r); }
//-----------------------------------------------------
// InsertThisURL()
// - - - - - - - -
// Print the URL of this page.
//-----------------------------------------------------
function InsertThisURL() {
print $GLOBALS[SCRIPT_NAME];
}
//-----------------------------------------------------
// ShowThisURL($urls)
// - - - - - - - - -
// Returns true if any of the elements in $urls
// are part of this page's URL.
//
// $urls - a string containing partial url paths
// seperated by spaces: "url1 url2 ..."
//-----------------------------------------------------
function ShowThisURL( $urls )
{
if( !is_array($urls) )
$urls = explode(" ",trim($urls));
while( $url = each($urls) )
{
$u = trim($url[value]);
if( strlen($u) > 0 )
if( stristr($GLOBALS[SCRIPT_NAME],$u) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideThisURL($urls)
// - - - - - - - - -
// Returns false if any of the elements in $urls
// are part of this page's URL.
//
// $urls - a string containing partial url paths
// seperated by spaces: "url1 url2 ..."
//-----------------------------------------------------
function HideThisURL( $urls )
{
return !ShowThisURL($urls);
}
//-----------------------------------------------------
// InsertPath()
// - - - - - -
// Print the path appended to the URL. The path is the
// text following $ but before ? in the URL request.
//
// See GetPath().
//-----------------------------------------------------
function InsertPath() {
print GetPath();
}
//-----------------------------------------------------
// GetPath()
// - - - - -
// Returns a string containing the path. The path is
// the text following $ but before ? in the request.
//-----------------------------------------------------
function GetPath() {
strtok($REQUEST_URI,"$");
return stripslashes(rawurldecode(strtok("?")));
}
//-----------------------------------------------------
// ShowPath($paths)
// - - - - - - - -
// Returns true if any of the elements in $paths
// are part of the path for this page.
//
// $paths - a string containing text phrases seperated
// by spaces: "path1 path2 ..."
//
// See: GetPath().
//-----------------------------------------------------
function ShowPath( $paths = 0 )
{
if( empty($paths) ){
$tmp = GetPath();
return empty( $tmp );
}
if( !is_array($paths) )
$paths = explode(" ",trim($paths));
while( $path = each($paths) )
{
$p = trim($path[value]);
if( strlen($p) > 0 )
if( stristr(GetPath(),$p) )
return true;
}
return false;
}
//-----------------------------------------------------
// HidePath($paths)
// - - - - - - - -
// Returns true if any of the elements in $paths
// are part of the path for this page.
//
// $paths - a string containing text phrases seperated
// by spaces: "path1 path2 ..."
//
// See: ShowPath().
//-----------------------------------------------------
function HidePath( $paths = 0 )
{
return !ShowPath($paths);
}
//-----------------------------------------------------
// InsertSearch()
// - - - - - -
// Print the search appended to the URL. The search is
// the text following ? in the URL request.
//
// See GetSearch().
//-----------------------------------------------------
function InsertSearch() {
print GetSearch();
}
//-----------------------------------------------------
// GetSearch()
// - - - - -
// Returns the search appended to the URL. The search
// is the text following ? in the URL request.
//-----------------------------------------------------
function GetSearch() {
return strtr(stripSlashes(rawurldecode($GLOBALS[QUERY_STRING])),"+"," ");
}
//-----------------------------------------------------
// ShowSearch($search)
// - - - - - - - - - -
// Returns true if any of the elements in $search are
// part of the search for this page.
//
// $search - a string containing text phrases seperated
// by spaces: "search1 search2 ..."
//
// See: GetSearch().
//-----------------------------------------------------
function ShowSearch( $search = 0 )
{
if( empty($search) ){
$tmp = GetSearch();
return empty($tmp);
}
if( !is_array($search) )
$search = explode(" ",trim($search));
while( $theSearch = each($search) )
{
$s = trim($theSearch[value]);
if( strlen($s) > 0 )
if( stristr(GetSearch(),$s) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideSearch($search)
// - - - - - - - - - -
// Returns false if any of the elements in $search are
// part of the search for this page.
//
// $search - a string containing text phrases seperated
// by spaces: "search1 search2 ..."
//
// See: ShowSearch().
//-----------------------------------------------------
function HideSearch( $search = 0 )
{
return !ShowSearch($search);
}
//=======================================
// Utility
// = = = =
// void ExecCGI ( app [, direct [, begin [, end] ] ] );
//=======================================
//-----------------------------------------------------
// ExecCGI( $app, $direct, $begin, $end )
// - - - - - - - - - - - - - - - - - - -
// Execute the cgi specified by $app and print the
// output that is between the text $begin and $end.
//
// $direct is not currently used.
//
// NOTE: This function has not been tested, use only
// if you're willing to debug.
//
// See PHP documentation for exec().
//-----------------------------------------------------
function ExecCGI( $app, $direct="", $begin="", $end="" )
{
unset($output);
exec($app,$output);
$i = 0;
if( !empty($begin) )
for(;$i 0 )
if( stristr($HTTP_COOKIE_VARS[$cookie], $v) )
return true;
}
return false;
}
//-----------------------------------------------------
// HideCookie($cookie,$values)
// - - - - - - - -
// Returns false if the cookie $cookie contains any of
// the values in $values.
//
// $values should be formatted:
// "value1 value2 value3 ..."
//-----------------------------------------------------
function HideCookie( $cookie, $values )
{
return !ShowCookie($cookie,$values);
}
?>