php - 重定向到电子邮件用户站点
问题描述
我尝试执行此代码,但我做错了,因为它总是将我重定向到谷歌:
<?php
$email = $_POST['email'];
$after_email = explode('@', $email);
$part = $part[1];
if($part == 'aol.com') {
header("Location: http://aol.com");
} else if($part == 'yahoo.com') {
header("Location: http://yahoo.com");
} else {
header("Location: http://google.com");
}
?>
这是我的 html 表单
<form action="snd.php">
email: <input type="text" id="email" name="email"><br>
<input type="submit" value="Submit">
</form>
解决方案
您在 上调用了该explode()
函数$email
。这意味着$after_email
现在是一个数组。您的错误是您访问了错误的数组变量。
更改此行:
$part = $part[1];
至:
$part = $after_email[1];
编辑
也更改表单中的这一行:
<form action="snd.php">
至:
<form action="snd.php" method="post">
您也没有指定表单方法。默认情况下,此设置为$_GET
。但是在您的 php 脚本中,您调用的是$_POST
超全局变量。将方法更改为post
,您就可以开始了。
推荐阅读
- pdf - IONIC:pdf没有在IOS中打开和下载
- javascript - In laravel blade page saying $.ajax is not a function
- dotnetnuke - 在我的本地机器上安装 dnn 时遇到问题
- javascript - Append a dynamic select box to a div after button click
- react-native - 如何使用电视遥控器聚焦元素或 TouchableOpacity?
- angular - How to unit test a function which as viewchild
- c++ - How do I mark one enum value as an inappropriate case in switches
- javascript - How can I reach specific div in JavaScript?
- linux - 如何在非活动天数后排除特定用户不被锁定
- npm - 401 Unauthorized: [Package name] error during npm install from azure DevOps feed