user4868041
user4868041

Reputation:

Php stop a user from viewing an expired page

Consider the following url based on a sporting event happening in the future:
http://www.example.com/file.php?1615=Submit

The 1615 in the url is the eventid. Now after the event has finishedthe page should not be viewable anymore.

Thus my question is how do I stop user from viewing the page if event has expired? Would something like this be my most efficient option using the following logic:

  1. Get event id from url assign to var $check
  2. Select event_date from events where event_id = $check
  3. If(date('Ymd') > event_date) then redirect user

Is there a more efficient way I can tackle this problem?

Upvotes: 3

Views: 68

Answers (2)

Marilee
Marilee

Reputation: 1598

Here is a water down version of what I believe you would like to do, change as needed

 $id =  $_SERVER["REQUEST_URI"]; 
    $id = substr($id,0,4); //here is your event_id
    //query your database
$data = $conn->query('SELECT event_date from events WHERE event_id ="$id"')
    //get date
     foreach($data as $row) {
        $event_date =($row);
        }
$cur_date = date("Ymd");
if($cur_date>$date){
//do what you need to do
}

Upvotes: 3

Gerton
Gerton

Reputation: 686

What you're proposing should just be a good way to do this as any, what you can do is redirect them to a 404 page if you really want to give the impression that this event doesn't exist anymore. or redirect to the event page but with a big warning that the event has already expired.

Upvotes: 1

Related Questions