0

I want to redirect a php page using php if statement. I did the redirect code with javascript but its not working.

Can someone please help me modify my code if i missed something out or help me out with a better solution.

Below is the code;

$vbi = $row_rsRek['duck'];
if ($vbi == "blocked"){'<script>window.location.href = "http://www.url.com/login.php";
</script>
';}
else {echo "NOT WORKING";}

I tried this too

$vbi = $row_rsRek['duck'];
if ($vbi == "blocked"){header("Location: www.url.com/login.php");}
else {echo "NOT WORKING";}
Chima
  • 172
  • 1
  • 14

2 Answers2

0

PHP has a build in feature for your needs

header("Location: path/to/file");

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

http://php.net/manual/en/function.header.php

Konstantinos
  • 943
  • 1
  • 9
  • 20
0

You can use header function :

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

<?php
    $vbi = 'blocked';
    if ($vbi == "blocked")
    {
      header("Location: http://www.yourwebsite.com/user.php");
    }
    else
    {
      echo "NOT WORKING";
    }
?>

see this link for more information and discuss :

How to make a redirect in PHP?

Community
  • 1
  • 1
Mr.Sun
  • 129
  • 4