【问题标题】:Php redirect to variable if existentphp重定向到变量(如果存在)
【发布时间】:2013-01-04 18:41:14
【问题描述】:

下午!我正在尝试检查从 post 变量接收到的 URL 是否存在,以及它是否确实将用户发送到那里。如果不重定向到其他地方......我写了这个但由于某种原因不起作用,

有什么想法吗? 干杯

<?php>
$file = $_POST["code"];
$file_headers =                   
@get_headers('http://example.co.uk/' $file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
/* does not exist
header('Location: http://example.co.uk/?exists=false');
echo $file 'not found';
}
else {
/* exists
header('Location: http://example.co.uk/' $file);
echo $file 'found';
};
?>

【问题讨论】:

标签: php redirect


【解决方案1】:

您使用错误的 cmets。进行单行注释时是//不是 /*

正如您从降价显示中看到的那样,您的代码的整个结尾当前都被注释掉了,并且您的脚本会有错误。

【讨论】:

  • 可能值得一提的是如何正确使用多行/* */
【解决方案2】:

尝试这样做:

$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
    $exists = false;
}
else {
    $exists = true;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 2016-04-04
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    相关资源
    最近更新 更多