session_start error

This is a discussion on "session_start error" within the PHP Forum section. This forum, and the thread "session_start error are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 17th, 2007, 07:07
Junior Member
Join Date: Aug 2005
Location: New Zealand
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
session_start error

when I test this script I get the following error -

"Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /hsphere/local/home/icmwebs/inkukustop.co.za/form.php:3) in /hsphere/local/home/icmwebs/inkukustop.co.za/form.php on line 3"

I have checked for extra spaces and made sure the php is before the html tag.

Here is the script:

<body bgcolor="yellow">
<div align="center">
<?php session_start();
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>
<form action="form.php" method="post">
<label for="name">Name: </label><input type="text" name="name" id="name"><br>
<label for="email">Email: </label><input type="text" name="email" id="email"><br>
<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br>
<img src="CaptchaSecurityImages.php?width=100&height=40 &characters=5"><br>
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text"><br>
<input type="submit" name="submit" value="Submit">
</form><?php
}
?></div>
</body>

any ideas please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 17th, 2007, 07:14
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: session_start error

have a look here: http://forum.mamboserver.com/archive...p/t-42814.html
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 17th, 2007, 10:07
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: session_start error

The session start must be the very first thing on the page because it is part of the header. When you output something onto the page the headers will have been sent and a session cannot be started.

So you should do this to make it work:

PHP: Select all

<?php session_start(); ?>
 
<body bgcolor="yellow">
<div align="center">
<?php
if( isset($_POST['submit'])) {
.....
...
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 17th, 2007, 21:12
Junior Member
Join Date: Aug 2005
Location: New Zealand
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: session_start error

Thanks guys!

Webforumz rocks. No be-littling attitude to newbies like me and fast, accurate solutions.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 17th, 2007, 21:15
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: session_start error

No problem.

We aim to please
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Sep 17th, 2007, 21:16
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: session_start error

Quote:
Originally Posted by gribble View Post
Webforumz rocks.
That alone should be the new testimonal on the front page
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Sep 17th, 2007, 22:28
Junior Member
Join Date: Aug 2005
Location: New Zealand
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: session_start error

Oooh! a testimonial on the front page...my 15 seconds of fame...

Your solutions worked a treat but I am having trouble getting the message field to appear in the email reply. I just get the email address and the name.

here is the amended code:

<?php session_start();
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
mail( "emotion@inspire.net.nz", "Website Feedback", $name, $email, $message );
echo 'Thank you for your enquiry. Will contact you shortly';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>
<form action="form.php" method="post">
<label for="name">Name: </label><input type="text" name="name" id="name"><br>
<label for="email">Email: </label><input type="text" name="email" id="email"><br>
<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br>
<img src="CaptchaSecurityImages.php?width=100&height=40 &characters=5"><br>
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
?>

Additionally, is it possible to add a background color and css styling to the echo messages?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Sep 18th, 2007, 07:55
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: session_start error

I don't know where the $name, $email, and $message variables get set, but like this is should work:
PHP: Select all

<?php session_start();
if( isset(
$_POST['submit'])) {
    if( 
$_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
        
mail"emotion@inspire.net.nz""Website Feedback"$_POST['name'], $_POST['email'], $_POST['message'] );
        echo 
'Thank you for your enquiry. Will contact you shortly';
        unset(
$_SESSION['security_code']);
    } else {
        
// Insert your code for showing an error message here
        
echo 'Sorry, you have provided an invalid security code';
    }
} else {
?>
<form action="form.php" method="post">
<label for="name">Name: </label><input type="text" name="name" id="name"><br>
<label for="email">Email: </label><input type="text" name="email" id="email"><br>
<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br>
<img src="CaptchaSecurityImages.php?width=100&height=40 &characters=5"><br>
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Getting the &quot;Microsoft JET Database Engine error '80040e14'&quot; error. VegaLA Classic ASP 3 Jan 26th, 2008 00:12
Keep getting error message Microsoft VBScript runtime error '800a01a8' cpando1974 Classic ASP 2 Aug 7th, 2007 12:00
session_start(); AHHH! Bradster PHP Forum 3 Jun 2nd, 2007 11:31
Error 500 - Internal server error JasonStanley PHP Forum 3 Apr 23rd, 2007 17:56


All times are GMT. The time now is 16:24.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42