Session start.
Posted by: Nevon (---.01-77-73766c10.cust.bredbandsbolaget.se)
Date: February 25, 2007 05:27PM

I just installed wamp and used it to host an existing site, that had worked perfectly before. Now I get this error message at the top of each page: "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Webbdesign\common.php:1) in D:\Webbdesign\common.php on line 3"
So I'm guessing that means wamp doesn't support the code I have on line 1-4 on each page, which is: "<?php
require_once('../common.php');
checkUser();
?>"

So, how do I solve this? Right now it looks like bullfuck with this naked PHP on the top of each page.

EDIT: Maybe I should add that this is a HTTP user authentication script.



Post Edited (02-25-07 19:09)

Options: ReplyQuote
Re: Session start.
Posted by: yfastud (---.cable.mindspring.com)
Date: February 25, 2007 07:39PM

Firstly, not sure how you setup, but it seems your sites are outside wamp/www folder, in which php will detect and parse the codes. If they are in wamp/www/your_folder, access like this [localhost]. Second, if using short_open_tag, make sure to enable it in php.ini.

Check my old post here for the idea

[forum.wampserver.com]

Have fun

[www.jlbn.com] (testing web server)
[test.jlbn.com] (testing codes)
[forum.jlbn.com] (testing phpBB2)
[forums.jlbn.com] (testing phpBB3)
[mail.jlbn.com] (testing mailserver)
[ftp.jlbn.com] (testing ftp server)
[www.jlbn.com] (testing flashes)
[www.jlbn.com] (testing images)
[joomla.jlbn.com] (testing Joomla 1.0.10)
[fusion.jlbn.com] (testing phpFusion 6.01.6)
[nuke.jlbn.com] (testing phpNuke 7.9)
[nukep.jlbn.com] (testing phpNuke Platinum 7.6.b.4v2)
[pnuke.jlbn.com] (testing PostNuke 0.800-MS2)
[nukevo.jlbn.com] (testing phpNuke Evolution 2.0.1)
[wp.jlbn.com] (testing WordPress 2.1)
[ws.jlbn.com] (testing WebSpell 4.01.02)

Options: ReplyQuote
Re: Session start.
Posted by: Nevon (---.01-77-73766c10.cust.bredbandsbolaget.se)
Date: February 25, 2007 08:16PM

Yes, my files are outside of wamp/www folder. However, it's not accessing the files that is the problem. Nor is it because of short_open_tags.

This is what appears on the top of my sites:
"Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Webbdesign\common.php:1) in D:\Webbdesign\common.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Webbdesign\common.php:1) in D:\Webbdesign\common.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at D:\Webbdesign\common.php:1) in D:\Webbdesign\common.php on line 80"

This is the top of each site in PHP:
"<?php
require_once('../common.php');
checkUser();
?>"

And this is the content of the file called common.php:
"<?php

session_start();

function registerUser($user,$pass1,$pass2){
$errorText = '';

// Check passwords
if ($pass1 != $pass2)
$errorText = "Passwords are not identical!";
elseif (strlen($pass1) < 6)
$errorText = "Password is to short!";

// Check user existance
$pfile = fopen("userpwd.txt","a+"winking smiley;
rewind($pfile);

while (!feof($pfile)) {
$line = fgets($pfile);
$tmp = explode(':', $line);
if ($tmp[0] == $user) {
$errorText = "The selected user name is taken!";
break;
}
}

// If everything is OK -> store user data
if ($errorText == ''){
// Secure password string
$userpass = md5($pass1);

fwrite($pfile, "rn$user:$userpass"winking smiley;
}

fclose($pfile);


return $errorText;
}

function loginUser($user,$pass){
$errorText = '';
$validUser = false;

// Check user existance
$pfile = fopen("userpwd.txt","r"winking smiley;
rewind($pfile);

while (!feof($pfile)) {
$line = fgets($pfile);
$tmp = explode(':', $line);
if ($tmp[0] == $user) {
// User exists, check password
if (trim($tmp[1]) == trim(md5($pass))){
$validUser= true;
$_SESSION['userName'] = $user;
}
break;
}
}
fclose($pfile);

if ($validUser != true)
$errorText = "Invalid username or password!";

if ($validUser == true) $_SESSION['validUser'] = true;
else $_SESSION['validUser'] = false;

return $errorText;
}

function logoutUser(){
unset($_SESSION['validUser']);
unset($_SESSION['userName']);
}

function checkUser(){
if ((!isset($_SESSION['validUser']))
|| ($_SESSION['validUser'] != true)){
header('Location: ../index.php');
}
}

?>"


I hope this helps in clearing things up, because right now I am considering ditching Wamp and manually installing apache and PHP. Wamp works great otherwise, but this problem is really getting annoying.

Options: ReplyQuote
Re: Session start.
Posted by: GaryD (---.bb.sky.com)
Date: February 28, 2007 11:36AM

ive not been using PHP for to long but correct me if im wrong.

1.) If the errors are appearing then php is running the scripts else the errors wouldnt generate.??

2) I think you need to add a Session_start() before you run your check user function in your main pages. i would do...

This is the top of each page in PHP:

"<?php
require_once('../common.php');
session_start();
checkUser();
?>"

if anyone could back be up or correct me? ive only been doing php 4/5 weeks myself

Options: ReplyQuote
Re: Session start.
Posted by: CyberSpatium (71.237.217.---)
Date: March 03, 2007 02:49PM

you can not use any php code that outputs any text to the browser before you use start_session(). some code in your common.php file is outputting something to the browser. so, the easiest fix for you would change the location of the start_session in your php code, versus searching through common.php to find the problem.


<?php
session_start();
require_once('../common.php');
checkUser();
?>




CyberSpatium
----------------------------
Wamp English Forum Admin

Options: ReplyQuote


Sorry, only registered users may post in this forum.