Goodmorning, I'm a university student and I'm trying to do a basic exercise about PHP, in particular I'm trying to set a cookie (Country) with the value IT. The task is to open the page a, then click on the link "pagina successiva" (next page in English). The browser will open the page b which should read the value of the cookie Country and and visualize (if exists). In professor's request it is written that I don't have to set an expire time. Here is my code of page a:
<?php
$value = 'IT';
setcookie('Country',$value, 0, "", "", TRUE);
?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<title>Esercizio 10.1 pagina A</title>
<meta name="author" content="Pippo Baudo" >
<link rel="stylesheet" type="text/css" href="../sol10_css/lab10_style.css">
</head>
<body>
<h1>Esercizio 10.1a</h1>
<p>Italia!</p>
<p><a href='10_1b.php'>Pagina successiva</a></p>
</body>
</html>
Here is my code of page b:
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<title>Esercizio 10.1b</title>
<meta name="author" content="Pippo Baudo" >
<link rel="stylesheet" type="text/css" href="../sol10_css/lab10_style.css">
</head>
<body>
<h1>Esercizio 10.1 pagina B</h1>
<?php
if(isset($_COOKIE["Country"])){
$nazione = $_COOKIE["Country"];
echo"<p>Il valore del cookie COUNTRY è $nazione </p>";}
else{
echo"<p class='err'> ERRORE: Cookie \"Country\" assente</p>";
echo"<p><a href='10_1a.php'>Pagina precedente</a></p>";}
?>
</body>
</html>
The output on the page b says that the cookie is not set, so it is absent.
I can't figure out what I'm doing wrong. Can anyone please halp me?
Edit: the error says when I open page a is: Parse error: syntax error, unexpected 'setcookie' (T_STRING) in /app/lab10/10_1/10_1a.php on line 3