Jump to content

problem with session_start() function


doforumda

Recommended Posts

hello there,

 

i am experiencing a problem in my php script. The problem is with session_start() function. when i write this function in my script and run the script in my browser the following error displays

 

"Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at f:\wamp\www\examples\show_session_var.php:9) in f:\wamp\www\examples\show_session_var.php on line 10"

 

"Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at f:\wamp\www\examples\show_session_var.php:9) in f:\wamp\www\examples\show_session_var.php on line 10"

 

above both errors are the same but my browser display it two times. Do anyone know whats the problem pleasee help if anybody knows.

 

thanks.

Link to comment
Share on other sites

Can you post what you currently have for this file

 

show_session_var.php

 

yes sure

 

this is the first page "sessions.php"

 

<?php

session_start();

$color = "blue";

session_register("color");

echo "<a href = 'show_session_var.php'>Click Here</a>";

?>

 

this is the second "show_session_var.php"

 

<?php

session_start();

echo "My favourite color is .....".$color;

?>

Link to comment
Share on other sites

The error message mentions line 9 of show_session_var.php, yet you showed us only 2 lines, where are the rest?

 

Those scripts are written with the assumption that register_globals is enabled. This hasn't been the case in many years. Also, session_register() is depreciated and shouldn't be used.

 

Try this:

sessions.php

<?php
session_start();
$_SESSION['color'] = "blue";
echo "<a href = 'show_session_var.php'>Click Here</a>";
?>

 

show_session_var.php

<?php
   session_start();
   echo "My favourite color is .....".$_SESSION['color'];
?>

 

 

Link to comment
Share on other sites

The error is occurring in show_session_var.php on line 9.  You only showed 2 lines in that file.

 

yes its actually like this

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

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

<title>Untitled Document</title>

</head>

 

<body>

<?php

session_start();

echo "My favourite color is .....".$color;

?>

</body>

</html>

 

i just didnt mention the html code

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.