PDA

View Full Version : Warning: session_start() [function.session-start]: Cannot send session cache limiter


Adam_C
01-07-2011, 07:50 PM
Hi, I am working on this site: http://daily.adamscarter.co.uk/ and on the home page I get this error:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/adamc93/public_html/daily/index.php:4) in /home/adamc93/public_html/daily/index.php on line 4

The top section of the index.php is as follows:
<!DOCTYPE HTML>
<html>
<head>
<?php session_start();

// Include class & create require_once("twitteroauth/consumer-keys.php");
require_once("twitteroauth/twitteroauth.php");
require_once("twitteroauth/consumer-keys.php");

// Create TwitterOAuth object with our Twitter provided keys
$tOAuth = new TwitterOAuth($consumerKey, $consumerSecret);

// Generate request tokens
$requestToken = $tOAuth->getRequestToken();
$_SESSION["oauth_token"] = $requestToken["oauth_token"];
$_SESSION["oauth_token_secret"] = $requestToken["oauth_token_secret"];

?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Daily</title>

I am making a request to twitter to use their API, but I am, later in the code sending AJAX twice using jQuery. Would this have anything to do with it?

I have tried to find a solution to this and have been googling for the past few days but had not luck!

Thanks in advance :D

davidj
01-09-2011, 02:29 PM
are you outputting anything before the HTML?

Adam_C
01-09-2011, 02:31 PM
are you outputting anything before the HTML?

how do you mean?

davidj
01-09-2011, 02:32 PM
are you outputting using PHP before the <html tags

Adam_C
01-09-2011, 02:48 PM
are you outputting using PHP before the <html tags

This is my code before the 'Head' section...
<!DOCTYPE HTML>
<?php session_start();

//Connect to Twitter
session_start();

// Include class & create require_once("twitteroauth/consumer-keys.php");
require_once("twitteroauth/twitteroauth.php");
require_once("twitteroauth/consumer-keys.php");

// Create TwitterOAuth object with our Twitter provided keys
$tOAuth = new TwitterOAuth($consumerKey, $consumerSecret);

// Generate request tokens
$requestToken = $tOAuth->getRequestToken();
$_SESSION["oauth_token"] = $requestToken["oauth_token"];
$_SESSION["oauth_token_secret"] = $requestToken["oauth_token_secret"];

?>
<html>

That is my code: however for some reason I know get these errors:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/adamc93/public_html/daily/index.php:2) in /home/adamc93/public_html/daily/index.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/adamc93/public_html/daily/index.php:2) in /home/adamc93/public_html/daily/index.php on line 2

Adam_C
01-09-2011, 03:28 PM
are you outputting using PHP before the <html tags

I think I solved it, I move the PHP Code before
<!DOCTYPE HTML>

It seems to have gone now (both errors/warnings)

thanks anyway :D