nostalgia149,
It's called query string. It is used to pass some information/data between page request.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
The id to which you refer can mean ANYTHING. Using 'id' in the querystring is just force of habit for most programmers when you want to pass a variable such as member id, page id etc. In these instances, the 'id' is often used for data retrieval from a database or a file. A common usage for this would be to get a record or records from a database table which has a field that has that particular id value.
pHp uses the $_GET variable, in this instance the $_GET['id'] variable, to pass on the data from one page to another as mentioned by adatapost.
Good question.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
You may use $_REQUEST for the same.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
The 'id' to which you refer, is meaningless. It's just a name (or 'key') in a querystring (the bit at the end of the url following '?') to which you can assign a value, which can be almost anything.
e.g. If this is your website and you wanted to send info to a page to delete an user:
http://www.example.com/delete.php?id=12389&confirmcode=hy6io98
You could equally have used:
http://www.example.com/delete.php?user=12389&confirm=hy6io98
You would then, in this instance use$_GET['user'] in your delete.php file to get at the data (12389) as opposed to using $_GET['id'] in the first example.
$_GET can also be used with forms if you set the 'method' attribute to 'get'. I would advise against this, use 'post' if possible.
adatapost may get back to you about $_REQUEST, so I won't step on his toes by giving an explanation.
So the querystring (rather than calling it the 'id'), is a way of passing data to the page in question.
BTW: you wouldn't necessarily delete an user through a querystring, there are more secure ways of doing this.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Just be very careful when working with values passed in the GET & POST arrays . Its extremely easy for them to be modified by the user and you have to be fully aware of this.
Probably the most common thing i've seen is the usage of $_GET and $_POST in queries or being used to dynamically include files in their raw, straight from the url, forms.
Precisely. This is why you should always pass a hashed key-value along with the other key-values. Probably the best known is md5, but you should use a 'salt'. Example:
http://www.example.com/delete.php?user=56
The above could be generated by a link on a different page, but could easily be modified by an user to 'user=67' etc and create havoc. You'd need to add somehting like a confirmation code:
http://www.example.com/delete.php?user=56&confirm=hsy692jsygbkchy279hscuybew0po3y7
This 32-character code can be generated like this:
<?php
$usr = "7";
$salt = "gibberish";
$cf = md5($usr . $salt);
?>
<a href="delete.php?<?php echo "user={$usr}&confirm={$cf}";?>">delete me</a>
In the delete.php page, you'd then check the user value against the confirm code:
if($_GET['conf'] == md5($_GET['user'] . 'gibberish'){
..do your stuff..
}
That's a very simple usage, for extra security you'd want something a little more secure again, e.g. double hashes or pseudo-random salts.
md5 is a one-way thingy, you can't 'un-md5' and get your original data, well not very easily anyway.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080