2010-06-09 48 views
0

我对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脚本网站。

回答

0

对不起,我回答的vaugness:

  • 交换机默认的应该是你的switch语句
  • 你不应该使用switch语句作为门的尽头。
  • 您必须在case:之后break;
  • 不要使用eviroment vars'GET'在你包括,因为你的包括arent supposted要求通过服务器。
  • 您的头函数参数在语法上是错误的。
  • 并回答最后一个问题,不,因为您始终将register_form分配到$_GET['id']
+0

你的意思是'break;'not'brake;' – Serge 2010-06-09 05:24:20