Same code, same php version, different results
Posted: Thu Nov 02, 2006 3:05 pm
I got the code below and I've got 2 webservers. local one, and remote one. Both servers run php version 4.3.10.
The code I run on both servers is 100% the same, also both use the same mysql database located on the remote one.
Problem is that I get different results.
If i run it on localhost with /?s=1 and then I run it without s parameter $_SESSION["server_id"] have value 1
But if I run it on remote server in the same way, $_SESSION["server_id"] have value 0
Heres the code:
The code I run on both servers is 100% the same, also both use the same mysql database located on the remote one.
Problem is that I get different results.
If i run it on localhost with /?s=1 and then I run it without s parameter $_SESSION["server_id"] have value 1
But if I run it on remote server in the same way, $_SESSION["server_id"] have value 0
Heres the code:
Code: Select all
session_start();
//session init and verify
if ( isset($_SESSION['UniqueId']) && isset($_COOKIE['UniqueId']) ) {
if (($_SESSION['UniqueId'] != $_COOKIE['UniqueId']) ||
($_SESSION['RemoteAddr'] != $_SERVER['REMOTE_ADDR']))
{
session_destroy();
setcookie('UniqueId', '', time());
echo '<script language="JavaScript"> window.location.search = ""; </script>';
}
} else {
$unique_id = md5(rand(1,999) . time());
$_SESSION['UniqueId'] = $unique_id;
$_SESSION['RemoteAddr'] = $_SERVER['REMOTE_ADDR'];
setcookie('UniqueId', $unique_id, time() + 123456789);
}
$page = $_GET["p"];
if(strlen($page) > 12 || !ereg("[a-z]", $page)) {
$page="";
}
$server_id = (int)$_GET["s"];
if ( $server_id == 0 && $page!="admin" && !isset($_SESSION["server_id"]) ) {
include("main.php");
$flag = 1;
}
elseif ( $server_id != 0 ) {
$sql = "SELECT * FROM `progress_servers` WHERE `id`=".$server_id;
$res = mysql_query($sql);
unset($_SESSION["server_id"]);
unset($_SESSION["server_name"]);
if ( mysql_num_rows($res) == 1 || $page=="admin" ) {
$row = mysql_fetch_array($res);
$_SESSION["server_id"] = (int)$row["id"];
$_SESSION["server_header"] = $row["zone"].' - '.$row["name"].' '.$row["type"];
$_SESSION["server_name"] = $row["name"];
} else {
echo '<script language="JavaScript"> window.location.search = ""; </script>';
$flag = 1;
}
}
if ( $flag != 1 ) {
include("header.php");
switch($page) {
case "news" : include("news.php"); break;
case "guilds" : include("guilds.php"); break;
case "progress" : include("progress.php"); break;
case "rarecrafts" : include("rarecrafts.php"); break;
case "notes" : include("notes.php"); break;
case "change" : {
unset($_SESSION["server_id"]);
unset($_SESSION["server_name"]);
echo '<script language="JavaScript"> window.location.search = ""; </script>';
}
case "admin" : include("admin.php"); break;
default : include ("home.php"); break;
}
}
include("footer.php");