Friday, July 25, 2014

How to set a cookie in PHP

Setting a cookie in PHP is very easy and takes just a few lines of code.

If you are authenticating a username, you could use this code below to set a cookie.

<?php

$username = $_POST["username"];

if ($username == "test") {

setCookie("cookietest");
echo "You are logged in";

} else {

echo "Please try again";

}

?>

I hope this helps your general knowledge of how to set a cookie in PHP

Check out my car information app if you get a chance


No comments:

Post a Comment