196 lines
4.9 KiB
PHP
196 lines
4.9 KiB
PHP
<?php
|
|
if(isset($nosession))
|
|
{
|
|
if(!session_id())
|
|
{
|
|
session_start();
|
|
if(isset($_GET["regenid"]) || isset($regenid))
|
|
{
|
|
$old=session_id();
|
|
$old_session = $_SESSION;
|
|
session_regenerate_id(TRUE);
|
|
$_SESSION=$old_session;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(!session_id()){session_start();}
|
|
}
|
|
//connect to db with appropriate rights
|
|
$sessid=session_id();
|
|
function dbconnect()
|
|
{
|
|
$emsg="Ok";
|
|
$mhostname = "localhost";
|
|
$mdatabase = "poremba_sociogenesis";
|
|
$musername = "poremba_poremba";
|
|
$mpassword = "dolphin123";
|
|
mysql_connect($mhostname, $musername, $mpassword) or $emsg="Host Connect Error";
|
|
if($emsg=="Ok"){mysql_select_db($mdatabase) or $emsg="Database Connection Error";}
|
|
return($emsg);
|
|
}
|
|
|
|
|
|
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
|
|
{
|
|
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
|
|
|
|
switch ($theType) {
|
|
case "text":
|
|
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
|
|
break;
|
|
case "textnn":
|
|
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";
|
|
break;
|
|
case "long":
|
|
case "int":
|
|
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
|
|
break;
|
|
case "double":
|
|
$theValue = ($theValue != "") ? "'".doubleval($theValue)."'" : "NULL";
|
|
break;
|
|
case "date":
|
|
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
|
|
break;
|
|
case "defined":
|
|
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
|
|
break;
|
|
}
|
|
return $theValue;
|
|
}
|
|
|
|
function quote_smart($value)
|
|
{
|
|
if (get_magic_quotes_gpc()) {
|
|
$value = stripslashes($value);
|
|
}
|
|
if (!is_numeric($value)) {
|
|
$value = "'" . mysql_real_escape_string($value) . "'";
|
|
}
|
|
return $value;
|
|
}
|
|
|
|
|
|
function checkEmail($email) {
|
|
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){
|
|
list($username,$domain)=split('@',$email);
|
|
if(!checkdnsrr($domain,'MX')) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
$wordgames="tspwitc";
|
|
|
|
function uuid() {
|
|
// The field names refer to RFC 4122 section 4.1.2
|
|
return sprintf('%04x%04x-%04x-%03x4-%04x-%04x%04x%04x',
|
|
mt_rand(0, 65535), mt_rand(0, 65535),
|
|
mt_rand(0, 65535),
|
|
mt_rand(0, 4095),
|
|
bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '01', 6, 2)),
|
|
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)
|
|
);
|
|
}
|
|
//date_default_timezone_set('America/Denver');
|
|
date_default_timezone_set('UTC');
|
|
if(!isset($_COOKIE["caseyknows"]))
|
|
{
|
|
$expire=strtotime("+3 years");
|
|
$Data=uuid();
|
|
setcookie('caseyknows', $Data, $expire,'/', false, 0);
|
|
$_SESSION["caseyknows"]=$Data;
|
|
}
|
|
else
|
|
{
|
|
$_SESSION["caseyknows"]=$_COOKIE["caseyknows"];
|
|
}
|
|
|
|
function exitIfNotModifiedSince($last_modified)
|
|
{
|
|
if(array_key_exists("HTTP_IF_MODIFIED_SINCE",$_SERVER))
|
|
{
|
|
$if_modified_since=strtotime(preg_replace('/;.*$/','',$_SERVER["HTTP_IF_MODIFIED_SINCE"]));
|
|
if($if_modified_since >= $last_modified)
|
|
{
|
|
header("HTTP/1.0 304 Not Modified");
|
|
exit();
|
|
}
|
|
}
|
|
}
|
|
function setLastModified($last_modified=NULL)
|
|
{
|
|
$page_modified=getlastmod();
|
|
|
|
if(empty($last_modified) || ($last_modified < $page_modified))
|
|
{
|
|
$last_modified=$page_modified;
|
|
}
|
|
$header_modified=filemtime(__FILE__);
|
|
if($header_modified > $last_modified)
|
|
{
|
|
$last_modified=$header_modified;
|
|
}
|
|
header('Last-Modified: ' . date("r",$last_modified));
|
|
return $last_modified;
|
|
}
|
|
function curPageURL() {
|
|
$pageURL = 'http';
|
|
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
|
|
$pageURL .= "://";
|
|
if ($_SERVER["SERVER_PORT"] != "80") {
|
|
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
|
|
} else {
|
|
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
|
|
}
|
|
return $pageURL;
|
|
}
|
|
function getRealIpAddr()
|
|
{
|
|
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
|
|
{
|
|
$ip=$_SERVER['HTTP_CLIENT_IP'];
|
|
}
|
|
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
|
|
{
|
|
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
}
|
|
else
|
|
{
|
|
$ip=$_SERVER['REMOTE_ADDR'];
|
|
}
|
|
return $ip;
|
|
}
|
|
|
|
function QueryIntoArray($query){
|
|
settype($retval,"array");
|
|
$result= mysql_query($query);
|
|
if(!$result){
|
|
print "Query Failed";
|
|
}
|
|
for($i=0;$i<mysql_numrows($result);$i++){
|
|
for($j=0;$j<mysql_num_fields($result);$j++){
|
|
$retval[$i][mysql_field_name($result,$j)] = mysql_result
|
|
($result,$i,mysql_field_name($result,$j));
|
|
}//end inner loop
|
|
}//end outer loop
|
|
return $retval;
|
|
}
|
|
|
|
function do_reg($text, $regex)
|
|
{
|
|
if (preg_match($regex, $text)) {
|
|
return TRUE;
|
|
}
|
|
else {
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//' = '
|
|
$specialChars = array('&'=>'&', '<'=>'<', '>'=>'>', "'"=>''', '"'=>'"'); //for chat
|
|
?>
|