簡體   English   中英

重定向到電子郵件用戶站點

[英]Redirecting to email user site

我嘗試執行此代碼,但我做錯了,因為它總是將我重定向到 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");
}
?>

這是我的 html 表單

<form action="snd.php">
email: <input type="text" id="email" name="email"><br>
<input type="submit" value="Submit">
</form> 

您在$email上調用了explode()函數。 這意味着$after_email現在是一個數組。 你的錯誤是你訪問了錯誤的數組變量。

改變這一行:

$part = $part[1];

到:

$part = $after_email[1];

編輯

在您的表單中也更改此行:

<form action="snd.php">

到:

<form action="snd.php" method="post">

您也沒有指定表單方法。 默認情況下,這設置為$_GET 但是在您的 php 腳本中,您正在調用$_POST超全局變量。 將方法更改為post ,您就可以開始了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM