? after page

They have: 1 posts

Joined: Jul 2006

Hi.

I am new to PHP and notice that on alot of other sites including this one have a ? after the php and then have text afterward. For example I saw a mysite.com/index.php?id=202 (that is just an example). If you would change the 202 to say 201 it would show a different page. How do you achieve this. Are they using a template page, and just calling a different document or what?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

This is data (arguments) passed the the apge being called. In PHP you can access these values via the predefined $_GET array. In the example you gave, $_GET['id'] would be set to 202. you can have more than one, they are generally given in the format of ?name=value&name=value&name=value

Be sure that you always validate/check the values before just using them in a script. If you go to use any values in things such as URLs, Filenames, SQL statements, etc, make sure that you escape out the values with something like addslashes().

-Greg

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

Most PHP installations do an auto addslashes to $_GET input, so if you echo them to the page or send them to somewhere that won't strip or need the slashes, you will want to stripslashes the output.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.