I am creating profile page I will distinguish if user is visiting own profile or other users with this simple code
if(isset($_GET['username']) && !empty($_GET['username'])) {
$username = $_GET['username'];
}
else {
$username = $_SESSION['username'];
}
Now the problem is I am using session and cookies both for auto-login feature. On header.php
and accountsettings.php
I am defining username like this:
if(isset($_SESSION['username'])) {
$username = $_SESSION['username'];
}
else if(isset($_COOKIE['username'])){
$username = $_COOKIE['username'];
}
else
{
//invalid ---
}
This code works fine for both pages, so how to set username on profile page where it checks if $_GET['username']
, or if $_SESSION['username']
or $_COOKIE['username']