Php prevents user from viewing expired page

Consider the following URL based on future sporting events:
http://www.example.com/file.php?1615=Submit

1615 in url eventid. Now, after the event ends, the page should no longer be displayed.

So my question is, how can I prevent the user from viewing the page if the event expired? It would be something like this the most efficient option using the following logic:

  • Get event id from url assigned to var $ check variable
  • Select event_date from events where event_id = $ check
  • If (date ('Ymd')> event_date) then redirect user

Is there a better way to solve this problem?

+3


source to share


2 answers


Here is the version below I think 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
}

      

+3


source


What you suggest should be a good way to do it like anyone else you can do is redirect them to a 404 page if you really want to give the impression that this event no longer exists. or redirect to an event page, but with a big warning that the event has already expired.



+1


source







All Articles