[英]Redirecting to email user site
I tried execute this code and I have done something wrong because it's always redirecting me to google:我尝试执行此代码,但我做错了,因为它总是将我重定向到 google:
<?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");
}
?>
this is my html form这是我的 html 表单
<form action="snd.php">
email: <input type="text" id="email" name="email"><br>
<input type="submit" value="Submit">
</form>
You called the explode()
function on $email
.您在$email
上调用了explode()
函数。 This implies that $after_email
is now an array.这意味着$after_email
现在是一个数组。 Your mistake was that you were accessing the wrong array variable.你的错误是你访问了错误的数组变量。
Change this line:改变这一行:
$part = $part[1];
to:到:
$part = $after_email[1];
EDIT编辑
Change this line in your form too:在您的表单中也更改此行:
<form action="snd.php">
to:到:
<form action="snd.php" method="post">
You also didn't specify the form method.您也没有指定表单方法。 By default, this is set to $_GET
.默认情况下,这设置为$_GET
。 But in your php script, you were calling the $_POST
superglobal.但是在您的 php 脚本中,您正在调用$_POST
超全局变量。 Change the method to post
and you are good to go.将方法更改为post
,您就可以开始了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.