Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving data passed through url

Status
Not open for further replies.

toneyamber

Programmer
Joined
Aug 26, 2003
Messages
3
Location
US
I am using fastemplate that allows me to have my php pages load html templates. That all works fine and dandy. Now, in one of my html templates I load the data in dynamically from MySQL database and the users are allowed to select the data that is pulled up. That data is inside a href tag in the html, so that when the users click on one, it automatically goes to another php page. When they click on the href I am trying to send data along with it ex.
< a href=&quot;/sub.php?id={ID}&quot;>{NAME}</a>
It sends the id fine, but problem is now being able to retrieve that id from the url to allow my sub.php page to use it and load the html template based off of that id. I really hope this makes sense. I know this is possible because I have done it before, but that was a long time ago, and I can't remember.
Thanks,
Amber
 
When you send data through the URL like that, it is sent using the GET method.

To access this data you would use the global $_GET[] variable.

i.e.

$id = $_GET[id];

The opposite would be $_POST[]. Post data is sent by default when you click the submit button on a form (this can be changed however with the method=&quot;get&quot; variable within the form tag).


- &quot;Delightfully confusing...&quot; raves The New York Times

-kas
 
Thank you so much for your fast replies. I was kind of thinking of something like that, just couldn't remember the function. Anyways, thank you so much guys.
Amber
 
Be aware that there is a restirction in the size of values passed using the GET method. Browsers have maximum URL length etc.
All values are also clear text exposed to the visitor. They can also just type arbitrary values and append it to the query string. Make sure that does not mess up the function of your code. Filter out any possible malicious vars.

I would recommend to use POST rather than get.
 
The limit on GET varies from browser to browser -- on IE I believe it's a little over 2000 bytes.

The real limit comes from the fact that GET-method data is handed to a script via a single environment variable, and most OSes limit the size of an environment variable to 255 bytes.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thank you for the information. By the way the get worked fine, that was exactly what I was looking for. I used get vs. post, because the id's that I am passing are very small and I know what exceed much. Thank you for that information though, because I am building a form and will have to use the post method for that one. Again, thanks for all of your help.
Amber
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top