MyBB Community Forums

Full Version: A PHP Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I am developing my site using PHP and I've seen a few sites using a different sort of address extension. It seemed quite neat and I was thinking about implementing it.

An example is:
page.php?id=content

I've searched on the internet but I don't really know what to call it. Could anyone please advice me what it's used for and how/if I should implement it?

Thanks a lot.
Using a different address extension? you mean the .php part? That stands for hypertext preparser and is the programming language it runs on. the id=content part is simply a $_GET variable (in php) passed from the URL.
(2008-12-12, 11:15 PM)Ryan Gordon Wrote: [ -> ]is simply a $_GET variable (in php) passed from the URL.

Or it can be a $_REQUEST variable which would work slightly different than the example url provided.
(2008-12-13, 05:16 AM)rcpalace Wrote: [ -> ]
(2008-12-12, 11:15 PM)Ryan Gordon Wrote: [ -> ]is simply a $_GET variable (in php) passed from the URL.

Or it can be a $_REQUEST variable which would work slightly different than the example url provided.

well yeh - tomato tamato
Yuck... $_REQUEST... The evil brother of the super global variables.
They're actually GET requests and they're usually to transfer content from a form to a page using PHP but they can also be used for separate content (as "virtual pages") by implementing something like this:

<?php
if($_GET['id'] == 5) {
echo 'Hello World!';
}
?>

now this code would echo the word Hello World to a page if the id is equal to 5 (i.e. id=5). This is a little complicated and it won't really achieve much more than that for the presumed knowledge you have in PHP.

$_REQUEST is a different superglobal variable that refers to both types of submissions available, GET and POST. The difference between $_GET and $_POST is that if you used a form and made it submit using a GET method, it would display the form contents in the URL address bar (as in, id=5 for instance) but POST methods won't, and simply transfer the data across hidden from the address bar completely. So you can either use $_REQUEST or $_GET, your choice.
(2008-12-13, 05:16 AM)rcpalace Wrote: [ -> ]
(2008-12-12, 11:15 PM)Ryan Gordon Wrote: [ -> ]is simply a $_GET variable (in php) passed from the URL.

Or it can be a $_REQUEST variable which would work slightly different than the example url provided.

$_REQUEST works exactly the same as $_GET, except $_REQUEST has $_POST in it aswell - $_REQUEST, as said above, shouldn't be used.
(2008-12-13, 04:00 PM)CraKteR Wrote: [ -> ]
(2008-12-13, 05:16 AM)rcpalace Wrote: [ -> ]
(2008-12-12, 11:15 PM)Ryan Gordon Wrote: [ -> ]is simply a $_GET variable (in php) passed from the URL.

Or it can be a $_REQUEST variable which would work slightly different than the example url provided.

$_REQUEST works exactly the same as $_GET, except $_REQUEST has $_POST in it aswell - $_REQUEST, as said above, shouldn't be used.

$_REQUEST shouldn't be used for the example url above. However, it can be used for something like this:
$mode = htmlspecialchars($_REQUEST['mode']);

file.php?mode=whatever

-------

Then, if you do an if statement as shown below, then whatever is in the if statement will be provided.

if($mode =='whatever') {
echo "Something!";
}

The $_GET as you put in your first post can be used for something like this:

$id = htmlspecialchars($_GET['id']);

$query = "SELECT * FROM tablename WHERE pid='$id'";

Using $_REQUEST won't necessarily work for this.

Plus, $_REQUEST can hold contents of $_GET, $_POST, and even $_COOKIE while $_GET is more primitive and can be used for the url you provided.
Why would you use $_REQUEST on that first example? It's the same as above. Mixing arrays isn't a good idea me thinks - what if you have a cookie named the same as the $_GET or $_POST? Oh that's not good.
(2008-12-13, 08:03 PM)CraKteR Wrote: [ -> ]Why would you use $_REQUEST on that first example? It's the same as above. Mixing arrays isn't a good idea me thinks - what if you have a cookie named the same as the $_GET or $_POST? Oh that's not good.

Exactly why I said you shouldn't use use $_REQUEST for this. I revised my post and made my sentence more understandable.
Pages: 1 2