Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Codeproject,

I was wondering what the section in a URL(with a PHP website) was called that allows for extra information.

The specific section I'm talking about is something along the lines of 'mysite.com?section=value".

I'd like to be able to write a simple if(section = value), and then perform a specific code, but since I don't know the name of it I can't find it on Google.

Best Regards,
- Nostarik
Posted

The string appears in the URL after '?' mark is called 'Query String'.

So, in your example, 'section=value' is the query string where 'section' is the query parameter. You can add more parameters in the query string as:

'mysite.com?section=value§ion2=value2§ion3=value3'
 
Share this answer
 
Comments
Dimitri Nostarik 21-Jan-15 18:08pm    
Thanks a lot Paul! Having a lot of fun here learning to create website. :-)
Sergey Alexandrovich Kryukov 21-Jan-15 18:40pm    
That's not all; please see Solution 2.
—SA
This is what you need to know: http://en.wikipedia.org/wiki/URI_scheme[^].

For parsing it, you could use:
http://php.net/manual/en/function.parse-url.php[^].

Now, with PHP, you don't have to parse all the URI string. You can use
PHP
$query = $_SERVER['QUERY_STRING'];


For parsing into separate query parameters, you could use
http://php.net/parse_str[^].

However, you can retrieve individual URL parameter using value if you know the key, such as in $_GET['key']:
http://php.net/manual/en/reserved.variables.get.php[^].

See also: http://stackoverflow.com/questions/5397726/parse-query-string-into-an-array[^].

I hope that's all you need.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900