p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: variable doesn't show up in $_COOKIE or $HTTP_COOKIE_VARS or $_POST


Message #1 by spam@k... on Fri, 21 Feb 2003 13:48:30
I'm sure I'm overlooking the most obvious thing in the world, but why is 
it that, on this page http://www.krubner.com/index.htm?articleId=42, when 
I hit submit , the variable $jess never shows up? 




if ($jess != "xxx") {
setcookie ("jess", "", time() -3600);
   echo "<form method='post' action='index.htm?articleId=42'>
    Please type your password:<br>
    <input type='text' name='jess'><br>
    <input type='submit'>
     </form>";
echo "<br><br> Here's the password: <br><br>$jess";
echo "The vars:<br><br>";
print_r($_POST);
print_r($_COOKIE);
print_r($HTTP_COOKIE_VARS);
   exit();
} else {
setcookie ("jess", $jess, time()+3600, "/", ".krubner.com", 0);
}
Message #2 by spam@k... on Fri, 21 Feb 2003 14:02:53
Further experimenting leads to below, and still no luck. I should add this 
is text that is being stored in a database, pulled out, and then run 
through eval(). The eval() seems to make all the echo statements work 
correctly, otherwise no page would render, but none of the other values 
are there. 



if ($jess != "xxx") {
setcookie ("jess", "", time() -3600);
echo "
<html>
<head>

<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1
\">
</head>

<body bgcolor=\"#FFFFFF\">
";
   echo "<form method=\"post\" action=\"index.htm?articleId=42\">
    Please type your password:<br>
    <input type='text' name='jess'><br>
    <input type='submit' name='submit' value='submit'>
     </form></body></html>";
echo "<br><br> Here's the password: <br><br>$jess";
echo "The vars:<br><br>";
print_r($_POST);
print_r($_COOKIE);
print_r($HTTP_COOKIE_VARS);
print_r($HTTP_POST_VARS);
   exit();
} else {
setcookie ("jess", $jess, time()+3600, "/", ".krubner.com", 0);
}
Message #3 by spam@k... on Fri, 21 Feb 2003 14:16:52
Okay, apparently variables just don't make it into eval() statements.





Message #4 by spam@k... on Fri, 21 Feb 2003 16:00:38
So I get $jess to show up by hard coding the below into the page. But now 
I can't seem to get the logout to work. There is a link on the page that 
says http://www.krubner.com/articleId=42&logged=logout. Click the link and 
the first if statement seems to work. The header() function works. But the 
cookie $jess doesn't seem to get overwritten - i can still get back to the 
page without having to log in again. What is wrong with the below code? 



if ($logged == "logout") {
$jess = "logout";
setcookie ("jess", $jess);
header ("Location: http://www.krubner.com/");
}
if ($jess != "xxx") {
setcookie ("jess", "");
   echo "<form method=\"post\" action=\"index.php?articleId=42\">
    Please type your password:<br>
    <input type='text' name='jess'><br>
    <input type='submit' name='submit' value='submit'>
     </form></body></html>";
   exit();
} 
if ($jess == "xxx") {
setcookie ("jess", $jess);

// lots more stuff here
}
Message #5 by "Nikolai Devereaux" <yomama@u...> on Fri, 21 Feb 2003 11:32:38 -0800
> I'm sure I'm overlooking the most obvious thing in the world, but why is 
> it that, on this page http://www.krubner.com/index.htm?articleId=42, when 
> I hit submit , the variable $jess never shows up? 

Are you still running PHP with register_globals = off?

What exactly (in english, not php) are you trying to do with this code?

Message #6 by spam@k... on Fri, 21 Feb 2003 13:58:12 -0600
> > I'm sure I'm overlooking the most obvious thing in the world, but why is 
> > it that, on this page http://www.krubner.com/index.htm?articleId=42, when 
> > I hit submit , the variable $jess never shows up? 
> 
> Are you still running PHP with register_globals = off?
> 
> What exactly (in english, not php) are you trying to do with this code?

register_globals is on. The code is simply supposed to keep people from seeing a page unless they've typed in the right password
($jess). All the print_r() stuff is just there for debugging. After a few hours tinkering I realized the problem was with retrieving
this code from a database and then hitting it with eval(). That works for echo statements and some variables, but for whatever
reason it didn't work for $jess. 

So then I took the code out of the database and got around the whole issue with eval. I hard coded the code into the main page,
which has code for rendering the template. Clunky, but whatever, I was tight on time this morning. 

Then I ran into what seems like an even more obvious problem. The variable $jess was now, finally, visible, it showed up as part of
the global variables, but now I couldn't destroy it. Still working on that one. Trying to do some kind of logout thing but can't
overwrite the cookie $jess. Don't know why. 


  Return to Index