Skip to content

Instantly share code, notes, and snippets.

@jayllellis
Last active August 29, 2015 14:06
Show Gist options
  • Save jayllellis/b46b5df903f7f526b35a to your computer and use it in GitHub Desktop.
Save jayllellis/b46b5df903f7f526b35a to your computer and use it in GitHub Desktop.
PHP setcookie
<?php
if( isset($_COOKIE['cw_section']) ){// cookie is set
$redirect_section = $_COOKIE['cw_section'];
if($redirect_section == 'doctor'){
header('Location: http://www.example.com/doctor/');
}
else{
header('Location: http://www.example.com/patient/');
}
}
else{// cookie is not set
if(isset($_POST['submit']){// if form submitted
$value = $_POST['section'];// get the value of the section field
setcookie("cw_section", $value, time()+3600, "/", "example.com");// set the cookie with the field
header('Location: http://www.example.com/patient/');// redirect to that section
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment