Trying to learn cookies in PHP to me everything seems fine but it doesnt even set the cookie
here is the code
<?php
if (isset($_COOKIE['user'])) {
header('Location: simple.php');
} else {
if (isset($_POST['submit'])) {
if (isset($_POST['username']) && isset($_POST['password'])) {
if (isset($_POST['checkbox'])) {
$expire = time() + 60 * 60;
setcookie('user', $_POST['username'], $expire);
} else {
header('Location: simple.php');
}
} else {
echo 'Please Enter Your Information !';
}
} else {
echo 'Please Submit';
}
}
?>
Edit
tried
<?php
setcookie("testcookie","testvalue",0);
echo $_COOKIE['testcookie'];
?>
Result is
Notice: Undefined index: testcookie in /var/www/php-practice/cookies/test.php on line 1
and it sets the cookie testcookie
in browser with the value testvalue
Feel there is some error in $_POST['submit']
because
if (isset($_POST['submit'])) {
//everything else
} else {
echo 'Submit Button Problem !';
}
it prints the Submit Button Problem !
here is the HTML of the submit button
<input type="submit" value="Submit" name="submit" />
Looked at this question and tried it but still nothing
I tried everything I could but it doesnt work
Help !