954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

a basic thing to know....

is it good to ask whats the use of id while working with php.... if u talk abt property . whose property is it.. the link of the present web page or that of the destination page that the codes makes the page to get redirected..........

nostalgia149
Newbie Poster
23 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

more elaborate your Ques with an example..???
are you talking about Id which u get from database...??? :)

innocent.boys
Newbie Poster
12 posts since Jul 2009
Reputation Points: 11
Solved Threads: 1
 

hiiiiiiiiiiii................. i m talking abt the id which is associated with the page of the present web page....................like...........
MAKE CHANGES IN THE RECORD

nostalgia149
Newbie Poster
23 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

nostalgia149,
It's called query string. It is used to pass some information/data between page request.

__avd
Posting Genius (adatapost)
Moderator
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)
Moderator
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)
Moderator
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.


thanks ardav... so id is mainly for linking two pages using a common entity .. is it???????? where else is it useful apart frm this n common applications?????????????????

nostalgia149
Newbie Poster
23 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 
You may use $_REQUEST for the same.


hi.. adatapost... with the little understanding of php wht i hav understood is that.. we use request whn v use certain data frm the same page and use the database.. in case of post v use it whn v hav to get the data frm a different page.. forget get for the time being.... how far is my conception right??????????????/

nostalgia149
Newbie Poster
23 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

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)
Moderator
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.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

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}&amp;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)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

thanks a lot ardav........... i guess things r getting clearer now..........

nostalgia149
Newbie Poster
23 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You