Page 1 of 1

strange browser issues with... php code!

Posted: Sun Jun 29, 2008 4:37 am
by s.dot
Hey guys, I have the following code:

Code: Select all

<?php
session_start();
 
require '/path/to/db_connect.php';
require '/path/to/functions.php';
require '/path/to/constants.php';
 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Banner Page</title>
</head>
<body topmargin="0" leftmargin="0">
<?php
 
 
 
 
if(!is_logged_in())
{
    die('If you see this, report E01 in a support ticket.');
}
 
$banner_id = mysql_real_escape_string(stripslashes($_GET['banner_id']));
$bannerr = mysql_query("SELECT `id`,`img`,`url`,`alttext` FROM `banners` WHERE `id` = '$banner_id' LIMIT 1") or die(mysql_error());
if($bannera = mysql_fetch_assoc($bannerr))
{
    echo '<a href="banner-click.php?banner_id=' . $bannera['id']
    . '&landing_page=' . urlencode($bannera['url'])
    . '" target="_blank" onmouseover="window.status = \'\'; return true;"><img src="'
    . $bannera['img'].'" alt="'.$bannera['alttext'].'" width="468" height="60" border="0" /></a>';
} else
{
    echo '&nbsp;';
}
?>
</body>
</html>
This is embedded within an iframe (for quicker loading pages while the banner is waiting to load). The iframe is in a regular frame. The problem is, to reach this frame that shows the iframe banner, the member must be logged in. However, members are getting the die() statement from the is_logged_in() call.

I don't understand it.

Here is the is_logged_in() function (which doesn't explain why it would let them on one page but not load the banner iframe) just in case.

Code: Select all

function is_logged_in()
{
    if(!empty($_SESSION) && !empty($_SESSION['logged_in']) && ($_SESSION['logged_in'] == true))
    {
        return true;
    } else
    {
        return false;
    }
}
I'm thinking it might be some browser incompatibilities with loading things inside of an iframe, but I am not sure.

EDIT| Or perhaps the session file is locked because the parent page has it open and the call to session_start() fails inside of the iframe?

EDIT 2| Okay, now that I've read the manual page for session_write_close(), I am pretty sure that the session can't be written to (or read from) until the lock on the session file has been released.

So I'm wondering how to check if there is a lock on the file inside of the banner iframe script? I don't want to use sleep() or usleep() inside of the iframe to provide a noticeable delay.

Re: strange browser issues with... php code!

Posted: Sun Jun 29, 2008 8:33 am
by ragnis12

Code: Select all

function is_logged_in()
{
     global $_SESSION;
     if(!empty($_SESSION) && !empty($_SESSION['logged_in']) && ($_SESSION['logged_in'] == true))
     {
         return true;
     } else
     {
         return false;
     }
 }

Re: strange browser issues with... php code!

Posted: Sun Jun 29, 2008 8:40 am
by Eran
@scottavy
It's better to avoid iframes in particular and frames in general, especially if its just for optimizations reasons. In any case, use var_dump on the $_SESSION variable and check out it's content. It's probably not set the way you expect it (either empty or possibly a typo in the index name).

@ragnis12
$_SESSION is a super-global variable, it is available in all scopes. There should never be a reason to declare it as global.