1

I am a completely clueless about PHP and attempted to add this in regardless.

Visiting /blog-1/index.html directly should redirect me to /blog-2/index.html or atleast that the idea...

<?php
global $url = "/blog-1/index.html";
if ($_SERVER['HTTP_REFERER'] == global $url) {
    header('Location: /blog-2/index.html'); 
    exit();
}
?>

I keep getting -

Parse error: syntax error, unexpected '=', expecting ',' or ';'

Any help is truly appreciated. Thanks!

Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40
Shurikan117
  • 105
  • 9

3 Answers3

1

This should be

<?php
    global $url = "/blog-1/index.html"; //no need of global here 
    if ($_SERVER['HTTP_REFERER'] == $url) 
    {
         header('Location: /blog-2/index.html'); 
         exit();
    }
?>

if ($_SERVER['HTTP_REFERER'] == global $url) { here global $url is the culprit

Praveen Kumar
  • 2,408
  • 1
  • 12
  • 20
1

First error: In this code that you wrote used global $url, why you used. this definition is not need just define variable like this:

$url = "/blog-1/index.html";

Second error: create your if conditions:

if ($_SERVER['HTTP_REFERER'] == $url) {
    header('Location: /blog-2/index.html'); 
    exit();
}

When it is necessary to use global, for example you define a variable in your PHP file and do not want to pass that to your function. in this cases you can use global in PHP.

Majid Abbasi
  • 1,531
  • 3
  • 12
  • 22
0

Try use of below code..........

<?php
global $url = "/blog-1/index.html";
if ($_SERVER['HTTP_REFERER'] ==  $url) {
header('Location: /blog-2/index.html'); 
exit();
}
?>
pedram shabani
  • 1,654
  • 2
  • 20
  • 30