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();
        }    
        ?> 
Était-ce utile?

La 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
        }   ?>

Autres conseils

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();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top