Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql injection for sessions

I used mysql_real_escape_string() to prevent sql injection for the $field variable below. Should I use the same for $_SESSION['user_id']?

I can't imagine someone being able to change a value in the $_SESSION array. Can they?

$query = "SELECT `".mysql_real_escape_string($field)."` FROM `users` WHERE         `id`='".$_SESSION['user_id']."'";
like image 965
Pavan Katepalli Avatar asked Mar 15 '26 00:03

Pavan Katepalli


1 Answers

They can't change the $_SESSION array, but your problem totally depends on how you initialized $_SESSION['id']. In a general way, you should always escape values in a SQL query. Don't try to guess whether or not values can be modified from an user input, just escape them.

like image 171
ldiqual Avatar answered Mar 17 '26 12:03

ldiqual



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!