-1

I am trying to get an HTML/PHP script to interpret data sent after the ? in a url. I've seen sites that do this, YouTube being one of them. I thought this was called Post Data (not sure if it is), I've been searching for a few days, and I can find is the PHP $_POST[''] with some HTML forms reading the data from a textbox, but I would like to read directly from the url, EX. www.example.com?ver=1

How would I go about doing this?

4

2 回答 2

7

What you're looking for is called a query string. You can find that data in $_GET.

print_r($_GET);

If you need access to the raw data (and you probably don't, unless you need multiples for some variable names), check $_SERVER['QUERY_STRING'].

于 2012-08-16T03:17:13.680 回答
3

You can't do that in HTML pages. In PHP pages, you can read (and process) the parameters using the $_GET array. This array contains all the things after which come after ? in the URL. Suppose we have a URL like

page.php?a=b&c=d

Then we can access a and c parameters by $_GET['a'] and $_GET['b']. There is also $_POST which works a bit different. You can google it to find out more.

于 2012-08-16T03:42:04.693 回答