Jump to content

Need advice on url security


clairian

Recommended Posts

Hi,

 

I am quite new to php and need to secure my site as it will hold personal info.

 

For example, when a user selects:

<a href="EditTenantFormT.php?UID=<?php echo ($row['UID']) ?>">Edit My Details</a>

 

It passes them to a page to edit their data. However, as the 'user id' is passed through the URL this is not secure as the db can be queried through the URL:

http://localhost/OceanBlue/EditTenantFormT.php?UID=20

 

What would be the best (and easiest) method of stopping the UID being shown in the URL. I did try urlencode/urldecode but it didnt seem to work - is this the best method?

Link to comment
https://forums.phpfreaks.com/topic/97615-need-advice-on-url-security/
Share on other sites

to explain on papaface post (which i recommend),

personally i store the userid in a session ie $_SESSION['UserID'],

then have a routine to check the access level (if that level allows me to edit others records then i accept the get "UserID=xxx" from the URL if not i ignore it.. and set theID back to the UserID

 

ie

<?php
start_session();
$isAdmin = checkaccess($_SESSION['UserID']);

if (isset($_GET['UID']) && ($isAdmin === true))
{
$uID = $_GET['UID'];
}else{
$uID = $_SESSION['UserID'];
}

//Load records with $uID as the userID

function checkaccess($userID)
{
//search user ID in mySQL and get UserLevel
if ($userlevel == 1)//whatever is the Admin Level
{
return true;
}else{ 
return false;
}
}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.