-1

I'm building a blog . I want to redirect users who tried to access a post page , without get parameter to thr previous page (if possible without $_SERVER['HTTP_REFERER'])

Exemple : www.myblog.com/post.php

And allow access to this page only via this url

www.myblog.com/post.php?id=number
Trippy
  • 81
  • 6

2 Answers2

2

You can use this PHP Codes if id is not set or empty, just choose here I would Recommend to use empty() function:

if(!isset($_GET['id'])) {
header("location: url");
}

or

if($_GET['id'] == NULL) {
header("location: url");
}

or

if(empty($_GET['id'])) {
header("location: url");
}
1

You can use a session variable.

First, in the script that accesses to post.php you need start the session and you need know the id, for example:

session_start();
$_SESSION['post_id'] = $id; //$id is the post id

Next, in post.php start the session and you can use the id to redirect, do a sql query.......

Miguel Jiménez
  • 484
  • 2
  • 12