You already have the answer to your problem, but since no one has explained how to read the error, here is my contribution so that in the future you can understand what PHP is saying:
Parse error: syntax error, unexpected '{' in C: \ xampp \ htdocs \ exercises \ saber2 \ php \ session.php on line 4
The error is divided into 3 parts:
-
Type of error:
You get Parse error
, from the E_PARSE
family, which are basically errors that will prevent execution from continuing.
-
Error:
You get syntax error
which indicates that something is wrong with the PHP code whose interpreter can not understand.
-
Description:
The description of your error identifies the problem, the line and the file where the error is located.
In your case, unexpected '{'
in line 4
of file C:\xampp\htdocs\exercicios\saber2\php\session.php
, that is, a {
was found in line 4 of said file, when something else was expected.
Since the error points to an unexpected character, the actual problem is before it:
#01 <?php
#02
#03 session_start();
#04 if(isset($_SESSION['user']){
#05 echo "<script>document.location.href='../areaprivada.html';</script>";
#06 }
#07 else{
#08 echo "<script>document.location.href='login.php';</script>";*/
#09 }
#10 ?>
And so, on your line # 4, before {
should be something else. Analyzing from the beginning of the line up to {
we finally realize that we have to close the parentheses of the if
condition with a )
.
More about errors and their types: