how to implement PHP session manually

ε祈祈猫儿з 提交于 2019-12-11 11:05:02

问题


I am new to PHP. I want to implement PHP session manually. On a PHP pageload, I will check if cookie is set. If yes, I will display the required information, and if not, I will ask user to enter his details and then display the information. But I am not allowed to use PHP Sessions. I can use Cookies. Also the information needed to be displayed is about all the users (browsers) who are in session (so I have to save this to some static global array). Any help is appreciated. Thanks.


回答1:


try this

setcookie('cookie_name', 'cookie_value', time());
echo $_COOKIE['cookie_name'];

Now check the cookie if it exists.

if(isset($_COOKIE['cookie_name'])) {
    echo "your cookie is set";
} else {
    echo "return error or any thing you want";
}

This will give you all browser(s) information.

echo $_SERVER['HTTP_USER_AGENT'];


来源:https://stackoverflow.com/questions/18605474/how-to-implement-php-session-manually

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!