-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?

Brad
  • 159,648
  • 54
  • 349
  • 530
Lucas Stanesa
  • 71
  • 2
  • 7
  • some light reading material: http://stackoverflow.com/questions/679013/get-vs-post-best-practices http://www.php.net/manual/en/language.variables.superglobals.php http://www.php.net/manual/en/reserved.variables.post.php http://www.php.net/manual/en/reserved.variables.get.php –  Aug 16 '12 at 03:22
  • 1
    This question should be re-opened. There is nothing ambiguous, vague, incomplete, overly broad, or rhetorical about it. It most certainly **can** be answered in its current form, as evidenced by the two answers (both of which contain up-votes) below. If your reason for voting to close is that you think this is obvious, consider for a moment that your attitude towards questions like this is one of the reasons folks have trouble learning. Sure, a "read the documentation" comment is appropriate, but it isn't a question that should be closed. It's hard for folks to get started sometimes. – Brad Nov 17 '12 at 04:23
  • It's not post data, it's a query string. – John Saunders Nov 17 '12 at 04:43

2 Answers2

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'].

Brad
  • 159,648
  • 54
  • 349
  • 530
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.

MMS
  • 408
  • 2
  • 5
  • 9