Hi i'm trying to get my registration script up and running on my site. When a user registers it sends them to a page called process.php but when they reach that page it comes up with this error, Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/***/***/***/***/config.php:24) in /home/***/***/***/***/process.php on line 47 Warning: Cannot modify header information - headers already sent by (output started at /home/***/***/***/***/config.php:24) in /home/***/***/***/***/process.php on line 48 Where i've marked *** is where my personal information is that's why i'm not showing it. And here is the code for process.php. <?php include("config.php"); class Process { function Process($connection){ if(isset($_POST['login'])){ $this->login(); } elseif(isset($_POST['register'])){ $this->register(); } else{ header("Location: login.php"); } } //Member Login function login(){ global $config; ob_start(); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; # Allows letters, numbers if(!preg_match('/^[a-zA-Z0-9]+$/i', $myusername)) { session_register(bad_char); $_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>"; header("location:login.php"); } // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypt_password = md5($mypassword); $query = $config->query("SELECT * FROM members WHERE username='".$myusername."' and password='".$encrypt_password."'"); // Mysql_num_row is counting table row $count=mysql_num_rows($query); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); header("location:main.php"); } else { session_register(error); $_SESSION['error'] = "<center><font color='red' size='4'>Wrong Username or Password</font></center>"; header("location:login.php"); } ob_end_flush(); } //Register_Submit function register(){ global $config; //Defines All The Users Inputs $myusername=$_POST['myusername']; $myusername2=$_POST['myusername']; $mypassword=$_POST['mypassword']; $mypassword2=$_POST['mypassword2']; $email=$_POST['email']; $passwordcount=$_POST['mypassword']; # Allows letters, numbers if(!preg_match('/^[a-zA-Z0-9]+$/i', $myusername2)) { session_register(bad_char); $_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>"; header("location:register.php"); } //Stop SQL Injection $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $mypassword2 = stripslashes($mypassword2); $email = stripslashes($email); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $mypassword2 = mysql_real_escape_string($mypassword2); $email = mysql_real_escape_string($email); //encrypt password variable $encrypt_password = md5($mypassword); $query = $config->query("SELECT * FROM members WHERE username='".$myusername."'"); // Mysql_num_row is counting table row $count=mysql_num_rows($query); // If result matches $myusername then username is taken if($count===1){ // Send error back to the register page if count = 1 session_register(username_taken); $_SESSION['username_taken'] = "<center><font color='red' size='1'>The Username You Chose Is Already In Use</font></center>"; header("location:register.php"); } elseif($mypassword != $mypassword2) { session_register(password_same); $_SESSION['password_same'] = "<center><font color='red' size='1'>Passwords Dont Match</font></center>"; header("location:register.php"); } elseif(strlen($mypassword) < "5") { session_register(password_less_then_5); $_SESSION['password_less_then_5'] = "<center><font color='red' size='1'>Password Must be Greater then 4 Charcters</font></center>"; header("location:register.php"); } else { $query = $config->query("INSERT INTO members (id, username, password, email) VALUES (NULL, '$myusername', '$encrypt_password', '$email')"); session_register(welcome_screen); $_SESSION['welcome'] = "Welcome, You are now a member of Corpal Uploads.<br> Reccommend us to your friends.<br> We are a free Upload site and WILL STAY FREE!<br> Thanks,<br> Whitey.<br> <a href='login.php'>Continue</a>"; header("location: register.php"); } } }; $process = new Process($connection); ?> Code (markup): Many thanks to whoever can help with this problem.
i'm too lazy to read your code but here's what your error means your page outputs something before it sends the session variables to the output, and thus the error the session and cookie are the things to be send out firstmost, before anything at all. So, for exaqmple, if your page has an empty line before the <?php - that will lead to an error. furthermore, if in your php code you echo out anything before sending the session - you'll get the error. in other words, simply make sure the visitor's browser does not get anything at all before they get the session variables otherwise you'll get the error the exact same rule applies to cookies good luck
just noticed .. you do an include .. make sure your included config.php does not output anything at all as well