baljeet
baljeet

Reputation: 43

PHP session not available

I successfully create session and it works for all pages but when the following page is executed it does not display any session variable and asks for login again ..

here is the code:

if(!session_id())
    session_start();
$con = mysql_connect("0.0.0.0 ","db_name","pwd");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
if($_GET['rating']=='like')
{
    $rcount = $_GET['rcount'] + 1;
    $id= $_GET['id'];
    mysql_query("UPDATE networx_notes SET up='$rcount' WHERE id='$id' ");
    header( 'Location: http://adrress.com/somewhere.php' ) ;
}

Upvotes: 1

Views: 744

Answers (1)

Ingmar Boddington
Ingmar Boddington

Reputation: 3500

If your session variables are not showing after the redirect http://adrress.com/somewhere.php, possibilities:

  • You do not have session_start() before trying to access session variables on this page http://adrress.com/somewhere.php.
  • The page http://adrress.com/somewhere.php is on a different domain than the referring page.
  • There are no actual session variables set in the script containing your code sample (check with print_r($_SESSION) before the redirect.

Note: You should always die \ exit after a header location change.

Upvotes: 2

Related Questions