开发者

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

开发者 https://www.devze.com 2023-03-20 16:04 出处:网络
I need to get the values out of a URL query string like this: http://exmaple.com/?xyz.123 And assign them to v开发者_运维百科ariables inside index.php running on example.com, so that:

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

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

And assign them to v开发者_运维百科ariables 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消