Search code examples
phpcookiessetcookie

Unable to set cookies in local machine


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);


Solution

  • after so much of searching in internet i found the solution, the main thing you need to display a php page is first you need to install the php, to install php use this command

    $ sudo apt-get install php

    after installing php you need to type this command

    $ sudo a2enmod proxy_fcgi setenvif

    $ sudo service apache2 restart

    here is reference