473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I can i fix this session start error

123 New Member
I do not understand these error and also i can i fix it.
This is the error- error:warning: session_start()[function.session-start]:cannot send session cache limiter - header already sent (output started at /home/alinkene/public_html/simpleimage.php:66) in /home/alinkene/public_html/user.php on line 4
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once("connect.php");
  3. include('simpleimage.php')
  4. if (! isset($_SESSION['user'])){
  5. header ('location: home.php');
  6. }
  7.  
  8. //my other code
  9.  
  10. ?>
  11.  
Oct 2 '09 #1
10 4849
Samishii23
246 New Member
To use sessions with PHP scripts, you must put session_start(); into your code.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include('simpleimage.php')
  4. if (! isset($_SESSION['user']))
    header ('location: home.php');
    ?>
If that doesn't work, then you need to check if your website servers PHP config is set to allow sessions.

http://us.php.net/manual/en/function.session-start.php
Oct 3 '09 #2
simon2x1
123 New Member
I included session_start(); in my code in line 4 when got the error i forgot put it when i was posting my question how can i check if my website server php config is set to allow session i need you to show me how and if not set how can i set it.
Oct 3 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
@simon2x1
that means that you send content (an image?) before session_start() is called. which causes the error.
Oct 3 '09 #4
simon2x1
123 New Member
Please explain that better i do not think i have send content(image) let me assume so i can i fix the error, the fun thing is that i did not get these error when i was testing it on wamp server it was when i was now testing it on my web server. i need fix it before i present to my project coordinator
Oct 3 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
@simon2x1
I can only judge from the message and that states, that before session_start() was called either some content (text, image) or a header (via header()) was sent (in file simpleimage.php on line 66).
Oct 3 '09 #6
simon2x1
123 New Member
I have the header( present in both the home page(home.php) and the login page(the page where the error appear) what should i then do should i remove the header() and if i remove it i hope it will not affect the login page and the error will to be fixed.
Oct 3 '09 #7
Atli
5,058 Recognized Expert Expert
Hey.

You can not use the session_start or header functions once you have started to add content to the page.
By that I mean: you must call the function before any part of the page is added. This includes any HTML or text. Even a white-space before the <?php counts.

The best way to fix these sort of errors is to make sure that no content is added before the function is called. If that is not possible, you can have PHP buffer the output and only send it when you allow it, thus allowing you to call the functions at any time.

You can read more about how that works in the manual: PHP: Output Control - Manual
Oct 4 '09 #8
simon2x1
123 New Member
what do you mean by no content must be added before the function is called.is it that i should remove header function which i have done but it still give me the same error.this is my code below i will appreciate it if you will help me edit the error on my code i have two pages home.php and login.php it is the login.php that display the error.

error - Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/alinkene/public_html/SimpleImage.php:66)
in /home/alinkene/public_html/admin_compile.php on line 5

login.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once("connect.php");
  3. include('SimpleImage.php'); ------ this reduce image
  4. session_start();
  5.  
  6. if (!isset($_SESSION['user_id'])){
  7.  header ('location: home.php');
  8. }
  9.  
  10. if (isset($_POST['submit'])) {
  11. if(empty($_POST['companyname']) OR empty($_POST['companyemail'])){
  12.     echo '<font size="2" color="#8B1601">You haven\'t filled in all the fields. Please do it again.</font>';
  13.  }else {
  14. $companyname = ($_POST['companyname']);
  15. $companyemail = ($_POST['companyemail']);
  16. mysql_query("INSERT INTO company
  17. (cname, cemail) VALUES
  18. ('" . $companyname . "', '" . $companyemail . "')") or die(mysql_error());
  19.     }
  20. }
  21. ?>
home.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once("connect.php");
  3. session_start();
  4.  
  5.  
  6. if(isset($_POST['submit'])){
  7. $username = mysql_real_escape_string($_POST['username']);
  8. $password = md5($_POST['password']);
  9.  
  10. $query = mysql_query("SELECT id FROM login WHERE username = '" . $username . "' 
  11.      AND password = '" . $password . "'") or die(mysql_error());
  12.  
  13. list($user_id) = mysql_fetch_row($query);
  14.  
  15.  
  16. if(empty($user_id)) {
  17.  echo 'No combination of username and password found.';
  18. }else{
  19.  
  20. $_SESSION['user_id'] = $user_id;
  21. header('location: login.php');
  22.     }
  23. }
  24.  
  25. <form method="post" action="home.php">
  26.  
  27. Username: <input type="text" name="username"><br>
  28. <br>
  29. Password: <input type="password" name="password"><br>
  30. <br>
  31. <input type="submit" value="Login!">
  32.  
  33. </form>
  34. ?>
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
Oct 5 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
do this
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. require_once("connect.php");
  4. include('SimpleImage.php'); ------ this reduce image
…I wonder why you didn’t try that yet, it was the first thing proposed to solve the issue…
Oct 5 '09 #10
Atli
5,058 Recognized Expert Expert
@simon2x1
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "This will cause an error";
  3. session_start();
  4. ?>
Expand|Select|Wrap|Line Numbers
  1. <p>And so will this</p>
  2. <?php
  3. session_start();
  4. ?>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. echo "This will work.";
  4. ?>
The same goes for the header and setcookie functions.

Just think of it this way.
When your server sends the page to your users, before it can send the actual page it sends a bunch of info about what it is about to send. Those are the headers.
So if you want to send a header, which the session_start, setcookie and header functions do, you must do so before you start sending the actual page.

Once you start sending the page, it is to late to try to send a header.
Oct 5 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7769
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
9
3303
by: Larry Woods | last post by:
I have a site that works fine for days, then suddenly, I start getting ASP 0115 errors with an indication that session variables IN SEPARATE SESSIONS have disappeared! First, for background...
0
1704
by: nbdy9(nospam) | last post by:
I have a ASP.Net website (mobile). From time to time the browser popup the following message. Anyway to catch the error and redirect to my start page? saying, login.aspx? Thanks. ...
3
3452
by: Gary K | last post by:
After a bit a trouble getting VS to create a project on a different web server (I forgot to apply the 'fix'), I get the following error when trying to debug my web application. Error while...
7
2548
by: Spencer H. Prue | last post by:
Hello!, I have a using system.web.sessionstate directive one the top of each of two web pages. On the first page I have the dataadapter, dataconnection, and dataset (also in the component tray)....
2
2080
by: Gavin Lyons via .NET 247 | last post by:
Hello, I'm writing a newsletter application which uses backgroundthreading. I'm using Session variable to report on progresswhile it loops through a dataset. The 'Status.aspx' pagerefreshes every...
2
2021
by: Dave | last post by:
I have an application running on a 3 server webfarm running Windows 2003 with SQLServer Session state. After running for several hours, I started getting the following error. When I access each...
2
23786
by: Anthony Smith | last post by:
I have read the message boards in this group and others. I still have not been able to pull my obect out of a session and use it. Here is how I store it in a session: <? //Include the UserClass...
6
469
by: scout3014 | last post by:
Hi I am currently doing a php logging in function with user level (meaning which user shld go to which page). Currently i am at a loss of creating session parameters. The following code is used...
7
2951
by: David Lozzi | last post by:
Howdy, I'm trying to capture the session end event. I put a spot of code in the Session_End event in the Global.asax.vb file. The function simply writes to a database table logging the event. I...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.