redirect - PHP: How to check if URL link contains variable to prevent redirecting (rest of code working) -


i new php , hope can me this.

i trying cover following scenarios in header file included on pages:

  1. if session variable "status" not set , page name not "login" or "user" redirect login page.
  2. if session variable "status" not set , page name "user" , variable "resettoken" not set redirect login page.

so far have below works pages when accessing them browser when use link email following still redirected if link contains variable "resettoken":

example link: https://www.myurl.com/user.php?resettoken=abcde

my php (in header include):

$baseurl = "https://www.myurl.com"; $pageurl = basename($_server["request_uri"]); $pagename = pathinfo(parse_url($pageurl, php_url_path), pathinfo_filename);  if( (!isset($_session["status"])) && ($pagename != "login") && ($pagename != "user") ){     header("location: " . $baseurl . "/login.php");     exit; } if( (!isset($_session["status"])) && ($pagename == "user") && (!isset($_get["resettoken"])) ){     header("location: " . $baseurl . "/login.php");     exit; } 

i have 2 questions regarding this:

  1. does $_get not work when accessing page through email link or have change else here ?
  2. is there way combine these checks in 1 if statement instead of having 2 in row ?

many help, mike

  1. $_get work no matter url clicked
  2. combining 2 statements easy, wrap them () , combine them ||

php

if(      (         (!isset($_session["status"])) && ($pagename != "login") &&          ($pagename != "user")     ) || (         (!isset($_session["status"])) && ($pagename == "user") &&          (!isset($_get["resettoken"]))      )    ){     header("location: " . $baseurl . "/login.php");     exit; } 

when redirecting tho have set token should dump variable before. code should not redirect when token set.


Comments