I used $_SESSION['name'] to handle data from page to page. I mainly used it to keep the user logged in between pages. Within every page, i check if $_SESSION[logged_in'] is true or not. If true, keep user logged in. Otherwise, do something else.
This is how i handle my sessions - basic sample:
<?php
session_start();
if($_SESSION['logged_in'])
{
//show control panel list
}
else
{
//show login box. Once user logs in. Once user logs in,
//fetch userID, username, etc from database. Also set
//$_SESSION['logged_in'] = true.
}
?>
Somewhere in between codes i do the following:
SELECT * FROM User WHERE userID = $_SESSION['userID'];
I'm not sure if $_SESSION['userID'] would be accessible by users or not. If its accessible, then the page would be in threat because a user could change the userID manually and get access to others account he/she desires.
I'm not much into security. Please advice! What can i do?
Note: i'm trying to make code as simple as possible. For now, no oop is involved.
Your code is vulnerable to session fixation and session hijacking attacks. See http://phpsec.org/projects/guide/4.html for more information.
As you build bigger, more involved applications, you will also want to be careful how you handle logging the user out and handling other session-related aspects, such as privilege escalation. Handling sessions and logins safely is a tricky beast.
Implementing secure authentication is hard. Unless you are doing it as an academic exercise, i would strongly recommend using the library provided by your framework, if you are lucky enough to have a good one.
You will also want to consider things such as the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With