Jump to content

Why The @#&% Does My $_SESSION Change!?


Bean Boy

Recommended Posts

Hey Guys,

 

I've been at this for hours and tried everything I know, but nothing's working.

 

This code rotates headlines and counts the impressions of each one. But when I click to the next page, the $_SESSION variable seems to increment by one?

 

WTF!?

 

<?
session_start();
$result = mysql_query("SELECT * FROM headline ORDER BY impressions") 
or die(mysql_error());
$row = mysql_fetch_array( $result );

$headline = $row['headline'];
$impressions = $row['impressions'] + 1;

// COUNT IMPRESSION
$result2 = mysql_query("UPDATE headline SET impressions='$impressions' WHERE headline='$headline'")
or die(mysql_error());

$_SESSION['headline'] = $headline;
echo "<h1>\"" . $_SESSION['headline'] . "\"</h1>";
echo "<a href=nextpage.php> Click-Through</a>";
?>

 

And here's the next page:

 

<?
session_start();
print $_SESSION['headline'];
?>

 

If $_SESSION['headline'] was Headline1, on the next page it becomes Headline2, etc.

 

What's going on here?

Link to comment
https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/
Share on other sites

No. I'm not sure what that is.

 

How would I use register_globals?

 

Also, I've never had a problem passing session variables in the past creating codes similar to this one.

 

He asked because you shouldn't have register_globals on.  Go to your php.ini or phpinfo() and verify.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.