SkId_mARK Posted January 6, 2003 Share Posted January 6, 2003 Ok, so i am just starting out with php and i have this question. How do i get the variables from the http address and save them as a variable in my php? Ex www.somesite.com/index.php?somting=what_i_need_to_get I have been using ASP till i switched my host, could someone point out the function to me? Thanks Linton Link to comment Share on other sites More sharing options...
0 parrots Posted January 6, 2003 Share Posted January 6, 2003 $_REQUEST['what_i_need_to_get'] is the variable you want. Link to comment Share on other sites More sharing options...
0 SkId_mARK Posted January 6, 2003 Author Share Posted January 6, 2003 Thanks for the fast reply but I have 2 more small questions. 1) " $_REQUEST['what_i_need_to_get']" shouldn't 'somting' be requested because the other part is what is going to change. 2) Is it saved to the variable $_REQUEST or would my line look like $address = $_REQUEST['what_i_need_to_get']? Again Thanks EDIT! Wo rked it out myself ... thanks! Link to comment Share on other sites More sharing options...
0 parrots Posted January 6, 2003 Share Posted January 6, 2003 (edited) $_REQUEST[] is like request.querystring() or request.form() in ASP, except it gets both post and get submissions. Lol, reread my post, sorry, "something" should be the thing in quotes, you are right. Edited January 6, 2003 by parrots Link to comment Share on other sites More sharing options...
0 Quboid Posted January 6, 2003 Share Posted January 6, 2003 Many hosts won't require you to do anything - you can just call $somting. However, this is bad practise. PHP allows you to get it in 4 better ways. $address = $_POST['somting']; /* Or the next one: */ $address = $HTTP_POST_VARS['somting']; /* These two will get data passed by the POST method, usual used by forms */ $address = $_GET['somting']; /* Or the next one: */ $address = $HTTP_POST_VARS['somting']; /* These two will get data passed by the GET method, usually used by, as you put, vars on the end of the URL string, sometimes used by forms aswell */ $address = $_COOKIE['somting']; /* Or the next one: */ $address = $HTTP_COOKIE_VARS['somting']; /* These two will get data saved on the client machine as cookies. */ $address = $_REQUEST['somting']; /* This is probably the handiest if you're not fussy about source, any of GET, POST or COOKIE */ The last one will usually do the job but you might want to be careful. If you are expecting data through a form and you have an important variable passed as in a hidden field, if the visitor sees this and alters it he will be submitting it as a GET data type. If you use $_REQUEST, you're script won't notice this and accept it. This shouldn't be a problem as all variables should be checked anyway, but that's a whole other story and better safe than sorry anyway. Link to comment Share on other sites More sharing options...
Question
SkId_mARK
Ok, so i am just starting out with php and i have this question. How do i get the variables from the http address and save them as a variable in my php?
Ex
www.somesite.com/index.php?somting=what_i_need_to_get
I have been using ASP till i switched my host, could someone point out the function to me?
Thanks
Linton
Link to comment
Share on other sites
4 answers to this question
Recommended Posts