Page 1 of 1

HELP!!! - problem with starting sessions!! [SOLVED]

Posted: Thu May 07, 2009 5:20 pm
by andylyon87
Hi guys am in need of some help

I have been working on a website that works perfectly on my server, but now doesnt work on my clients server!!!

Code: Select all

 
 
<?
  session_start();
  
  if(!$_SESSION['select']){
    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
    // Check for a trailing slash.
    if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
          $url = substr ($url, 0, -1); // Chop off the slash.
    }
    // Add the page.
    $url .= '/splash.php';
    
    header("Location: $url");
  
   exit(); //quit script
  }  
    
    if($_SESSION['select']== 'trade'){
    $set_p= "t";
  }
  
  if($_SESSION['select']== 'retail'){
    $set_p= "r";
  } 
?>
 
This should just start the session and then check if the variable exists and then should redirect the user if it doesnt exist.

It is throwing up the error:

Code: Select all

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/joan3252/public_html/splash.php:8) in /home/joan3252/public_html/splash.php on line 14
 
Warning: Cannot modify header information - headers already sent by (output started at /home/joan3252/public_html/splash.php:8) in /home/joan3252/public_html/splash.php on line 27
 
I dont understand why it works on one server and not the other :s

Any help would be great thanks

Re: HELP!!! - problem with starting sessions!!

Posted: Thu May 07, 2009 5:42 pm
by xplore
You need to clear up that white space in the top of the document.

TOP OF DOC
----
<?php
<code>
?>

headers are already sent before it reaches your code because the white space is the first thing read in and interpreted by the server.

Re: HELP!!! - problem with starting sessions!!

Posted: Thu May 07, 2009 6:48 pm
by ldougherty
As xplore stated the PHP Error: Cannot modify header information is a common PHP error which is usually caused by white spaces before or after the PHP start "<?php" or end "?>" tags;

If tha does not resolve the issue check carefully the code before and at the line of the header() statement.

Re: HELP!!! - problem with starting sessions!!

Posted: Fri May 08, 2009 5:33 am
by andylyon87
Hey guys thanks

In the past I must have had no white space before the session start! All fixed

cheers