Question

I have a website and i have a cover page that suggests the user logs in or registers, there is also a button to let them go to the site anyway. But i want it to detect if the user is actually logged in or not so that when they are logged in it will bypass the cover page and go to the home page.

Is there a way i can do this with PHP?

i currently just have the following code in my main page.

           <?php
        if(!isset($_SESSION['steamid'])) {
        steamlogin();
        }  else {
            include ('steamauth/userInfo.php');

          echo "Welcome back " . $steamprofile['personaname'] . "</br>";
          echo "here is your avatar: </br>" . '<img src="'.$steamprofile['avatarfull'].'" title="" alt="" />';

          logoutbutton();
        }    
        ?> 
Was it helpful?

Solution

What you did looks good, just some changes:

<?php
        if(!isset($_SESSION['steamid'])) {
            steamlogin();
        }  else {
            header('Location: loggedUserPage.php'); 
           //It's better to redirect the user to a different page on this scenarios
        }   ?>

OTHER TIPS

this is what i would do, or something like this.

if(isset($_SESSION['steamid'])) AND $_SESSION['steamid'] != '') {
    //user is logged in 
    header("location: index.php");
} else {
    // not logged in
    header("location: login.php"); // or  steamlogin();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top