Hi i have a site hosted with GoDaddy! my site will be able to retrieve sessions that are manually set such as “$_SESSION[‘xxx’]=“xxxxxxx”;” but when i use “$_SESSION[‘xxxx’]=$xxx;” it doesn’t work and the session data in non-retrieveable! Code is below!
<?php session_start(); $username=$_POST['username']; $password=md5($_POST['password']); if ($username&&$password) { mysql_connect("xxxxxxxxxxxxxxxx", "xxxxxxxxxx", "xxxxxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxxxx") or die(mysql_error()); $query = mysql_query("SELECT * FROM login WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['md5pass']; $id = $row['id']; $firstname = $row['firstname']; } if ($username==$dbusername&&$password==$dbpassword) { $id = $row['id']; $firstname = $row['firstname']; $acc = $row['acc']; $username = $row['username']; $email = $row['email']; $err = ""; $_SESSION['id']=$id; $_SESSION['name']=$firstname; $_SESSION['acc']=$acc; $_SESSION['username']=$username; $_SESSION['email']=$email; $_SESSION['err']=""; header("Location: index.php"); } else { $_SESSION['err']="Invalid Password"; header("Location: index.php"); } } else { $_SESSION['err']="Invalid Username"; header("Location: index.php"); } } ?>You need to register the session before assigning the variables to the sessions.
These are the following code which needs to be put:
[b] session_register('id');
session_register('name');
session_register('acc');
session_register('username');
session_register('email');[/b]
$_SESSION['id']=$id;
$_SESSION['name']=$firstname;
$_SESSION['acc']=$acc;
$_SESSION['username']=$username;
$_SESSION['email']=$email;
I hope it would help you. Best of Luck!