Jump to content

Recommended Posts

Before asking, I have read this. http://www.phpfreaks.com/forums/index.php?topic=37442.0  I am just confused why my header still doesn't work. I don't think I'm outputting anything in the else statement where my header(Location: 'registerconf.php') is; Here's the code

 

<?php require('includes/header.php'); ?>
<?php
//VARIABLES
$submit = mysql_real_escape_string($_POST['submit']);
$username = mysql_real_escape_string($_POST['username']);
$user = $_POST['username'];
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$passwordconf = mysql_real_escape_string($_POST['passconf']);
$ageconf = mysql_real_escape_string($_POST['ageconf']);
$tosconf = mysql_real_escape_string($_POST['tosconf']);

$loweruser = strtolower($username);

$checkuser = mysql_query("select * from users where username_lower='{$loweruser}'");
$userexists = mysql_fetch_assoc($checkuser);

$emailexistsquery = mysql_query("select * from users where email='{$email}'");
$emailexists = mysql_fetch_assoc($emailexistsquery);
    
/*CHECKS
* Many checks need to be done, the checks will also be done in order. The order will 
* be listed here
* 
*/

if(isset($_POST['submit'])) {
    if(empty($username)||empty($firstname)||empty($lastname)||empty($email)||empty($password)||empty($passwordconf)){
        echo('Please fill out all fields!<br/>'); 
    }else{
        if($userexists) {
            echo "Username $username already exists";
    }else{
        if(strlen($username)>15||strlen($username)<5) {
            echo "Username must be between 5 and 15 characters";
        }else{
            if (!preg_match('/^[a-zA-Z0-9]+$/', $user)) {
                echo "Username can only contain letters and numbers with no spaces";
            }else{
               if(strlen($firstname)>20) {
                   echo "Your first name cannot be larger than 20 characters";
               }else{
                   if(!preg_match('/^[A-Z]{1}[a-z]+$/', $firstname)) {
                       echo "Your first name can only contain letters and must start with a capital followed by lowercase letters";
                   }else{
                       if(strlen($lastname)>20) {
                           echo "Your last name cannot be larger than 20 characters";
                       }else{
                         if(!preg_match('/^[A-Z]{1}[a-z]+$/', $lastname)) {
                           echo "Your last name can only contain letters and must start with a capital followed by lowercase letters";
                                    }else{
                                        if(strlen($email)>40) {
                                           echo "Email cannot be longer than 40 characters";                                                                               
                                    }else{
                                       if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                                         echo "Invalid Email";
                                     }else{
                                         if($emailexists) {
                                             echo "Email already exists";
                                         }else{
                                            if(strlen($password)<5||strlen($password)>30) {
                                                echo "Password must be between 5 and 30 characters";                                            
                                            }else{
                                                if($password!=$passwordconf) {
                                                echo "Passwords don't match";
                                            }else{
                                                 if($ageconf=='') {
                                                     echo "You must be 16 or older to register";
                                                 }else{
                                                     if($tosconf==''){
                                                         echo "You must agree with the Terms of Service";
                                                     }else{
                                                         //add to database
                                                         $mdpass = md5($password);
                                                         $rand = rand('12345','54321');
                                                         $activekey = time()+$rand;
                                                         
                                                         $query = "insert into users set username='{$username}', username_lower='{$loweruser}', firstname='{$firstname}', lastname='{$lastname}', email='{$email}', activationcode='{$activekey}', password='{$mdpass}'";  
                                                         $query2 = mysql_query("select * from users where username='{$username}'");
                                                         
                                                         mysql_query($query);
                                                         
                                                         $sqluserid = mysql_fetch_assoc($query2);
                                                             
                                                         $userid = $sqluserid['id'];
                                                       
                                                         
                                                         $to = $email;
                                                         $subject = "Activate your account";
                                                         $message = "Welcome to Site! $firstname! </br>
                                                         Thank you for taking your time to register an account for the Site Networks your click the link below to activate your account! </br></br>
                                                         <a href=ns.com/registerconf.php?pid=$userid&activate=$activekey;
                                                         ";
                                                                                                       
                                                        
                                                         header('Location: registerconf.php');                                                         
                                                     }
                                                 }
                                            }     
                                       }
                             }                        
                          }
                          
                       }   
                   }
               }
            }
        }
     }
    }
   }
  }
  echo "";
}

echo "<table>
<form name='login' method ='POST' action='register.php'>
    <tr><h3>Register your account and get access to all of the Networks!<h3></tr>
    <tr><td>Username</td><td><input type='text' name='username' value=".$username."></td></tr>
    <tr><td>First Name</td><td><input type='text' name='firstname' value=".$firstname."></td></tr>
    <tr><td>Last Name</td><td><input type='text' name='lastname' value=".$lastname."></td></tr>
    <tr><td>Email</td><td><input type='text' name='email' value=".$email."></td></tr>
    <tr><td>Password</td><td><input type='password' name='password'></td></tr>
    <tr><td>Confirm Password</td><td><input type='password' name='passconf'></td></tr>
    <tr><td>I am 16 or older</td><td><input type='checkbox' name='ageconf'></td></tr> 
    <tr><td>I agree with the <a href='tos.php'>terms of service</a></td><td><input type='checkbox' name='tosconf'></td></tr> 
    <tr><td><input type='submit' name='submit' value='Register'>
</form>
</table>
";

?>
<?php require('includes/footer.php'); ?>

 

It might be the sql statement but I need that for the user id.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/245646-regisitry-form-with-header-error/
Share on other sites

I added a new line in an attempt to redirect if the user first of all and the error changed to that line, it's obviously still applicable to the other header().

 

if(isset($_SESSION['username'])) {
header('Location: index.php');
}

 

The error I'm getting is

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/ns/ns.com/httpdocs/subdomains/ns/includes/header.php:8) in /var/www/vhosts/ns/ns.com/httpdocs/subdomains/ns/register.php on line 29

 

 

The header looks like this at the top

 

<?php ini_set('session.cookie_domain', '.ns.com'); ?>
<?php session_start(); ?>
<head>
    <link rel="stylesheet" href="includes/css/style.css" type="text/css"/>
    <link rel='stylesheet' href='includes/css/reset.css' type="textcss"/>
    <title>NS</title>
</head>

<?php
require('db.inc.php');
require('cookiecheck.php');

 

Sorry about not posting that. I was hesitating to do so, but I feared it was something in the code.

output started at /var/www/vhosts/ns/ns.com/httpdocs/subdomains/ns/includes/header.php:8 (line 8)

 

Lines 3-8 of header.php are a bunch of characters that are being sent to the browser. Any characters that you send to the browser before a header() statement will prevent the header() from working.

 

I recommend that you re-read the sticky post concerning this, because this subject has been beaten to death.

PHP should be coded:

 

1. Processing

2. Displaying

 

So, keep your processing separate from you display, and you will not run into these problems.  All processing should happen before you include that 'header' file.

 

Anyways, it won't let me do it in the footer. My header contains navigations and such which is obviously html. I want the errors to appear under the header and above the form. I know that guide explained how to do it, but I keep my registry where it runs the else statement.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.