REQUEST_URI if statement thinks /test.php is not test.php

127 views Asked by At

I'm currently doing a check in my PHP script to see if the current URL is not test.php. If it isn't, then redirect. If it is, redirect. However, I ran into an issue. It thinks that test.php is not test.php. I looked on here for something, including other websites, but I couldn't find many questions with the same issue. If there's something I missed, feel free to point me in that direction. Here's my code:

<?php
/*
above code connects to DB, check if user is logged in. if so, then we run a check
with the DB to see if their user account is temporarily prohibited from
accessing the website. if they are, redirect. if not, do nothing. 
*/
if(($_SERVER["REQUEST_URI"]) != "/test.php") {
    echo $_SERVER["REQUEST_URI"]; // debug
    echo '<meta http-equiv="refresh" content="0;URL=/test.php">';
}
?>

Thanks!

1

There are 1 answers

1
Ishmam Haque Bhuiyan On

As far as I understand your question, you redirection is not working. You need to remove '/' from your meta tag. Here is the code:

echo '<meta http-equiv="refresh" content="0;URL=test.php">';