-1

I'm having issues with my simple PHP script. I want if $_SESSION['username'] is set to redirect to welcome.php, if not, it goes to /login.php I thought it would be easy but i seem to have some issues.

INDEX.php

<?php
session_start();
if(isset($_SESSION['username']))
{
  header("Location","/welcome.php");
}
else
{
  header("Location","/login.php");
}
?>
Syscall
  • 18,131
  • 10
  • 32
  • 49
Mattia Marziali
  • 99
  • 1
  • 1
  • 7

1 Answers1

1

Add exit after you redirect to page whenever you do it with condition. Also write header function as below

<?php
session_start();
if(isset($_SESSION['username']))
{
  header("Location: /welcome.php");
  exit();
}
else
{
  header("Location: /login.php");
  exit();
}
?>
B. Desai
  • 16,264
  • 5
  • 24
  • 44