Azu Posted December 18, 2006 Share Posted December 18, 2006 How can I get the get? I know that I can use $_GET[somethingspecific] to retrieve the value of somethingspecific, but what I am trying to do is just retrieve whatever is after the ?So if someone types in http://www.website.com/?asdf then the asdf would be retrieved. Whatever is it would be retrieved and put into a variable. Please can someone tell me how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/ Share on other sites More sharing options...
drifter Posted December 18, 2006 Share Posted December 18, 2006 well you can use $_SERVER and there are some options in there... try print_r($_SERVER) and take a look and see if what you need is there.Or maybe you need to[code]foreach($_GET AS $key=>$value){ echo $key . " " . $value;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143881 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 The latter would work better. Below is an example using $_REQUEST, so it will pick up all the values regardless of whether POST or GET was used.[code]<?phpforeach ($_REQUEST as $k => $v){ echo "$k - $v<br>\n";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143891 Share on other sites More sharing options...
thepip3r Posted December 18, 2006 Share Posted December 18, 2006 if you want to use $_GET so that you can pass along information via the URL string.... all you'd need is something simple like the following: www.website.com/somepage.php?var=dataand then the code to grab that data: [code]if ($_GET['var']) { echo $_GET['var']; # would write "data" to the screen}[/code]Edit: Do not use $_REQUEST. It's a security nightmare -- there are many articles describing reasons not to but the most basic is this. $_POST is often used when you don't want the user to have the availability to just pass information via the url string. When you're using $_REQUEST, your $_POST specific code (if you have any) becomes vulnerable to malicious code injection. Just somethign to think about. Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143896 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 [quote author=thepip3r link=topic=119158.msg487619#msg487619 date=1166474817]Do not use $_REQUEST. It's a security nightmare[/quote]$_REQUEST should be taken into consideration with regards to security, but to say don't use it isn't really helpful. There are uses for it and if used correctly, can be perfectly secure.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143914 Share on other sites More sharing options...
thepip3r Posted December 18, 2006 Share Posted December 18, 2006 this isn't the place to stand on a soap box but it IS helpful to push people away from using things like $_REQUEST and register_globals because they don't understand what they're doing when they use such superglobals and if they simply take 5 minutes to understand the subtle differences between $_GET and $_POST, they don't need to mess with $_REQUEST. If a proficient PHP programmer wants to user $_REQUEST and accept the security risks, so be it. Don't push the noobies towards the easy answer that will lead them and their code to a vulnerable state because they won't know how to "secure" $_REQUEST the way it needs to be. Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143930 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 Fair comment.Huggie Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143934 Share on other sites More sharing options...
heckenschutze Posted December 18, 2006 Share Posted December 18, 2006 your after [color=blue]$_SERVER['QUERY_STRING'];[/color]Which will return the query string (everything after the ?)...Also, its not 'programming' unless its compiled, therefore your a proficient PHP [i]scripter[/i]. Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-143959 Share on other sites More sharing options...
drifter Posted December 18, 2006 Share Posted December 18, 2006 [quote author=heckenschutze link=topic=119158.msg487682#msg487682 date=1166478113]your after [color=blue]$_SERVER['QUERY_STRING'];[/color]Which will return the query string (everything after the ?)...Also, its not 'programming' unless its compiled, therefore your a proficient PHP [i]scripter[/i].[/quote]I thought php was compiled for before it ran.... and if you run a cache system - it stores it in compiled format... So what is really the difference then? manual compiling vs automatic compiling? Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-144018 Share on other sites More sharing options...
thepip3r Posted December 18, 2006 Share Posted December 18, 2006 [quote author=heckenschutze link=topic=119158.msg487682#msg487682 date=1166478113]your after [color=blue]$_SERVER['QUERY_STRING'];[/color]Which will return the query string (everything after the ?)...Also, its not 'programming' unless its compiled, therefore your a proficient PHP [i]scripter[/i].[/quote]I am aware of the differences between the definitions but when you're looking for a job, employers look for PHP [b]Programmers[/b]. I've never seen a category for a job listing for a PHP [i]scripter[/i].Drifter: PHP is an interpreted language, not a compiled language, and in that, lies the subtle difference with what hecken was trying to get across. Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-144033 Share on other sites More sharing options...
drifter Posted December 18, 2006 Share Posted December 18, 2006 I think the lines between scripting and programming are not really existant at all - not when you look at everything like php, java, c#, c++ and then try to categories there is not real difference. Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-144063 Share on other sites More sharing options...
thepip3r Posted December 18, 2006 Share Posted December 18, 2006 I'm not trying to argue with you drifter, i was just telling you that in all of the classes I've taken for programming specifically point out that "programming" is used in reference to a compiled language (like C++, etc) and "scripting" is used for an interpreted language (VBScript, Javascript, PHP, KiX, ASP, etc.) -- Languages like PERL and Java are unique because they can be both compiled or interpreted. Official definitions from Wikipedia:[url=http://en.wikipedia.org/wiki/Interpreted_language]Interpreted Language[/url][url=http://en.wikipedia.org/wiki/Compiled_language]Compiled Language[/url] Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-144069 Share on other sites More sharing options...
heckenschutze Posted December 19, 2006 Share Posted December 19, 2006 C++ is compiled to Machine code, Whereas PHP and Java are compiled to Byte Code and interpreted by a VM...BIG difference. Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-144351 Share on other sites More sharing options...
Azu Posted December 19, 2006 Author Share Posted December 19, 2006 Thanks guys :) Quote Link to comment https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/#findComment-144836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.