(posted this in the code forum, but no help there... figured i'd pimp my problem a bit 😉 )
I'm confused. I have a page that is including a file (inc/left-col.php) and when it is included, it doesn't read cookie information at all. If I just go directly to the included file, it reads it correctly?!
That may be a lil confusing, so I'll show the code...
PHP for setting the cookie (snippet from login.php):
<?
if ($_REQUEST["remember"] == "on")
{
setcookie( "logged", $_REQUEST["username"], time()+3600);
do_html_header();
start_right_column();
?>
<center>
<table>
<tr><td align="center">Success! Welcome back, <?=$_REQUEST["username"]?>.<br>
Transferring you to the page you requested. If your browser does not<br>
automatically forward you in 5 seconds (doesnt work yet), <a href="<?=$_SESSION["newpage"]?>">click here</a></td>
</tr>
</table>
</center>
<?
end_right_column();
do_html_footer();
exit;
}
And now the code for the included file (inc/left-col.php):
<?
if (isset($HTTP_COOKIE_VARS["logged"]) || $_SESSION["logged_in"] == "yes")
{
?>
<!-- left column -->
<div id="lh-col"><br />
<h4 align="center">Left Column</h4>
<center>
<p>Perhaps some links or polls over here?</p>
<?=$userson?>
</center>
</div>
<!-- end of left column -->
<?
}
else
{
?>
<!-- left column -->
<div id="lh-col"><br />
<h4 align="center">Left Column</h4>
<form method="post" action="login.php">
<center>Log In:<br>
Us:<input type="text" name="username" maxlength="20" size="20"><br>
Pa:<input type="password" name="password" maxlength="20" size="20"><br>
<input type="checkbox" class="checkbox" name="remember"> Remember my login<br>
<input class="button" type="submit" value="log in">
<input type="hidden" name="submit" value="clicked">
</form>
<?=$userson?>
</center>
</div>
<?
}
?>
A lil 'splainin to do: The login box has a checkbox input named "remember". If this is checked (or "on"), login.php sets the cookie. If not, it just does a few session_register()'s. If I log in without checking the box, left-col.inc displays the appropriate "logged in" content. If I check the box and it sets the cookie (which it does) it still shows me the "logged out" content.
The most confusing thing of it all is that if I just go directly to inc/left-col.php in the browser once the cookie is set, it works as it should, but not when that file is included in index.php.
Guh?!
Sorry for the long post and thanks for any info!
~Tal