John Davidson

php - Unable to set cookies in local machine

0 comments
Message:


i want to set cookies to the webpage, the webpage with extension .php has this content


<?php
setcookie("engineer","engineer",time()+3600);
?>
<html>
<img src= "image3.jpg" height="300" width="300"/>
</html>

i created a apache2 server in my ubantu virtual machine, and placed the above file with name test.php in the /var/www/html folder and tried to access the website, the website got opened but the cookie was not set :( i don't the reason why cookie has not set. i tried some answers from stackoverflow but still not able to set cookie anyone help me in this
Here is what i tried



  1. added the '/' for path


    setcookie("engineer","engineer",time()+3600,'/');
    but still not able to setcookie



  2. uninstalled and reinstalled the apache2 server but still same issue.



  3. also tried by removing time() in that line
    setcookie("engineer","engineer",3600);





My Answer:
setcookie("user", "John Doe", time() + 3600, "/");
?>



";
} else {
echo "Cookie not set!";
}
?>

Rate this post

4 of 5 based on 1695 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us