Help - Search - Members - Calendar
Full Version: Session Doesn't Work
Zymic Webmaster Forums > Zymic Free Web Hosting > Zymic Free Web Hosting - General Discussion & Help
plgod
Hi everybody. I am having a problem with the sessions. On my site, even if I log in, it acts like i wasn't logged in. But on my local server, it works fine and everything is ok, just like it should. Here is the code of the main pages.

In home.php, (since index.php is a portal), I do session_start() on line 1, like it should. Then at some point on the page, I do include("include/ad+menu.php"), here is ad+menu.php :
CODE
// Here is a google ad...


<div id=menu>
<?php if($_SESSION['name'] != NULL) { ?> // If i am logged in
<div id=session class=menu_element>
Connecté en tant que : <div id=session_name><?php echo $_SESSION['name']; ?></div>
<a href="session/end.php" class=connect>Déconnexion</a>
</div><?php }
else {?> // If I am not logged in
<a href="session/login.php" class=connect>Connexion</a> <?php } ?>

// Then I have some links...

</div>


On session/login.php, I have a form that sends "username" and "password" by POST to postlogin.php Then I have postlogin.php
CODE
<?php session_start();

$password = crypt($_POST['password'], pl);
$username = $_POST['username'];

mysql_connect("localhost", "plgod_clanteam_com_admin", "nothing");
mysql_select_db("plgod_clanteam_com_main");
$response = mysql_query("SELECT * FROM session WHERE username ='$username' AND password ='$password'");
$data = mysql_fetch_array($response);
mysql_close();

if($data['name'] == NULL) // I received nothing, so incorrect user or pass
{
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Erreur</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Main Style" href="../styles/main_style.css" />
</head>
<body>
Le nom d'utilisateur ou le mot de passe est incorrect. Ou peut-être que vous n'êtes pas inscrit. <a href="login.php">Rééssayer</a> ou <a href="../home.php">retour à l'accueil</a>? // Means incorrect username or pass, you guessed it.
</body>
</html>
<?php die();
}






// I received something, so Ive got a user

$_SESSION = $data; // Setting up all data at once.


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Connexion OK</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Main Style" href="../styles/main_style.css" />
</head>
<body>

// Everythings fine, welcome, bla bla bla, I even show $_SESSION['name'] and it is ok, same as in the database (different from $username)

</body>
</html>


But then I come back to home.php and ad+menu still shows the "connexion" link, whereas it should put a "déconnexion" link. It does so on my local server, but it doesn't on zymic. Are session disabled? Please help me.
plgod
I looked up Firefox settings and found out that I had a cookie named PHPSESSID, and it contained a UID (of course from my site). Maybe it can help people who want to help me. By the way, to see my site, it's here, click on Connexion in the menu at the left, then you can enter plgodtest as username, and test as password to try logging in. Then click "Retour à l'accueil" and see that it's still written Connexion instead of Déconnexion... I hope it can help you.
Scapelord00
Maybe you have to errase the cookies, or in the worst case you'll have to upload all the files again, but before that you must make a backup of you Data Base.
plgod
I tried both solutions. No result.
Scapelord00
Hmmmmm thats rare. Then you will have to contact the admins via PM laugh.gif
Tom
Try reconfribulating the whatchamacallit-thingamajig, or maybe debrinkifying the double-routed memory cells.
plgod
Oh yeah! I had to debrinkify the double-routed memory cells, because they were assigned to check the server for dividing modules, and i had to change the access priorities to this module, so they were single-routed and this route was assigned to cookies, so sessions couldn't reach them.

No, seriously.
plgod
Is anyone still reading this topic??? I need help here!
Daniel
Hi,


I'm not 100% sure of this, but i can tell you it's at least bad practise. The $_SESSIONS superglobal array is an array with some predefined keys. Assigning a whole array to it is a bad idea. Maybe you can either explicity declare each key, or, use array_merge(). Assiging a different array to the superglobal directly may well wipe out crucial data from the array (including the session id etc, making it invalid after the current page execution).

So personally i'd change this line first, then see what happens:

$_SESSION = $data; // Setting up all data at once.

Other than that, try to echo out values ( print_r() and session_id() etc) at each critical point, and try to debug exactly where the values are lost.
plgod
Thank you! You were right! I defined the array variable by variable, and it works! Thanks a lot!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.