Jump to content

My localhost can't accept session and header in php pages


Recommended Posts

Hi,

I newly have installed apache 2.2 / php 5.2 / mysql 5.5 / phpmyadmin 3.4 on XP Home.

 

Problem:

Warning: Cannot modify header information - headers already sent by (

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (

....

 

I tried to unactivate error reports in php.ini but I just get a blank page.

The problem is that it can't accept session and header.

And the problem is NOT free spaces and the like.

The program works just fine on the server, but not on my localhost.

 

I've read and followed many guides about how to configure php.ini and httpd.conf.

 

One time I installed the same and it worked; but I reinstalled OS and these programs again and this time with problem.

 

I appreciate any help

 

Thanks

Nick

 

Link to comment
Share on other sites

this is nothing to do with your localhost not being able to accept sessions. this error :

Warning: Cannot modify header information - headers already sent by .....

means that somewhere in your code you are trying to send a header AFTER something has been sent to the page. There are two basic rules for using headers :

[*]Ensure thats there is no whitespace directly after the opening / closing tags

[*]Ensure that nothing is printed to the page before any kind of header redirect etc.

 

to help you further we need to see some code

Link to comment
Share on other sites

Thanks for your answer.

 

As I said this code already was at the server and works at it does.

1. The first alternativ can not be the case.

 

The code is:

 

<?php

if (!isSet($pwd) || empty($pwd)) {

header ( "Location: /francais/index.php " );

} else {

include "db.php";

$sql = mysql_query("select * FROM user WHERE pwd = '$pwd'", $conn);

while ($rs= mysql_fetch_array($sql)){

$pass = $rs['pwd'];

$userid = $rs['user_id'];

$nom = $rs['nom'];

session_start();

session_register("pass");

session_register("nom");

session_register("userid");

}

if ($pass) {

header ( "Location: /francais/insert_phrase.php" );

} else {

header ( "Location: /francais/index.php" );

}

}

?>

 

 

Hope it's more clear what I mean..

Link to comment
Share on other sites

@belmon, the error message you were getting, but which you did not post entirely, stated where the output was occurring at. Had you posted it or read that part of it, you would have directly known that the output was occurring in your db.php file.

 

Just because you have php code that 'works' on one server, does not mean that it will work on all server configurations. Php has a few got ya's that hide problems in your code, so if you get errors when moving code between servers, you have to consider that the code really does have a problem in it that needs to be fixed. In most of these cases, once you correct the problem that is causing the error message, that portion of the code will work on all server configurations.

Link to comment
Share on other sites

Yes. 

Simple fact. But you should experience it in order to understand it.

With this explanation, PFMaBiSmAd, I realize that I need to review my codes during 11 years. I'm almost sure that I would have difficulty to open at least half of them on this local server! I allways have developed and uploaded directly on the server.

I think that I need to come back soon for further issus.

 

Thanks again PFMaBiSmAd and gristoi.

 

Nick

 

Link to comment
Share on other sites

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.