3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2009 iDB Support - http://idb.berlios.de/
12 Copyright 2004-2009 Game Maker 2k - http://gamemaker2k.org/
14 $FileInfo: functions.php - Last Update: 11/15/2009 SVN 349 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
20 // Check the file names
21 function CheckFile($FileName) {
22 $File3Name = basename($_SERVER['SCRIPT_NAME']);
23 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
27 function CheckFiles($FileName) {
28 $File3Name = basename($_SERVER['SCRIPT_NAME']);
29 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
31 CheckFile("functions.php");
32 require($SettDir['misc']."compression.php");
34 if ($_GET['act']=="DeleteSession") { @session_destroy(); }
35 if ($_GET['act']=="ResetSession") { @session_unset(); }
36 if ($_GET['act']=="NewSessionID") { @session_regenerate_id(); }
37 if ($_GET['act']=="PHPInfo") { @phpinfo(); exit(); }
38 if ($_GET['act']=="phpinfo") { @phpinfo(); exit(); }
39 if ($_GET['act']=="PHPCredits") { @phpcredits(); exit(); }
40 if ($_GET['act']=="phpcredits") { @phpcredits(); exit(); }
41 */// Connect to mysql database
42 function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb,$retlink=false) {
43 if($retlink!==true) { $retlink = false; }
44 $StatSQL = @mysql_connect($sqlhost,$sqluser,$sqlpass);
45 $StatBase = @mysql_select_db($sqldb);
46 if (!$StatSQL) { return false; }
47 if (!$StatBase) { return false; }
48 if($retlink===true) { return $StatSQL; }
49 if($retlink===false) { return true; } }
50 $Names['RS'] = "Renee Sabonis";
51 define("_renee_", $Names['RS']);
52 // Change the title and gzip page
53 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
55 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
56 $output = @ob_get_clean();
57 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
58 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
59 $SessName = @session_name();
60 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
61 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
62 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
66 if($gzip_type=="gzip") {
67 $goutput = gzencode($output); }
68 if($gzip_type=="deflate") {
69 $goutput = gzcompress($output); }
71 // Fix amp => (&) to & and gzip page
72 function fix_amp($use_gzip="off",$gzip_type="gzip") {
74 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
75 $output = @ob_get_clean();
76 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
77 $SessName = @session_name();
78 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
79 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
80 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
84 if($gzip_type=="gzip") {
85 $goutput = gzencode($output); }
86 if($gzip_type=="deflate") {
87 $goutput = gzcompress($output); }
89 $Names['RJ'] = "Rene Johnson";
90 define("_rene_", $Names['RJ']);
91 // GZip page for faster download
92 function gzip_page($use_gzip="off",$gzip_type="gzip") {
94 $output = @ob_get_clean();
95 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
99 if($gzip_type=="gzip") {
100 $goutput = gzencode($output); }
101 if($gzip_type=="deflate") {
102 $goutput = gzcompress($output); }
104 $foo="bar"; $$foo="foo";
105 // Execute a query :P
107 function exec_query($query,$link=null) {
109 if(isset($link_identifier)) {
110 $result = mysql_query($query,$link); }
111 if(!isset($link_identifier)) {
112 $result = mysql_query($query); }
114 echo "Invalid query: ".mysql_error();
119 // SafeSQL Lite Source Code by Cool Dude 2k
120 // Make SQL Query's safe
121 function query($query_string,$query_vars) {
122 $query_array = array(array("%i","%I","%F","%S"),array("%d","%d","%f","%s"));
123 $query_string = str_replace($query_array[0], $query_array[1], $query_string);
124 if (get_magic_quotes_gpc()) {
125 $query_vars = array_map("stripslashes", $query_vars); }
126 $query_vars = array_map("mysql_real_escape_string", $query_vars);
127 $query_val = $query_vars;
128 $query_num = count($query_val);
130 while ($query_i < $query_num) {
131 $query_is = $query_i+1;
132 $query_val[$query_is] = $query_vars[$query_i];
134 $query_val[0] = $query_string;
135 return call_user_func_array("sprintf",$query_val); }
136 if(function_exists('mysql_set_charset')===false) {
137 function mysql_set_charset($charset) {
138 exec_query("SET CHARACTER SET '".$charset."'");
139 exec_query("SET NAMES '".$charset."'");
141 $Names['KP'] = "Kazuki Przyborowski";
142 define("_kazuki_", $Names['KP']);
143 // Kill bad vars for some functions
144 function killbadvars($varname) {
145 $badphp1 = array('$'); $badphp2 = array(null);
146 $varname = str_replace($badphp1, $badphp2, $varname);
147 $varname = preg_replace("/(_SERVER|_ENV|_COOKIE|_SESSION)/i", null, $varname);
148 $varname = preg_replace("/(_GET|_POST|_FILES|_REQUEST|GLOBALS)/i", null, $varname);
149 $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
150 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
151 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
153 // Trying to fix this bug. ^_^
154 // http://xforce.iss.net/xforce/xfdb/49697
155 if(!isset($Settings['DefaultTheme'])) {
156 $Settings['DefaultTheme'] = "iDB"; }
157 $BoardTheme = $Settings['DefaultTheme'];
158 //Check to make sure theme exists
159 function chack_themes($theme) {
161 if(!isset($theme)) { $theme = null; }
162 require('settings.php');
163 $ckskindir = dirname(realpath("settings.php"))."/".$SettDir['themes'];
164 if ($handle = opendir($ckskindir)) { $dirnum = null;
165 while (false !== ($ckfile = readdir($handle))) {
166 if ($dirnum==null) { $dirnum = 0; }
167 if (file_exists($ckskindir.$ckfile."/info.php")) {
168 if ($ckfile != "." && $ckfile != "..") {
169 //include($ckskindir.$ckfile."/info.php");
170 $cktheme[$dirnum] = $ckfile;
172 closedir($handle); asort($cktheme); }
173 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
174 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
175 $theme = $BoardTheme; } return $theme; }
176 // Change the text to icons(smileys)
177 function text2icons($Text,$sqlt) {
179 $reneequery=query("SELECT * FROM `".$sqlt."smileys`", array(null));
180 $reneeresult=exec_query($reneequery);
181 $reneenum=mysql_num_rows($reneeresult);
183 while ($renees < $reneenum) {
184 $FileName=mysql_result($reneeresult,$renees,"FileName");
185 $SmileName=mysql_result($reneeresult,$renees,"SmileName");
186 $SmileText=mysql_result($reneeresult,$renees,"SmileText");
187 $SmileDirectory=mysql_result($reneeresult,$renees,"Directory");
188 $ShowSmile=mysql_result($reneeresult,$renees,"Show");
189 $ReplaceType=mysql_result($reneeresult,$renees,"ReplaceCI");
190 if($ReplaceType=="on") { $ReplaceType = "yes"; }
191 if($ReplaceType=="off") { $ReplaceType = "no"; }
192 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
193 $Smile1 = $SmileText;
194 $Smile2 = '<img src="'.$SmileDirectory.''.$FileName.'" style="vertical-align: middle; border: 0px;" title="'.$SmileName.'" alt="'.$SmileName.'" />';
195 if($ReplaceType=="no") {
196 $Text = str_replace($Smile1, $Smile2, $Text); }
197 if($ReplaceType=="yes") {
198 $Smile1 = preg_quote($SmileText,"/");
199 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
200 ++$renees; } return $Text; }
201 // Removes the bad stuff
202 function remove_bad_entities($Text) {
203 //HTML Entities Dec Version
204 $Text = preg_replace("/‮/isU","",$Text);
205 $Text = preg_replace("/ /isU","",$Text);
206 $Text = preg_replace("/ /isU","",$Text);
207 $Text = preg_replace("/ /isU","",$Text);
208 $Text = preg_replace("/‌/isU","",$Text);
209 $Text = preg_replace("/‍/isU","",$Text);
210 $Text = preg_replace("/‎/isU","",$Text);
211 $Text = preg_replace("/‏/isU","",$Text);
212 //HTML Entities Hex Version
213 $Text = preg_replace("/‮/isU","",$Text);
214 $Text = preg_replace("/ /isU","",$Text);
215 $Text = preg_replace("/ /isU","",$Text);
216 $Text = preg_replace("/ /isU","",$Text);
217 $Text = preg_replace("/‌/isU","",$Text);
218 $Text = preg_replace("/‍/isU","",$Text);
219 $Text = preg_replace("/‎/isU","",$Text);
220 $Text = preg_replace("/‏/isU","",$Text);
221 //HTML Entities Name Version
222 $Text = preg_replace("/ /isU","",$Text);
223 $Text = preg_replace("/ /isU","",$Text);
224 $Text = preg_replace("/ /isU","",$Text);
225 $Text = preg_replace("/‌/isU","",$Text);
226 $Text = preg_replace("/‍/isU","",$Text);
227 $Text = preg_replace("/‎/isU","",$Text);
228 $Text = preg_replace("/‏/isU","",$Text);
230 // Remove the bad stuff
231 function remove_spaces($Text) {
232 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
233 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
234 $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
235 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
236 $Text = preg_replace("/\s\s+/"," ",$Text);
237 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
238 $Text = @remove_bad_entities($Text);
241 function fixbamps($text) {
242 $fixamps1 = array("&copy;","&reg;","&trade;","&quot;","&amp;","&lt;","&gt;","&(a|e|i|o|u|y)acute;","&(a|e|i|o|u)grave;","&(a|e|i|o|u)circ;","&(a|e|i|o|u|y)uml;","&(a|o|n)tilde;","&aring;","&aelig;","&ccedil;","&eth;","&oslash;","&szlig;","&thorn;");
243 $fixamps2 = array("©","®","™",""","&","<",">","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","å","æ","ç","ð","ø","ß","þ");
244 $ampnum = count($fixamps1); $ampi=0;
245 while ($ampi < $ampnum) {
246 $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
248 $text = preg_replace("/&#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
250 // Get next id for stuff
251 function getnextid($tablepre,$table) {
252 $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
253 $getnextidr = exec_query($getnextidq);
254 $getnextid = mysql_fetch_assoc($getnextidr);
255 return $getnextid['Auto_increment'];
256 @mysql_free_result($getnextidr); }
257 // Get number of rows for table
258 function getnumrows($tablepre,$table) {
259 $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
260 $getnextidr = exec_query($getnextidq);
261 $getnextid = mysql_fetch_assoc($getnextidr);
262 return $getnextid['Rows'];
263 @mysql_free_result($getnextidr); }
264 $Names['K'] = "Katarzyna";
265 define("_katarzyna_", $Names['K']);
266 // Change Time Stamp to a readable time
267 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
268 $TCHour = date("H",$timestamp);
269 $TCMinute = date("i",$timestamp);
270 $TCSecond = date("s",$timestamp);
271 $TCMonth = date("n",$timestamp);
272 $TCDay = date("d",$timestamp);
273 $TCYear = date("Y",$timestamp);
275 if(!is_numeric($minoffset)) { $minoffset = "00"; }
276 $ts_array = explode(":",$offset);
277 if(count($ts_array)!=2) {
278 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
279 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
280 $offset = $ts_array[0].":".$ts_array[1]; }
281 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
282 if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
283 if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
284 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
285 if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
286 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
287 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
288 //$tsa['minute'] = $tsa['minute'] + $minoffset;
289 if($dst!="on"&&$dst!="off") { $dst = "off"; }
290 if($dst=="on") { if($dstake!="done") {
291 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
292 $TCHour = $TCHour + $tsa['hour'];
293 $TCMinute = $TCMinute + $tsa['minute'];
294 return date($format,mktime($TCHour,$TCMinute,$TCSecond,$TCMonth,$TCDay,$TCYear)); }
295 $Names['D'] = "Dagmara";
296 define("_dagmara_", $Names['D']);
297 // Change Time Stamp to a readable time
298 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
299 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
300 // Make a GMT Time Stamp
301 function GMTimeStamp() {
302 $GMTHour = gmdate("H");
303 $GMTMinute = gmdate("i");
304 $GMTSecond = gmdate("s");
305 $GMTMonth = gmdate("n");
306 $GMTDay = gmdate("d");
307 $GMTYear = gmdate("Y");
308 return mktime($GMTHour,$GMTMinute,$GMTSecond,$GMTMonth,$GMTDay,$GMTYear); }
309 // Make a GMT Time Stamp alt version
310 function GMTimeStampS() { return time() - date('Z', time()); }
312 function GMTimeGet($format,$offset,$minoffset=null,$dst=null) {
313 return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); }
314 // Get GMT Time alt version
315 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
317 if(!is_numeric($offset)) { $offset = "0"; }
318 if(!is_numeric($minoffset)) { $minoffset = "00"; }
319 $ts_array = explode(":",$offset);
320 if(count($ts_array)!=2) {
321 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
322 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
323 $offset = $ts_array[0].":".$ts_array[1]; }
324 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
325 if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
326 if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
327 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
328 if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
329 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
330 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
331 //$tsa['minute'] = $tsa['minute'] + $minoffset;
332 if($dst!="on"&&$dst!="off") { $dst = "off"; }
333 if($dst=="on") { if($dstake!="done") {
334 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
335 return date($format,mktime(gmdate('h')+$tsa['hour'],gmdate('i')+$tsa['minute'],gmdate('s'),gmdate('n'),gmdate('j'),gmdate('Y'))); }
337 function GetSeverZone() {
338 $TestHour1 = date("H");
339 @putenv("OTZ=".@getenv("TZ"));
341 $TestHour2 = date("H");
342 @putenv("TZ=".@getenv("OTZ"));
343 $TestHour3 = $TestHour1-$TestHour2;
345 // Get Server offset alt version
346 function SeverOffSet() {
347 $TestHour1 = date("H");
348 $TestHour2 = gmdate("H");
349 $TestHour3 = $TestHour1-$TestHour2;
351 // Get Server offset new version
352 function SeverOffSetNew() {
353 return gmdate("g",mktime(0,date("Z"))); }
354 function gmtime() { return time() - (int) date('Z'); }
355 // Acts like highlight_file();
356 function file_get_source($filename,$return = FALSE) {
357 $phpsrc = file_get_contents($filename);
358 $phpsrcs = highlight_string($phpsrc,$return);
360 // Also acts like highlight_file(); but valid xhtml
361 function valid_get_source($filename) {
362 $phpsrcs = file_get_source($filename,TRUE);
363 // Change font tag to span tag for valid xhtml
364 $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1;\">", $phpsrcs);
365 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
367 // Check to see if the user is hidden/shy. >_> | ^_^ | <_<
368 function GetUserName($idu,$sqlt) { $UsersName = null;
369 $gunquery = query("SELECT * FROM `".$sqlt."members` WHERE `id`=%i LIMIT 1", array($idu));
370 $gunresult=exec_query($gunquery);
371 $gunnum=mysql_num_rows($gunresult);
372 // I'm now hidden from you. ^_^ | <_< I cant find you.
373 $UsersHidden = "yes";
375 $UsersName=mysql_result($gunresult,0,"Name");
376 // Am i still hidden. o_O <_< I see you.
377 $UsersHidden=mysql_result($gunresult,0,"HiddenMember"); }
378 @mysql_free_result($gunresult);
379 $UsersInfo['Name'] = $UsersName;
380 $UsersInfo['Hidden'] = $UsersHidden;
382 // hmac hash function
383 function hmac($data,$key,$hash='sha1',$blocksize=64) {
384 if (!function_exists('hash_hmac')) {
385 if (strlen($key)>$blocksize) {
386 $key=pack('H*',$hash($key)); }
387 $key=str_pad($key, $blocksize, chr(0x00));
388 $ipad=str_repeat(chr(0x36),$blocksize);
389 $opad=str_repeat(chr(0x5c),$blocksize);
390 return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); }
391 if (function_exists('hash_hmac')) {
392 return hash_hmac($hash,$data,$key); } }
393 // b64hmac hash function
394 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
395 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
396 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
397 // b64hmac rot13 hash function
398 function b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
399 $data = str_rot13($data);
400 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
401 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
402 // salt hmac hash function
403 function salt_hmac($size1=4,$size2=6) {
404 $hprand = rand(4,6); $i = 0; $hpass = "";
405 while ($i < $hprand) {
406 $hspsrand = rand(1,2);
407 if($hspsrand!=1&&$hspsrand!=2) { $hspsrand=1; }
408 if($hspsrand==1) { $hpass .= chr(rand(48,57)); }
409 if($hspsrand==2) { $hpass .= chr(rand(65,70)); }
410 ++$i; } return $hpass; }
411 /* is_empty by M at http://us2.php.net/manual/en/function.empty.php#74093 */
412 function is_empty($var) {
413 if (((is_null($var) || rtrim($var) == "") &&
414 $var !== false) || (is_array($var) && empty($var))) {
415 return true; } else { return false; } }
416 // PHP 5 hash algorithms to functions :o
417 if(function_exists('hash')&&function_exists('hash_algos')) {
418 if(in_array("md2",hash_algos())) {
419 function md2($data) { return hash("md2",$data); } }
420 if(in_array("md4",hash_algos())) {
421 function md4($data) { return hash("md4",$data); } }
422 if(in_array("sha384",hash_algos())) {
423 function sha384($data) { return hash("sha384",$data); } }
424 if(in_array("sha512",hash_algos())) {
425 function sha512($data) { return hash("sha512",$data); } } }
426 // Try and convert IPB 2.0.0 style passwords to iDB style passwords
427 function hash2xkey($data,$key,$hash1='md5',$hash2='md5') {
428 return $hash1($hash2($key).$hash2($data)); }
429 // Hash two times with md5 and sha1 for DF2k
430 function PassHash2x($Text) {
434 // Hash two times with hmac-md5 and hmac-sha1
435 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
436 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
437 $Text = hmac($data,$key,"md5").$extdata;
438 $Text = hmac($Text,$key,"sha1").$extdata;
439 return base64_encode($Text); }
440 function cp($infile,$outfile,$mode="w") {
441 $contents = file_get_contents($infile);
442 $cpfp = fopen($outfile,$mode);
443 fwrite($cpfp, $contents);
446 /* str_ireplace for PHP below ver. 5 updated //
447 // by Kazuki Przyborowski - Cool Dude 2k //
448 // and upaded by Kazuki Przyborowski again */
449 if(!function_exists('str_ireplace')) {
450 function str_ireplace($search,$replace,$subject) {
451 if(!is_array($search)&&is_array($replace)) {
452 $search = array($search); }
453 if(is_array($search)&&!is_array($replace)) {
454 $replace = array($replace); }
455 if(is_array($search)&&is_array($replace)) {
456 $sc=count($search); $rc=count($replace); $sn=0;
457 if($sc!=$rc) { return false; }
459 $search[$sn] = preg_quote($search[$sn], "/");
460 $subject = preg_replace("/".$search[$sn]."/i", $replace[$sn], $subject);
462 if(!is_array($search)&&!is_array($replace)) {
463 $search = preg_quote($search, "/");
464 $subject = preg_replace("/".$search."/i", $replace, $subject); }
466 /* Adds mysql_set_charset to PHP below Ver. 5.2.3 - by: Janez R. //
467 // http://us.php.net/manual/en/function.mysql-set-charset.php#77565 */
468 if (!function_exists('mysql_set_charset')) {
469 function mysql_set_charset($charset) {
470 return exec_query("set names $charset"); } }
471 /* Adds httponly to PHP below Ver. 5.2.0 //
472 // by Kazuki Przyborowski - Cool Dude 2k */
473 function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
474 $mkcookie = null; $expireGMT = null;
475 if(!isset($name)) { echo "Error: You need to enter a name for cookie."; return false; }
476 if(!isset($expire)) { echo "Error: You need to enter a time for cookie to expire."; return false; }
477 $expireGMT = gmdate("D, d-M-Y H:i:s \G\M\T", $expire);
478 if(!isset($value)) { $value = null; }
479 if(!isset($httponly)||$httponly==false) {
480 setcookie($name, $value, $expire, $path, $domain, $secure); return true; }
481 if(version_compare(PHP_VERSION,"5.2.0",">=")&&$httponly==true) {
482 setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); return true; }
483 if(version_compare(PHP_VERSION,"5.2.0","<")&&$httponly==true) {
484 $mkcookie = "Set-Cookie: ".rawurlencode($name)."=".rawurlencode($value);
485 $mkcookie = $mkcookie."; expires=".$expireGMT;
486 if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
487 if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
488 if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
489 if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
490 header($mkcookie, false); return true; } }
491 $foobar="fubar"; $$foobar="foobar";
493 function dump_included_files() { return var_dump(get_included_files()); }
494 function count_included_files() { return count(get_included_files()); }
495 function dump_extensions() { return var_dump(get_loaded_extensions()); }
496 function count_extensions() { return count(get_loaded_extensions()); }