2017-11-11 194 views
1

我对PHP完全无能为力,无论如何都试图添加它。解析错误:语法错误,意外的'=',期待','或';'

参观/blog-1/index.html直接应我重定向到/blog-2/index.html或至少这个主意......

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

我不断收到 -

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

任何帮助是真正的赞赏。谢谢!

回答

1

这应该是

<?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) {这里global $url是罪魁祸首

+0

@Akintunde完成我编辑我的答案,当你写这个... –

+0

感谢作品像一个魅力。 – Shurikan117

0

尝试使用下面的代码..........

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

谢谢你的回答。 – Shurikan117

+0

不客气 –

1

第一个错误:在你写的这段代码使用了全球$ url,为什么你用过。这个定义并不只需要像这样定义变量:

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

二错误:创建您若条件:

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

当需要用全局的,比如你在你的PHP定义一个变量文件,并不想将它传递给你的函数。在这种情况下,您可以在PHP中使用全局。

+0

感谢您的回答。 – Shurikan117

+0

不客气 –

相关问题