OSDN Git Service

Small update (Added UTF-8 Support)
[idb/iDB.git.git] / inc / misc / functions.php
index 8d3ed06..6fb13e2 100644 (file)
@@ -8,15 +8,16 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     Revised BSD License for more details.
 
-    Copyright 2004-2007 Cool Dude 2k - http://intdb.sourceforge.net/
-    Copyright 2004-2007 Game Maker 2k - http://upload.idb.s1.jcink.com/
+    Copyright 2004-2009 Cool Dude 2k - http://idb.berlios.de/
+    Copyright 2004-2009 Game Maker 2k - http://intdb.sourceforge.net/
 
-    $FileInfo: functions.php - Last Update: 06/04/2007 SVN 18 - Author: cooldude2k $
+    $FileInfo: functions.php - Last Update: 6/07/2009 SVN 262 - Author: cooldude2k $
 */
 $File3Name = basename($_SERVER['SCRIPT_NAME']);
 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
        require('index.php');
        exit(); }
+// Check the file names
 function CheckFile($FileName) {
 $File3Name = basename($_SERVER['SCRIPT_NAME']);
 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
@@ -29,28 +30,26 @@ if ($File3Name==$FileName||$File3Name=="/".$FileName) {
        return true; } }
 CheckFile("functions.php");
 require($SettDir['misc']."compression.php");
-if ($_GET['act']=="DeleteSession") {
-       @session_destroy(); }
-if ($_GET['act']=="ResetSession") {
-       @session_unset(); }
-if ($_GET['act']=="NewSessionID") {
-       @session_regenerate_id(); }
-if ($_GET['act']=="PHPInfo") {
-       @phpinfo(); exit(); }
-if ($_GET['act']=="phpinfo") {
-       @phpinfo(); exit(); }
-if ($_GET['act']=="PHPCredits") {
-       @phpcredits(); exit(); }
-if ($_GET['act']=="phpcredits") {
-       @phpcredits(); exit(); }
-function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb) {
+/* 
+if ($_GET['act']=="DeleteSession") { @session_destroy(); }
+if ($_GET['act']=="ResetSession") { @session_unset(); }
+if ($_GET['act']=="NewSessionID") { @session_regenerate_id(); }
+if ($_GET['act']=="PHPInfo") { @phpinfo(); exit(); }
+if ($_GET['act']=="phpinfo") { @phpinfo(); exit(); }
+if ($_GET['act']=="PHPCredits") { @phpcredits(); exit(); }
+if ($_GET['act']=="phpcredits") { @phpcredits(); exit(); } 
+*/// Connect to mysql database
+function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb,$retlink=false) {
+if($retlink!==true) { $retlink = false; }
 $StatSQL = @mysql_connect($sqlhost,$sqluser,$sqlpass);
 $StatBase = @mysql_select_db($sqldb);
 if (!$StatSQL) { return false; }
 if (!$StatBase) { return false; }
-return true; }
+if($retlink===true) { return $StatSQL; }
+if($retlink===false) { return true; } }
        $Names['RS'] = "Renee Sabonis";
 define("_renee_", $Names['RS']);
+// Change the title and gzip page
 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
 global $Settings;
 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
@@ -59,7 +58,7 @@ $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title
 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
 $SessName = @session_name();
 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
-$qstrcode = htmlentities($Settings['qstr']);
+$qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
 if($use_gzip!="on") {
        echo $output; }
@@ -69,6 +68,7 @@ if($use_gzip=="on") {
        if($gzip_type=="deflate") {
        $goutput = gzcompress($output); }
        echo $goutput; } }
+// Fix amp => (&) to &amp; and gzip page
 function fix_amp($use_gzip="off",$gzip_type="gzip") {
 global $Settings;
 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
@@ -76,7 +76,7 @@ $output = @ob_get_clean();
 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
 $SessName = @session_name();
 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
-$qstrcode = htmlentities($Settings['qstr']);
+$qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
 if($use_gzip!="on") {
        echo $output; }
@@ -86,12 +86,13 @@ if($use_gzip=="on") {
        if($gzip_type=="deflate") {
        $goutput = gzcompress($output); }
        echo $goutput; } }
+       $Names['RJ'] = "Kazuki Przyborowski";
+define("_rene_", $Names['RJ']);
+// GZip page for faster download
 function gzip_page($use_gzip="off",$gzip_type="gzip") {
 global $Settings;
-if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
 $output = @ob_get_clean();
-       $Names['RJ'] = "René Johnson";
-define("_rene_", $Names['RJ']);
+if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
 if($use_gzip!="on") {
        echo $output; }
 if($use_gzip=="on") {
@@ -101,7 +102,13 @@ if($use_gzip=="on") {
        $goutput = gzcompress($output); }
        echo $goutput; } }
 $foo="bar"; $$foo="foo";
+if(function_exists('mysql_set_charset')===false) {
+function mysql_set_charset($charset) {
+       mysql_query("SET CHARACTER SET '".$charset."'");
+       mysql_query("SET NAMES '".$charset."'"); 
+       return true; } }
 // SafeSQL Lite Source Code by Cool Dude 2k
+// Make SQL Query's safe
 function query($query_string,$query_vars) {
    $query_array = array(array("%i","%I","%F","%S"),array("%d","%d","%f","%s"));
    $query_string = str_replace($query_array[0], $query_array[1], $query_string);
@@ -117,6 +124,9 @@ $query_val[$query_is] = $query_vars[$query_i];
 ++$query_i; }
    $query_val[0] = $query_string;
    return call_user_func_array("sprintf",$query_val); }
+       $Names['KP'] = "Kazuki Przyborowski";
+define("_kazuki_", $Names['KP']);
+// Kill bad vars for some functions
 function killbadvars($varname) {
 $badphp1 = array('$'); $badphp2 = array(null);
 $varname = str_replace($badphp1, $badphp2, $varname);
@@ -126,9 +136,32 @@ $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
        return $varname; }
+// Trying to fix this bug. ^_^
+// http://xforce.iss.net/xforce/xfdb/49697
+if(!isset($Settings['DefaultTheme'])) {
+       $Settings['DefaultTheme'] = "iDB"; }
+$BoardTheme = $Settings['DefaultTheme'];
+function chack_themes($theme) {
+global $BoardTheme;
+if(!isset($theme)) { $theme = null; }
+require('settings.php');
+$ckskindir = dirname(realpath("settings.php"))."/".$SettDir['themes'];
+if ($handle = opendir($ckskindir)) { $dirnum = null;
+   while (false !== ($ckfile = readdir($handle))) {
+          if ($dirnum==null) { $dirnum = 0; }
+          if (file_exists($ckskindir.$ckfile."/info.php")) {
+                  if ($ckfile != "." && $ckfile != "..") {
+          include($ckskindir.$ckfile."/info.php");
+       $cktheme[$dirnum] =  $ckfile;
+          ++$dirnum; } } }
+   closedir($handle); asort($cktheme); }
+$theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
+if(!in_array($theme,$cktheme)||strlen($theme)>26) {
+       $theme = $BoardTheme; } return $theme; }
+// Change the text to icons(smileys)
 function text2icons($Text,$sqlt) {
 global $Settings;
-$reneequery="SELECT * FROM ".$sqlt."smileys";
+$reneequery=query("SELECT * FROM `".$sqlt."smileys`", array(null));
 $reneeresult=mysql_query($reneequery);
 $reneenum=mysql_num_rows($reneeresult);
 $renees=0;
@@ -150,6 +183,36 @@ if($ReplaceType=="yes") {
        $Smile1 = preg_quote($SmileText,"/");
 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
 ++$renees; } return $Text; }
+// Removes the bad stuff
+function remove_bad_entities($Text) {
+//HTML Entities Dec Version
+$Text = preg_replace("/&#8238;/isU","",$Text);
+$Text = preg_replace("/&#8194;/isU","",$Text);
+$Text = preg_replace("/&#8195;/isU","",$Text);
+$Text = preg_replace("/&#8201;/isU","",$Text);
+$Text = preg_replace("/&#8204;/isU","",$Text);
+$Text = preg_replace("/&#8205;/isU","",$Text);
+$Text = preg_replace("/&#8206;/isU","",$Text);
+$Text = preg_replace("/&#8207;/isU","",$Text);
+//HTML Entities Hex Version
+$Text = preg_replace("/&#x202e;/isU","",$Text);
+$Text = preg_replace("/&#x2002;/isU","",$Text);
+$Text = preg_replace("/&#x2003;/isU","",$Text);
+$Text = preg_replace("/&#x2009;/isU","",$Text);
+$Text = preg_replace("/&#x200c;/isU","",$Text);
+$Text = preg_replace("/&#x200d;/isU","",$Text);
+$Text = preg_replace("/&#x200e;/isU","",$Text);
+$Text = preg_replace("/&#x200f;/isU","",$Text);
+//HTML Entities Name Version
+$Text = preg_replace("/&ensp;/isU","",$Text);
+$Text = preg_replace("/&emsp;/isU","",$Text);
+$Text = preg_replace("/&thinsp;/isU","",$Text);
+$Text = preg_replace("/&zwnj;/isU","",$Text);
+$Text = preg_replace("/&zwj;/isU","",$Text);
+$Text = preg_replace("/&lrm;/isU","",$Text);
+$Text = preg_replace("/&rlm;/isU","",$Text);
+return $Text; }
+// Remove the bad stuff
 function remove_spaces($Text) {
 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
@@ -157,7 +220,9 @@ $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
 $Text = preg_replace("/\s\s+/"," ",$Text);
 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
+$Text = @remove_bad_entities($Text);
 return $Text; }
+// Fix some chars
 function fixbamps($text) {
 $fixamps1 = array("&amp;copy;","&amp;reg;","&amp;trade;","&amp;quot;","&amp;amp;","&amp;lt;","&amp;gt;","&amp;(a|e|i|o|u|y)acute;","&amp;(a|e|i|o|u)grave;","&amp;(a|e|i|o|u)circ;","&amp;(a|e|i|o|u|y)uml;","&amp;(a|o|n)tilde;","&amp;aring;","&amp;aelig;","&amp;ccedil;","&amp;eth;","&amp;oslash;","&amp;szlig;","&amp;thorn;");
 $fixamps2 = array("&copy;","&reg;","&trade;","&quot;","&amp;","&lt;","&gt;","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","&aring;","&aelig;","&ccedil;","&eth;","&oslash;","&szlig;","&thorn;");
@@ -167,29 +232,22 @@ $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
 ++$ampi; }
 $text = preg_replace("/&amp;#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
 return $text; }
+// Get next id for stuff
 function getnextid($tablepre,$table) {
    $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
    $getnextidr = mysql_query($getnextidq);
    $getnextid = mysql_fetch_assoc($getnextidr);
    return $getnextid['Auto_increment'];
    @mysql_free_result($getnextidr); }
-       $Names['RSA'] = "Rachel Sabonis";
-define("_rachel_", $Names['RSA']);
-function redirects($type,$url,$time=0) {
-if($type!="location"&&
-       $type!="refresh") {
-       $type=="location"; }
-if($type=="refresh") {
-header("Refresh: ".$time."; URL=".$url); }
-if($type=="location") {
-header("Location: ".$url); }
-return true; }
-function xml_doc_start($ver,$encode,$retval=false) {
-       if($retval!=false&&$retval!=true) { $retval=false; }
-       if($retval==false) {
-       echo '<?xml version="'.$ver.'" encoding="'.$encode.'"?>'."\n"; }
-       if($retval==true) {
-       return '<?xml version="'.$ver.'" encoding="'.$encode.'"?>'."\n"; } }
+function getnumrows($tablepre,$table) {
+   $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
+   $getnextidr = mysql_query($getnextidq);
+   $getnextid = mysql_fetch_assoc($getnextidr);
+   return $getnextid['Rows'];
+   @mysql_free_result($getnextidr); }
+       $Names['K'] = "Katarzyna";
+define("_katarzyna_", $Names['K']);
+// Change Time Stamp to a readable time
 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
 $TCHour = date("H",$timestamp);
 $TCMinute = date("i",$timestamp);
@@ -197,22 +255,33 @@ $TCSecond = date("s",$timestamp);
 $TCMonth = date("n",$timestamp);
 $TCDay = date("d",$timestamp);
 $TCYear = date("Y",$timestamp);
-unset($dstake); $dstake = null;
-if(!is_numeric($offset)) { $offset = 0; }
-if(!is_numeric($minoffset)) { $minoffset = 0; }
+$dstake = null;
+if(!is_numeric($minoffset)) { $minoffset = "00"; }
+$ts_array = explode(":",$offset);
+if(count($ts_array)!=2) {
+       if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
+       if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
+       $offset = $ts_array[0].":".$ts_array[1]; }
+if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
+if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
+if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
+if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
+if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
+if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
+$tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
+//$tsa['minute'] = $tsa['minute'] + $minoffset;
 if($dst!="on"&&$dst!="off") { $dst = "off"; }
-if($dst=="on") { 
-if($dstake!="done") {
-if($offset>=0) { $dstake = "done";
-       $offset = $offset-1; } }
-if($dstake!="done") {
-if($offset<0) { $dstake = "done";
-       $offset = $offset+1; } } }
-$TCHour = $TCHour + $offset;
-$TCMinute = $TCMinute + $minoffset;
+if($dst=="on") { if($dstake!="done") { 
+       $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
+$TCHour = $TCHour + $tsa['hour'];
+$TCMinute = $TCMinute + $tsa['minute'];
 return date($format,mktime($TCHour,$TCMinute,$TCSecond,$TCMonth,$TCDay,$TCYear)); }
+       $Names['CK'] = "Christine";
+define("_christine_", $Names['CK']);
+// Change Time Stamp to a readable time
 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
+// Make a GMT Time Stamp
 function GMTimeStamp() {
 $GMTHour = gmdate("H");
 $GMTMinute = gmdate("i");
@@ -225,18 +294,27 @@ function GMTimeStampS() { return time() - date('Z', time()); }
 function GMTimeGet($format,$offset,$minoffset=null,$dst=null) { 
        return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); }
 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
-unset($dstake); $dstake = null;
-if(!is_numeric($offset)) { $offset = 0; }
-if(!is_numeric($minoffset)) { $minoffset = 0; }
+$dstake = null;
+if(!is_numeric($offset)) { $offset = "0"; }
+if(!is_numeric($minoffset)) { $minoffset = "00"; }
+$ts_array = explode(":",$offset);
+if(count($ts_array)!=2) {
+       if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
+       if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
+       $offset = $ts_array[0].":".$ts_array[1]; }
+if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
+if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
+if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
+if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
+if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
+if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
+$tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
+//$tsa['minute'] = $tsa['minute'] + $minoffset;
 if($dst!="on"&&$dst!="off") { $dst = "off"; }
-if($dst=="on") { 
-if($dstake!="done") {
-if($offset>=0) { $dstake = "done";
-       $offset = $offset-1; } }
-if($dstake!="done") {
-if($offset<0) { $dstake = "done";
-       $offset = $offset+1; } } }
-return date($format,mktime(gmdate('h')+$offset,gmdate('i')+$minoffset,gmdate('s'),gmdate('n'),gmdate('j'),gmdate('Y'))); }
+if($dst=="on") { if($dstake!="done") { 
+       $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
+return date($format,mktime(gmdate('h')+$tsa['hour'],gmdate('i')+$tsa['minute'],gmdate('s'),gmdate('n'),gmdate('j'),gmdate('Y'))); }
+// Get Server offset
 function GetSeverZone() {
 $TestHour1 = date("H");
 @putenv("OTZ=".@getenv("TZ"));
@@ -265,13 +343,14 @@ $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1
 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
 return $phpsrcs; }
 function GetUserName($idu,$sqlt) {
-$gunquery = query("select * from ".$sqlt."members where id=%i", array($idu));
+$gunquery = query("SELECT * FROM `".$sqlt."members` WHERE `id`=%i", array($idu));
 $gunresult=mysql_query($gunquery);
 $gunnum=mysql_num_rows($gunresult);
 if($gunnum>0){
-$UsersName=mysql_result($gunresult,$gunnum-1,"Name"); }
+$UsersName=mysql_result($gunresult,0,"Name"); }
 @mysql_free_result($gunresult);
 return $UsersName; }
+// hmac hash function
 function hmac($data,$key,$hash='sha1',$blocksize=64) {
   if (strlen($key)>$blocksize) {
   $key=pack('H*',$hash($key)); }
@@ -279,9 +358,11 @@ function hmac($data,$key,$hash='sha1',$blocksize=64) {
   $ipad=str_repeat(chr(0x36),$blocksize);
   $opad=str_repeat(chr(0x5c),$blocksize);
   return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); }
+// b64hmac hash function
 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
        $extdata2 = hexdec($extdata); $key = $key.$extdata2;
   return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
+// salt hmac hash function
 function salt_hmac($size1=4,$size2=6) {
 $hprand = rand(4,6); $i = 0; $hpass = "";
 while ($i < $hprand) {
@@ -294,12 +375,13 @@ if($hspsrand==2) { $hpass .= chr(rand(65,70)); }
 function is_empty($var) {
     if (((is_null($var) || rtrim($var) == "") &&
                $var !== false) || (is_array($var) && empty($var))) {
-        return true; } else {
-        return false; } }
+        return true; } else { return false; } }
+// Hash two times with md5 and sha1
 function PassHash2x($Text) {
 $Text = md5($Text);
 $Text = sha1($Text);
 return $Text; }
+// Hash two times with hmac-md5 and hmac-sha1
 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
 $Text = hmac($data,$key,"md5").$extdata; 
@@ -312,8 +394,8 @@ function cp($infile,$outfile,$mode="w") {
    fclose($cpfp);
    return true; }
 /* str_ireplace for PHP below ver. 5 updated // 
-//       by René Johnson - Cool Dude 2k      //
-//      and upaded by René Johnson again     */
+//       by Kazuki Przyborowski - Cool Dude 2k      //
+//      and upaded by Kazuki Przyborowski again     */
 if(!function_exists('str_ireplace')) {
 function str_ireplace($search,$replace,$subject) {
 if(!is_array($search)&&is_array($replace)) {
@@ -331,7 +413,33 @@ if(!is_array($search)&&!is_array($replace)) {
 $search = preg_quote($search, "/");
 $subject = preg_replace("/".$search."/i", $replace, $subject); }
 return $subject; } }
+/*   Adds mysql_set_charset to PHP below Ver. 5.2.3 - by: Janez R.      // 
+//   http://us.php.net/manual/en/function.mysql-set-charset.php#77565   */
+if (!function_exists('mysql_set_charset')) {
+  function mysql_set_charset($charset) {
+    return mysql_query("set names $charset"); } }
+/*   Adds httponly to PHP below Ver. 5.2.0   // 
+//       by Kazuki Przyborowski - Cool Dude 2k      */
+function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
+       $mkcookie = null; $expireGMT = null;
+       if(!isset($name)) { echo "Error: You need to enter a name for cookie."; return false; }
+       if(!isset($expire)) { echo "Error: You need to enter a time for cookie to expire."; return false; }
+       $expireGMT = gmdate("D, d-M-Y H:i:s \G\M\T", $expire);
+       if(!isset($value)) { $value = null; }
+       if(!isset($httponly)||$httponly==false) {
+       setcookie($name, $value, $expire, $path, $domain, $secure); return true; }
+       if(version_compare(PHP_VERSION,"5.2.0",">=")&&$httponly==true) {
+       setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); return true; }
+       if(version_compare(PHP_VERSION,"5.2.0","<")&&$httponly==true) {
+       $mkcookie = "Set-Cookie: ".rawurlencode($name)."=".rawurlencode($value);
+       $mkcookie = $mkcookie."; expires=".$expireGMT;
+       if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
+       if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
+       if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
+       if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
+header($mkcookie, false); return true; } }
 $foobar="fubar"; $$foobar="foobar";
+// Debug info
 function dump_included_files() {       return var_dump(get_included_files()); }
 function count_included_files() {      return count(get_included_files()); }
 function dump_extensions() {   return var_dump(get_loaded_extensions()); }