Home > Software engineering >  i want redirection to be done to account created when signup form is submitted
i want redirection to be done to account created when signup form is submitted

Time:12-13

Well let me illustrate my problem, at first when form of signup is submitted it redirects to account created as instructed by code. But my problem is when you don't create account the page account_created can still be accessed.

Although it is of no use, as anyone can't do anything in that page but still i want the page to be redirected only when signup is done and can't be opened by any user when signup is not done. I tried

if(!isset($_SESSION['username'])) {
        header("Location:signup");
    }

but i could realise later , that immediate after signup session doesn't store value unless signed in. So, what can be done to protect the page from opening if signup is not done.

CodePudding user response:

Prevent Direct Access to PHP file

Add the following lines to the top of your PHP file.

if(!isset($_SERVER['HTTP_REFERER'])){
    // redirect them to your desired location
    header('location: /index.php');
    exit;
}

The above code basically tests if the HTTP_REFERER header of request is set or not. If it is not set, as is the case with plain GET requests sent from browsers, then it will redirect users to home page.

  • Related