我對PHP相當陌生,我正在搞亂登錄/註冊系統。我安裝我的樣本網站使用PHP-SWITCH腳本,我發現了一段時間後:PHP開關和登錄
<?php
switch($_GET['id']) {
default: include('home.php');
/* LOGIN PAGES */
break; case "register_form":
include ('includes/user_system/register_form.php');
}
?>
在註冊頁面的形式鏈接到我的「register.php」的檢查形式的有效性和檢查任何空白字段等。 「register.php」應該刷新頁面,併爲提交表單時用戶做錯了添加了一個理由。
在我的「register_form.php」頁面上,它包含實際的表單。該字段在用戶犯錯之前一直隱藏。
<?php if (isset($reg_error)) { ?>
<span class="red"><?php echo $reg_error; ?></span>, please try again.
<?php } ?>
我的「register.php」檢查表單中的所有錯誤。這裏有一個代碼,將刷新頁面與錯誤的原因位:
// Check if any of the fields are missing
if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass'])) {
// Reshow the form with an error
$reg_error = 'One or more fields missing';
include 'register_form.php';
現在,經過我提交沒有任何字段的形式填寫了我的錯誤代碼,但它刷新到實際的「register_form中。 PHP的」。這個問題是由於我的PHP-SWITCH腳本(幫助我更容易管理網站),我沒有在該頁面上進行任何格式化。我的「register_form.php」的實際URL是:「index.php?id = register_form」。現在,我已經嘗試了幾種不同的東西,如將其更改爲:
include 'index.php?id=register_form'
而且也將其更改爲:
header(location:index.php?id=register_form')
不幸的是這一切都爲刷新頁面,而不該錯誤的原因。我知道這可以很容易地通過添加一個Javascript驗證器來解決,但我想知道是否有可能使用「include」或「header()」錯誤刷新頁面,同時啓用PHP-SWITCH腳本網站。
你的意思是'break;'not'brake;' – Serge 2010-06-09 05:24:20