简体   繁体   中英

PHP Get Values out of URL Query String without Key / Value pairs

I need to get the values out of a URL query string like this:

http://exmaple.com/?xyz.123

And assign them to variables inside index.php running on example.com, so that:

$name = xyz;
$number = 123;

How do I code this?

Thanks!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM