0

How can i open another webpage if a varaiable is not like expected, and in the same window?

I have tried variants of:

if ($variable <> 2 ) { 'window.location.replace("https://www.somwhere.no/somepage.php","_self")'; }

I usually get just a stop in the current webpage. I am trying to send the command to the user, to load an other page instead.

Bergum
  • 77
  • 9
  • 2
    You are mixing php with javascript. You can't. You actually are just typing a string, without instructions. If you want to do a redirection in php you can use [`header()`](https://www.php.net/manual/en/function.header.php) – Cid Sep 21 '19 at 19:27
  • 1
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Cid Sep 21 '19 at 19:28
  • Maybe https://stackoverflow.com/questions/5061675/emulate-a-403-error-page – user3783243 Sep 21 '19 at 19:34

2 Answers2

1

Regardless of what you want to achieve, the "not equals" comparison is performed using != or !== operators instead of <>. Also, redirection in php is performed differently by using, as someone mentioned, a "Location" header.

if ($variable !=2) {
    header('Location: https://www.somwhere.no/somepage.php');
    exit;
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Srdjan Marjanovic
  • 375
  • 1
  • 3
  • 11
0

The solution is: (or athleast it works for me...)

if ($variable !=2) { echo ' <script> 
{ 
window.open("https://www.somwhere.no/somepage.php", "_self"); 
} 
</script> ';
}
Bergum
  • 77
  • 9