URL sending the parameter but php does not get it

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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

URL sending the parameter but php does not get it

Post by anjanesh »

I have this :

Code: Select all

<form action="test.php">
<input name=username>
<input type=submit value="Test" name=but>
</form>

On clicking the test button after entering Hello in the text box url is
http://localhost/anjanesh/test.php?user ... o&but=Test.

The test.php code is

Code: Select all

<?php
print($username);
?>
But nothing gets printed. Why ?

Thanks
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

there was a sticky topic on this, but I dont see it now.

Anyway, you are probally using a newer version of PHP with register_globals to off. To get the value you need to use $_POST['username'], as you are sending the data through a form. To get data via the url like example.com/index.php?action=dothis, then the code $_GET['action'] would return "dothis".

I'm very sleepy right now so I hope that made sense.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Thanks - but IIS6 is recognizing it ?

Post by anjanesh »

Thanks - Did not know about that but in that case how is IIS6 managing this without $_GET[] etc. All this time I was using $username in IIS6 ?
Thanks a lot
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You must have had register_globals turned on on your other server, this has nothing to do with the web server being used and everything to do with how PHP is set up.

Mac
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You might want to note not to be using $_GET for a login form since the data passed will be jotted down in the history of the browser thus raising security problems.

Just a note.

-Nay
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Re: URL sending the parameter but php does not get it

Post by patrikG »

anjanesh wrote:

Code: Select all

<form action="test.php">
<input name=username>
<input type=submit value="Test" name=but>
</form>
Also, make sure that you specify the method (either POST or GET) in the form-tag:

Code: Select all

<form action="test.php" method="GET">
<input name=username>
<input type=submit value="Test" name=but>
</form>
Post Reply