I need to get the values out of a URL query string like this:
And assign them to variables inside index.php running on example.com, so that:
$name = xyz;
$number = 123;
How do I code this?
Thanks!!
4 Answers 4
list($name,$number) = explode('.',$_SERVER['QUERY_STRING']);
You can parse it with the following, though it is ripe for injection unless you perform some validation/sanitization afterwards:
list($name, $number) = explode('.', $_SERVER['QUERY_STRING']);
What you want to do is take a look at $_SERVER['QUERY_STRING']
. Explode the query string by .
to get an array of values. You can then set up the appropriate variables. Keep in mind you'll also probably want to do some validation on the data to ensure it's in the format you need.
You'd need to setup a mod_rewrite rule first like this (untested)...
RewriteRule ^([a-zA-Z]+)\.([0-9]+)$ index.php?name=1ドル&number=2ドル
Then you could pull them out from $_GET
in PHP.
?xyz=123
? This will form a key/value pair that you can access using$_GET
.