문제

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();
        }    
        ?> 
도움이 되었습니까?

해결책

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

다른 팁

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();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top