Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php $ GET from a form



10:09 pm on May 30, 2007 (gmt 0)

5+ Year Member


I am working on a system that logs IP addresses, I posted earlier about pagination, which I now have sorted however I am now attempting to implement a search feature that will display the results and also offer the pagination.

The paghination is working like this


I have introduced a new file called search.php that has the following URI, mysite.com/search.php?ip=

my problem is getting the IP address or value typed into the search text box (the search text box appears at the top of the search.php file), How do i get the value from the search text box into the URI, and also how do i make it so that once it is in a variable that variable will never change, even if the page is reloaded (session variables?) so I suppose its more of how do i get the search text into a session variable, and then get the session variable into the URI for the ip attribute?

any help here would be appreciated, if you need to see code snippets just ask, I didn't want to post the entire code as its long and also incase the solution didn't need it.

anyhow any help appreciated as i mentioned before.




11:56 pm on May 30, 2007 (gmt 0)

10+ Year Member

You can access the IP address using the $_GET array - $_GET[ip].

If you want to display it in a text box you can use this code:

echo '<input type="text" value="'.$_GET[ip].'">';


12:18 am on May 31, 2007 (gmt 0)

5+ Year Member

This is not what I meant, sorry if my initial post wasn't clear.

I am using a form text box to type the ip in lets say the ip i am typing is

so i type and press "Search" this search button submits to search.php, which I want to be able to list all the IPs from a database.

the problem I have is that i list 20 records for per page, when i click next to goto the next page it doesn't remember the $_POST['textbox'] item from the first page and returns no results because the search criteria originally from $_POST['textbox'] isnt set anymore.

I added an extra field to the URI called IP now i can access my results correctly but only by hand modfying the URI to be


i want to be able to do this automatically and not have to hand modify the URI so if i type into the text box and press search it should make the initial URI include the value i typed in the text box.

Do you get me?

I dont have a clue how to do this properly so I am here seeking guidance.

any thoughts at all will be much appreciated

Thanks again



1:37 am on May 31, 2007 (gmt 0)

10+ Year Member

I still don't quite understand how you're doing this. For moving on to the next lot of search results you can either set a hidden field with the IP address like this:

echo '<input type="hidden" name="ip" value="'.$_POST[ip].'">';

and then access the IP from the $_POST array on the next page, or add the IP address in the <form> code like this:

echo '<form action="search.php?ip='.$_POST[ip].'">';

and access the IP address from the $_GET array.


5:45 am on May 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

// the next page it doesn't remember the $_POST['textbox'] item

Yea it is not supposed to. $_POST, $_REQUEST, $_GET, all get values of a form from just submitted forms, and you shouldn't expect them to be there by themselves in the following paes.

I would recommend you to assign them to a SESSION. May be put the id in the following manner:

$_SESSION['id'] = $_POST['textbox']; then use $_SESSION['id'] in the following pages.

or carry the values in hidden textboxes

<input type="hidden" value=". $_POST['textbox'] ." name = "textbox">

I hope this helps.



9:11 am on May 31, 2007 (gmt 0)

5+ Year Member

will this work?

because when i click next, $_POST['textbox'] will not have been submitted to the next page so isnt it like saying

$_SESSION['ip'] = "/*nothing*/";

this is because when i click next to view the next page of results it loads the same file e.g.

search.php displays the first page of results based on the search criteria entered into the search box, on this initial search.php page i can click next if there are more than a certain number of results, my problem is that the search criteria isnt remembered because it reloads the search page which will store the $_POST['textbox'] value and sionce it reloads and theres nothing to post the value is empty when the page reloads.

since the $_POST['textbox'] field will be empty when i click next to view the next page of the search results.

so I thought that maybe I need to somehow get the value from $_POST['textbox'] into a $_GET value so that when i choose "next" on the first page of results it passes the search criteria onto the next page and so on and on....

I am not sure, any ideas?

thanks again


PS- I was always throwing the idea of a session variale to store search criteria from the text box, not sure though thats why I am here .

[edited by: bysonary at 9:20 am (utc) on May 31, 2007]


9:19 am on May 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Once the SESSION values are set, you wouldn't need to change if that is what you are saying. You want keep on assign it to the POST. Assign the search text to the SESSION once, and keep on using the SESSION.

or use hidden text boxes, it is very widely used.



9:22 am on May 31, 2007 (gmt 0)

5+ Year Member

Yes i know but if i press next the code to set the session variable is reset the the value of $_POST['textbox'] which will be empty?

could i place it like this?

//do code


1:52 pm on May 31, 2007 (gmt 0)

10+ Year Member

when i click next to goto the next page it doesn't remember...

the link you click has a query string at the end. Just make that query string include the current query also (whatever you just searched for). like?page=1&query=


6:07 pm on May 31, 2007 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I would avoid sessions and use either hidden inputs or writing the query string into hrefs.

Reason? The same user could have two browser windows open with different queries in each one. Whichever was opened last would overwrite the search query of the first window.


12:10 pm on Jun 2, 2007 (gmt 0)

5+ Year Member

hey all your suggestions are great and I know how I could get it working in my theory but in practice its proving difficult.

here goes ill try explain once more

HOW do i get the value from the textbox, into the url header? I could use:

echo '<a href="search.php?ip='.$_POST['textbox'].'>Next</a>";

one problem there tho, when i click NEXT the form will be empty! so its like saying its nothing. Because each time next is pressed it reloads the same page only like this


you see what I mean now? when im on page 1, its fine yeah but on page 2 nothing was previously entered into the textbox so using $_POST['textbox'] would be wrong, or am i wrong?

any further advice here appreciated

ps - is it possible without session variables?


Featured Threads

Hot Threads This Week

Hot Threads This Month