Jump to content

Securing $_GET


Eiolon

Recommended Posts

Are there any tutorials on this?  Basically, I want to make it so people can't type in the URL to delete a record and whatnot.

 

Also, what are your thoughts on using $_SESSION instead of $_GET to navigate records?  For example, use $_GET to set the session and use the session thereafter to do the queries.

Link to comment
Share on other sites

its not more secure, its an illusion really, post data can be modify, sure it takes additional steps, but still can be done.  The advantage to get over post is that a page can be chached or accessed through non conventional methods such as a hyperlink.  In generally you should always use post and when you find a strong advantage for get you use get.

Link to comment
Share on other sites

Who said anything about data that is being submitted to the database? The OP was asking about a delete function which, I presume, would accept a record id. The user would not typically know/care about the record IDs as they should not be customer facing.

 

But, cooldude is 100% correct. Any data submitted through POST or GET should be considered possibly malicious and must be properly validated and sanitized. Just as a user can enter data on the URL they may also create their own forms to post data.

Link to comment
Share on other sites

Any data submitted through POST or GET should be considered possibly malicious and must be properly validated and sanitized. Just as a user can enter data on the URL they may also create their own forms to post data.

 

Yes, this is what I was referring to.  Is there any information on how to "validate and sanitize" the data?

Link to comment
Share on other sites

So wait, you are saying I should use POST to RETRIEVE data?  How would I delete a record by using POST?  I thought I need to call the record id in order to delete it, hence I used GET.

 

In some ways yes.

 

But, cooldude is 100% correct. Any data submitted through POST or GET should be considered possibly malicious and must be properly validated and sanitized. Just as a user can enter data on the URL they may also create their own forms to post data.

 

I agree and that's why for this situation I'll prefer using a combination of POST,Session, and encryption/decryption.

 

Yes, this is what I was referring to.  Is there any information on how to "validate and sanitize" the data?

 

There are many ways around this.

 

1. Data Level: don't ever use small digit id's as much as possible mask it.

2. I was thinking of use js to encrypt your data and get it so it will show in your url and in your source the encryption but use php to encrypt it using sessions.  Should be harder to crack rather than having straigh POST or straight Session.

Link to comment
Share on other sites

TIP TOP TIPS EVERYONE LOl ... THIS IS SHORT BUT IMPORTANT>>>

 

never ever do this

 

$sql= "select * from table".$_POST[value];

y?

if my post or get is >>>  4; delete tablename;

$sql= "select * from table".$_POST[value];

it will select and delete your table

 

better to do this

$sql= "select * from table {$_POST[value]}";

in this case you will get sql error if you try the first value i posted..(4; delete tablename;)

 

and also try to always limit your query

so if ever he get your system hack he can only delete your records one by one not once in a row

 

DOES IT MAKE SENSE lol ;)

 

Link to comment
Share on other sites

When i insert data i always use escape strings and the sprintf() function.

 

e.g.

 


$password = mysql_escape_string(htmlspecialchars(MD5(MD5($_POST['password']))));

$sql = mysql_query(sprintf("INSERT INTO `users` ( `password` ) VALUES ( '%s' )", $password)) or die('Error: ' . mysql_error());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.