how do I show a php page just once only per user

2019-04-15 02:06发布

Hi I have a php page that I want show it just one time per user.

I think this just might be possible with cookies,session-timeout or session-cookies.

But I'm not sure.

Thanks for your kindness :)

3条回答
你好瞎i
2楼-- · 2019-04-15 02:18

you answered your own question - by setting a cookie.

// check if they've been here, if they haven't set
// a cookie for subsequent visits
if($_COOKIE['beenhere']) { 
    setcookie("beenhere", '1');
}
else {
    // where you want them to go if they've seen this page
    header('Location: http://www.example.com/');

For more information:

If you want a single user to -never- see the page again, you must set an expiration for the cookie (see linked page above) as closing the browser will eliminate the cookie as I've set it above.

查看更多
可以哭但决不认输i
3楼-- · 2019-04-15 02:22

You may also use sessions

if($_SESSION['sessioned_here'] == null) {
    // just been on this page
} else {
    // visited already. get out

}
查看更多
三岁会撩人
4楼-- · 2019-04-15 02:33

To show a page once per-user-session you can try the following

//mypage.php

if(!isset($_SESSION['mypage_view'])
{
     $_SESSION['mypage_view'] = 1;   
} else {
     //check if this is not the first time the page has been viewed
     if(isset($_SESSION['mypage_view'])) {
      //not first time redirect
      header('location: google.com');
      session_write_close();
      exit();
     }
}
查看更多
登录 后发表回答