2012-08-07 289 views
0

試圖找出乳清我的重定向不起作用在我的標題命令。表單發送信息,但不會重定向到目標頁面。我仍然用php代碼隱藏在耳朵後面,所以請對我的無知進行比較。 HHphp表頭重定向不起作用

<?php 
// Get email address 
require_once 'config.php'; 
// Ensures no one loads page and does simple spam check 
if(isset($_POST['name']) && empty($_POST['spam-check'])) {  
    // Declare our $errors variable we will be using later to store any errors 
    $error = '';  
    // Setup our basic variables 
    $input_name = strip_tags($_POST['name']); 
    $input_email = strip_tags($_POST['email']); 
    $input_subject = strip_tags($_POST['subject']); 
    // We'll check and see if any of the required fields are empty 
    if(strlen($input_name) < 2) $error['name'] = 'Please enter your name.'; 
    // Make sure the email is valid 
    if(!filter_var($input_email, FILTER_VALIDATE_EMAIL)) $error['email'] = 'Please enter a valid email address.'; 
    // Set a subject & check if custom subject exist 
    $subject = "Message from $input_name"; 
    if($input_subject) $subject .= ": $input_subject";  
    $message = "$input_message\n"; 
    $message .= "\n---\nThis email was sent by contact form."; 
    // Now check to see if there are any errors 
    if(!$error) { 
     // No errors, send mail using conditional to ensure it was sent 
     if(mail($your_email_address, $subject, $message, "From: $input_email")) { 
      echo '<p class="success">Your email has been sent!</p>'; 
     } 
     else { 
      echo '<p class="error">There was a problem sending your email!</p>'; 
     }  
    } 
    else {  
     // Errors were found, output all errors to the user 
     $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null; 
     $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null; 
     $response .= (isset($error['message'])) ? $error['message'] . "<br /> \n" : null; 
     echo "<p class='error'>$response</p>";  
    } 
} 
else { 
    die('Direct access to this page is not allowed.'); 
    header("Location: http://jjco.energy526.com/Introduction.aspx"); 
    exit; 

} 
+2

http://de.php.net/die – hakre 2012-08-07 21:55:32

回答

7

您使用的die調用之前頭信息意味着你將永遠不會執行header通話。 ('...');

+0

由於麥克結束時,我實際上刪除了死亡('不允許直接訪問此頁面');但這個垃圾土耳其仍然沒有重定向。任何線索? – 2012-08-07 22:00:55

+2

@HeadHoncho如果設置了適當的POST變量,那麼在腳本部分中將看不到任何重定向。重定向只會發生,如果這些值不張貼,除非我失去了一些東西。 – 2012-08-07 22:39:50

2

die('...');輸出消息並終止當前腳本。

+0

感謝弗拉德,我真的刪除了死亡('不允許直接訪問此頁面'。但這個垃圾土耳其仍然沒有重定向。任何線索? – 2012-08-07 22:02:52

1

你的代碼的執行在模具命令因此以下這沒有線將被執行的論文線是您的標題代碼(重定向)

+0

謝謝ewein,我實際上刪除了死亡('不允許直接訪問此頁面'。但這個垃圾土耳其仍然沒有重定向。任何線索? – 2012-08-07 22:02:10