help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingkong
Forum Newbie
Posts: 5
Joined: Tue Mar 02, 2004 7:09 pm

help

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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;
kingkong
Forum Newbie
Posts: 5
Joined: Tue Mar 02, 2004 7:09 pm

Post 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...
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

NO!!! Wrong way to go.

Change the script, not your configuration!
kingkong
Forum Newbie
Posts: 5
Joined: Tue Mar 02, 2004 7:09 pm

Post by kingkong »

Yes I think I should do that, but after hours of frustrating, I just want to see my script works :lol:
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

extract($_POST); at the top will be enough to see if it works as extract() will create $login from $_POST['login']
kingkong
Forum Newbie
Posts: 5
Joined: Tue Mar 02, 2004 7:09 pm

Post 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?
Post Reply