【发布时间】:2015-04-18 07:54:06
【问题描述】:
我是 PHP 新手,所以请耐心回答这个初级问题。
我想创建一个脚本,根据 GET 变量将用户重定向到各种地址。例如,redirection.php?id=youtube 应该将他们重定向到 www.youtube.com,redirection.php?id=twitter 应该将他们重定向到 www.twitter.com , 等等。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Please Wait...</title>
</head>
<body>
<?php
// directs the user to various locations on the internet
print_r($_GET);
if($_GET['id'] === 'youtube') {
header('Location: http://www.youtube.com/') ;
die()
}
if($_GET['id'] === 'twitter') {
header('Location: http://www.twitter.com/') ;
die()
}
if($_GET['id'] === 'reddit') {
header('Location: http://www.reddit.com/') ;
die()
}
?>
</body>
</html>
到目前为止,PHP 文件根本没有响应,我应该更改什么来解决这个问题?
再次,对于初级级别的问题,我很抱歉,但这实际上是我的第一个 PHP 脚本,我对一些术语不是很熟悉,这使得 Google 难以搜索正确的代码。
【问题讨论】:
-
死();你忘记了 die() 中的分号
-
成功解决了,谢谢!
-
@Richie 接受 saty 的回答,如果这对你有用。
标签: php variables redirect get