PHP - Sessions and cookies

Asked

Viewed 70 times

1

I have a page login.php which after being filled goes to the processa.php and then enter the session and cookie:

$cookie_name = "Administrador";
$cookie_value = $id;
setcookie($cookie_name, $cookie_value, time() + (3600), "/");
$_SESSION['user'] = $id;
header("Refresh: 0; url=MENU/menu.php");

And on the page login.php, i wanted to do something like, if the user who has already logged in, want to go back to the site, and go to the login, the login checks if the session still exists and sends it back to the menu.php. I did it this way but it doesn’t seem to work:

<? 
session_start();

if(!isset($_SESSION['user']))
    {
        setcookie("Administrador");
        session_destroy();
    }else
    {
        $user = $_SESSION['user'];
        header("MENU/menu.php");
    }
?>
  • 1

    Try it like this: header("Location: MENU/menu.php");

  • 1

    I always used a refresh header that I forgot Location existed! I was embarrassed! Thanks for reminding me Van.

1 answer

0


You can use the PHP header function

header("Location: http://www.seusite.com.br");

More details here: php header function

Browser other questions tagged

You are not signed in. Login or sign up in order to post.