繁体   English   中英

PHP Redierct与if,if else和else

[英]PHP Redierct with if, if else and else

您好我有一个关于php的问题。

我想创建一个特殊的重定向脚本,但是它不起作用。 我想检查“关键字”是否在列表中。 如果在列表中,则使用“标题位置”重定向。如果不使用您从$ _get获得的值重定向到搜索机。

<?php
$q=$_get['q']
if ($q = tw) {
header('Location: http://twitter.com');
exit;
} else if ($q = fb) {
header('Location: http://fb.com');
exit;
} else {
header('Location: https://searchit.com/search?q='$q'+ ');
}
?>

我现在有一个包含10个关键字的列表

tw twitter.com
fb facebook.com
gg google.com

等所有内容都在文本列表中。

你应该写像

$q=$_GET['q'];

而不是$_get而是$_GET['q'] ,也可以使用$_REQUEST['q']

和使用

error_reporting(E_ALL);
ini_set('display_errors', true);

查看您页面上是否有错误。

代码的最后一部分: header('Location: https://searchit.com/search?q='$q'+ '); 似乎是空白的问题,也称为“死亡白页” :)

尝试header('Location: https://searchit.com/search?q=' . $q);


您还忘记了以下分号: $q=$_get['q']


您也可以尝试以下设置:

switch($_GET['q'])
{
  case 'tw':
    header('Location: http://twitter.com');
    exit;
  case 'fb':
    header('Location: http://fb.com');
    exit;
  default:
    header('Location: https://searchit.com/search?q=' . urlencode($_GET['q']));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM