PHP Switch and Login
Posted
by Steve Rivera
on Stack Overflow
See other posts from Stack Overflow
or by Steve Rivera
Published on 2010-06-09T02:51:50Z
Indexed on
2010/06/09
2:52 UTC
Read the original article
Hit count: 331
php
I'm fairly new with PHP and I am messing around with a login/registration system. I setup my sample website using a PHP-SWITCH script I found a while back:
<?php
switch($_GET['id']) { default: include('home.php'); /* LOGIN PAGES */ break; case "register_form": include ('includes/user_system/register_form.php'); } ?> On the registration page the form links to my "register.php" which checks the validity of the form and to check for any blank fields and so on. "register.php" is supposed to refresh the page and add a reason to what the user did wrong when submitting the form.
On my "register_form.php" page, which holds the actual form. This field is hidden until the user makes a mistake.
<?php if (isset($reg_error)) { ?>
, please try again. My "register.php" checks the form for all the errors. Here's the bit of code that will refresh the page with the reason for the error:
// 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'; Now after I submit the form without any fields filled out I get the error code, but it refreshes to the actual "register_form.php". The problem with this is that because of my PHP-SWITCH script (helps me manage the site a lot easier) I don't have any formatting on that page. The actual URL to my "register_form.php" would be: "index.php?id=register_form.php". Now I have tried several different things such as changing it to:
include 'index.php?id=register_form.php'
And also changing it to:
header(location:index.php?id=register_form.php')
Unfortunately all this does is refresh the page without the reason for the error. I know this can be easily solved by just adding a Javascript Validator but I'd like to know if it is possible to refresh the page with the error using either "include" or "header()" while having a PHP-SWITCH script on the website.
© Stack Overflow or respective owner