Jump to content

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/31149-solved-finding-out-the-get/
Share on other sites

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]<?php
foreach ($_REQUEST as $k => $v){
  echo "$k - $v<br>\n";
}
?>[/code]

Regards
Huggie
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=data

and 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 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.

Regards
Huggie
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 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 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.
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.