Page 1 of 1

help

Posted: Tue Mar 02, 2004 7:09 pm
by kingkong
Hi all, I am new to PHP and this forum. I can't think of a good subject name therefore "help".

Here's what my problem is, I am taking over a project(un commented) from some one else. This project would run fine in a host server. But once I downloaded to my local machine. It doesn't work. Here's the piece of code that I am having problem with. The file name is welcome.php

Code: Select all

<? 

if($login == "yes")&#123; 
//do something... 
//some SQL statement to verify user. 
header("Location: ?welcome=user"); 
&#125; 
... 
... 
?> 

<form method="post" action="welcome.php?login=yes"> 
username: 
<br><input type="text" name="username" size="15"> 
<br>password: 
<br><input type="password" name="password" size="15"> 
<br><input type="submit" value="login"> 
</form>
When I entered in the correct user/pass, and click submit, the page doesn't do anything. Now notice the variable $login, I am curious that why doesn't it need to declare like $login = $_GET["login"]? Note that this is working in a host server, and if I do $login = $_GET["login"], it will go into the if() block, but it won't send me to another page unless I add something like echo "blah blah"; before the header("Location:..") call.
Any suggestions will be much appreciated as I am stuck on this for couple hours now.

Posted: Tue Mar 02, 2004 7:51 pm
by markl999
The script must have required register_globals to be On (and they are Off by default with PHP => 4.2.0) that's why you have to do $login = $_GET['login'].

Also try changing the header thing to :
header("Location: ".$_SERVER['PHP_SELF']."?welcome=user");
exit;

Posted: Tue Mar 02, 2004 8:00 pm
by kingkong
Thanks alot Mark, I knew it has something to do with PHP configuration.
One more knowledge gain! :D
Now on to research how to turn the register_globals on...

Posted: Tue Mar 02, 2004 8:07 pm
by d3ad1ysp0rk
NO!!! Wrong way to go.

Change the script, not your configuration!

Posted: Tue Mar 02, 2004 8:24 pm
by kingkong
Yes I think I should do that, but after hours of frustrating, I just want to see my script works :lol:

Posted: Tue Mar 02, 2004 8:28 pm
by markl999
extract($_POST); at the top will be enough to see if it works as extract() will create $login from $_POST['login']

Posted: Wed Mar 03, 2004 6:02 pm
by kingkong
extract() should work, but I also need to perform extract() on $_GET, I did a search on it and has a warning that if I had to do it, I should do it in the order $_SERVER, $_SESSION, $_COOKIE, $_POST and $_GET. And also use EXTR_SKIP. Is there anything else I should becareful about?