简体   繁体   中英

Restrict web page to be viewed once?

I'm trying to set up a webpage (using wordpress) to display a video that can only be viewed once. After some research it seems that my best option would be to restrict page views via cookies?

For example i have found this code which I feel might do the trick:

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

(Source: how do I show a php page just once only per user )

How would this be applied within wordpress? or does anyone have any better solutions to achieve this?

Thanks for your time!

If this is something where people will actively trying to defeat your security, this won't work. But if people want to view this multiple times, they'll find a way to do it regardless of what you do. Grab the IP Address

$_SERVER['REMOTE_ADDR']

Toss it into a file, database, whatever floats your boat

Start the page with

$viewedonce = array(); // populate this however you've stored the data
if (in_array ($_SERVER['REMOTE_ADDR'], $viewedonce)) 
{
header("location: http://redirect.com");
   exit();
}

If you would like to combine cookies and IPs, go to town.

Edit:

If all you are after is "AS SOON AS THIS PICTURE IS VIEWED ONCE, BY ANYONE, NO ONE ELSE CAN VIEW IT"

just serve the file, and then delete it

unlink($theFile);

you can also rename the file and delete it...

rename('theFile.jpg', 'derp/theFile.jpg');

or copy the file and delete it...

copy('theFile.jpg', 'derp/thefile.jpg');

I'm not entirely sure what you're trying to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM