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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

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

Post 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
Last edited by andylyon87 on Fri May 08, 2009 5:33 am, edited 2 times in total.
xplore
Forum Newbie
Posts: 16
Joined: Mon Apr 06, 2009 12:06 pm

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

Post 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.
Last edited by Benjamin on Thu May 07, 2009 9:15 pm, edited 1 time in total.
Reason: Removed quote of entire post.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

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

Post 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.
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

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

Post by andylyon87 »

Hey guys thanks

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

cheers
Post Reply