I have a very simple page, in which I check to see if there is a $_SESSION[‘username’] set, to see if the user is logged in. If not, I issue an error, which I email to myself.
When I display the page for the first time, it appears correctly (I am logged in) BUT I receive an email stating that session info isn’t set. If I put an “echo” statement or something in the “else” of that check, it never appears: page is always displayed correctly!
SO, I searched for days, and found nothing. Finally I just started deleting parts of my page, until I found that if I remove Google Adsense javascript code, the problem goes away!
So it’s as if the adsense code is causing a “render” of the page without session variables set. Then the session variables are set, and the page is displayed correctly!?
Now the “first time” is a hint. Subsequent visits to that page don’t cause errors. If I clear cookies and browser data (I didn’t check to see if it’s cookies specifically, I assume it is) then the error happens again.
Here’s the code on the page causing the error:
<?php
session_start();
include $_SERVER['DOCUMENT_ROOT']."/../db_live_connect.php";
if (isset($_SESSION['username']) && $_SESSION['username'] != "") {
// (Do stuff here)
} else { // If our session is not set or seems to be set incorrectly
// (This shouldn't happen! Page is always displaying correctly!?)
$error_msg = "Temps steps page failed.\\r\
Mysql_error: [".mysql_error()."] and GET is: ".$_GET['g'];
// Define $error_msg prior to including log_error.php
include ($_SERVER['DOCUMENT_ROOT'].'/include/log_error.php');
} // End if ( isset($_SESSION['username']) && $_SESSION['username']!="" )
?>
<html>
<head>
<title>Dreams: Steps</title>
</head>
<body>
<script type="text/javascript"><!--
google_ad_client = "pub-nnnnnnnnnnn";
/* Vertical short */
google_ad_slot = "nnnnnnnnnnn";
google_ad_width = 120;
google_ad_height = 240;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</body>
</html>
Any ideas?? How to solve this? Obviously I can live without the email messages, by just removing them, but I would like to turn that error checking on, and reporting. PLUS, I think it’s a sign of a more serious issue.
ps: I set that session variable very simply:
$_SESSION['username'] = $uRow['username'];
header ("Location: /home/");
Thanks!