-2

my php code is

<?php
session_start();
if(!isset($_SESSION["userId"]){
header('Location: index.php');
exit;
}
?>

and i got an error

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\page\login.php on line 3

can anyone help me to solve this problem

Neetesshhr
  • 526
  • 1
  • 8
  • 20

1 Answers1

1

That's because you forgot a closing bracket ) before the opening curly bracket {:

<?php
    session_start();
    if(!isset($_SESSION["userId"])){
        header('Location: index.php');
        exit;
    }
?>

When you get an unexpected character syntax error in PHP, it's usually because there is a character missing right before it

Jonan
  • 2,485
  • 3
  • 24
  • 42