having a problem here with WordPress. I want to redirect the page to a specific .php file inside a folder (php/adminpage.php) whenever $_SESSION
variable is equals to 1. Let’s say the session variable is 1:
<?php
if ((isset($_SESSION['login']) && $_SESSION['login'] == '1')) {
header ("Location: php/adminpage.php");
?>
But the browser returns “Not Found”. Any ways to get it to work?
UPDATE [SOLVED]: Using the full path works. Thanks to @andrewsi. Working code:
<?php session_start();
if ((isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: wp-content/themes/euro/php/adminpage.php");
}
?>
You’re using a relative path:
That will look for a folder below where the current file is, and look for
adminpage.php
in there.But WordPress does some funny things with page names and .htaccess, so your current page might not be where you expect it to be; it’s generally always better to use a full path, which is a lot less ambiguous:
header(“Location: /wp-content/themes/euro/php/adminpage.php”);
And don’t forget to
exit
after calling it, too, so code execution stops on the page from which you are redirecting.Is this an actual URL location?
To my eyes it seems like a file system path. Because is your local setup at this URL:
And then this would be the location of that file?
Also, I would clean up your code like so:
By using
array_key_exists
you prevent unset index errors & by usingintval
you are assured there is a numerical value in place.