SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Oct 24, 2009, 05:09 #1
session_start() [function.session-start] (What is this error?)
Hey,
I am getting an error on one of my website pages. If you take a look at this link:-
http://www.judgethejob.com/vinny/join-us/
You will i get this error:-
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /domains/judgethejob.com/http/vinny/join-us/index.php:11) in /domains/judgethejob.com/http/vinny/join-us/index.php on line 204
PHP Code:<?php
session_start();
ob_start();
if (isset($_POST['btn-submit']))
{
include("../conn.php");
$emailcheck = $_POST['txt_email'];
$email_check = mysql_query("SELECT email FROM tbl_members WHERE email = '$emailcheck'") or die(mysql_error());
$email_check2 = mysql_num_rows($email_check);
if ($email_check2 != 0) {
echo "<p>Sorry, the email '".$_POST['txt_email']."' is already in use. <a href='javascript:history.go(-1)'> Return</a> to amend.</p>";
}
else
{
$insert = "INSERT INTO tbl_members(username, password, email, gender, postcode, DOB, education, date_added) VALUES
(
// Insert here...
)";
$add_member = mysql_query($insert);
$from = "ibrar@freemanholland.com";
$headers = "From: $from";
$to = $_POST['txt_email'];
$subject = "This is a test";
$body = "Thank you for registering with Judge the Job.
One of our team will contact you within 24 hours about
your registration to confirm your details. If ok we will
make your account active and you will be able to place your
offer immediately.
Meanwhile please keep your login details safe: E-mail: ".$_POST['txt_email']." Password: ".$_POST['txt_password']."";
//$body = "Thank you for registering on our website. Your login details are as follows:- Email Address: ".$_POST['txt_email']." and Username: ".$_POST['txt_username']."";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Many thanks for registering – one of our team will contact you within 24 hours about your registration to confirm your details. If ok we will make your account active and you will be able to place your offer immediately.</p>");
} else {
echo("<p>Message delivery failed... please try again later, or contact the administrator.</p>");
}
}
}
Regards
-
Oct 24, 2009, 06:11 #2
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You need to make sure that NOTHING is sent to the browser before session_start is called. Output buffering to prevent it is usually a hack to overcome dodgy programming, so try and avoid that.
If your code snippet is anything to go by, you have whitespace before the opening PHP tag. That counts as sending something to the browser - therefore you can't start a session.
If you're outputting HTML or whatever before parsing this script, that will also cause this error. A simple solution would be to start the session in the main file, one that's always included - e.g. if you have a header file which outputs HTML before scripts are run, put the session start at the top of that. It may be your database connection file; any file which is included in the majority of pages and is run before anything is output.
Remove that space, see what happens.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 24, 2009, 07:29 #3
Thanks!
That worked i will keep that in mind for the future..
Regards
-
Oct 24, 2009, 16:32 #4
- Join Date
- Oct 2009
- Posts
- 20
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes, nothing can be outputted to the browser before you do a session start or even a header redirect.
-
Oct 27, 2009, 03:11 #5
- Join Date
- Jun 2009
- Posts
- 39
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yeah i had the same problem session ... nothing can be passed not even a single whitespace before start_session()
-
Oct 27, 2009, 03:36 #6
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
In the way of background, what separates headers from content in an HTTP response is a single blank line. Once your script has any output, including whitespace, in order to print that output, PHP must send the blank line ending the headers. At that point, it's too late to start the session, since sessions are maintained through a cookie. Cookies are sent as HTTP headers, and any output after that blank line is interpreted by the browser as content rather than a header, so it can't be output at this point.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
Bookmarks