Ok, first sorry for the time to reply! Second, this is going to be quite a post!
Can you post the relevant code and the session configuration details (see
phpinfo()) from the new site?
I'm leaving this up for a short while (
my phpinfo). I have a dedicated server, and this seems to be the same for all the virtual servers running on it. (it's cPanel/WHM on FC4)
Here's the code from the header:
Code:
<?php if ($_SESSION['MM_Username'] != "") { ?>
welcome, <?php echo $_SESSION['MM_Username']; ?> | <a href="/manage/login/logout.php">logout</a>
<?php } else { ?>
You're not logged in. | <a href="/manage/login/index.php">login</a> <hr noshade="noshade" size="1">No account? <a href="/manage/login/signup.php">Signup!</a><?php } ?>
And here's the code from the login page. It's just standard Dreamweaver 8 login function fayre:
Code:
<?php require_once('/Connections/dbc2.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['uid'])) {
$loginUsername=$_POST['uid'];
$password=$_POST['pwd'];
$password = md5($password);
$MM_fldUserAuthorization = "position";
$MM_redirectLoginSuccess = "/members/index.php";
$MM_redirectLoginFailed = "loginfailure.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_2pz, $2pz);
$LoginRS__query=sprintf("SELECT username, password, position FROM users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $2pz) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'position');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
And this is from my members page, and it does work...
Code:
<?php print_r($_SESSION); ?>
- it outputs this for me, for example:
Array ( [MM_Username] => andy [MM_UserGroup] => 0 )
When using session variables, the first thing to check is whether you are using
$_SESSION to access the variable and if not, is register_globals on (phpinfo() will tell you) and are you trying to access the session variable within a function?
I don't think I am. I'm not that advanced with PHP to know - hence using the Dreamweaver option
Register_globals is off. I was wandering if you were going to say turn it on, but that makes no difference. So it's back off.
How are you starting your sessions and assigning your session variables? If you're starting your session after your header file is included using session_start() your header file won't read the session data. If it's before the include statement you can access and assign your session data using $_SESSION['user']['wateva'] = 'Hello'; it might be worth running print_r($_SESSION); in your header file and in your main file and have a look at what the session ID's are... from your main file.
As you'll see above, I'm starting sessions using the standard way via Dreamweaver. And the same way I've done it before
Hope someone can shed some light on this, I'm really confuzzled!
