Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session errors 3

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can someone be good enough to point out why I am getting the following error.

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/R2D2/public_html/Digi.php:7) in /home/data8251/public_html/Digi.php on line 7

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/R2D2/public_html/Digi.php:7) in /home/data8251/public_html/Digi.php on line 7

The page code is:

<!DOCTYPE html

PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"

<?php session_start(); // This connects to the existing session
session_register ("DB6"); // Create a session variable called name
$HTTP_SESSION_VARS ["DB6"] = $name; // Set name = form variable $name
?>



<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<html xmlns=" xml:lang="en" lang="en">
<title>Submission Form</title>

</head>


<body>


<table class="Fatscope" width="84%" border="1">


<tr>
<td class="DescriptorCell" width="96%" bgcolor="#E7EFF7" colspan="4"><b>
<font face="Arial" size="5" color="#0000FF">Fuji D321 Digital Betacam</font></b></td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#E7EFF7"><b>
<font face="Arial" size="4">Product</font></b></td>
<td class="DescriptorCell" bgcolor="#E7EFF7" width="25%"><b>
<font face="Arial" size="4">Duration</font></b></td>
<td class="ContentCell" width="5%" bgcolor="#E7EFF7" align="center">
<b><font face="Arial" size="4">Qty</font></b></td>
<td class="ContentCell" width="32%" bgcolor="#E7EFF7">
&nbsp;</td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#FFFFFF" height="26">
<font face="Arial"><b>DBC-6</b></font></td>
<td class="DescriptorCell" bgcolor="#FFFFFF" height="26" width="25%">
<font face="Arial"><b>6mins</b></font></td>
<td class="ContentCell" width="5%" bgcolor="#FFFFFF" height="26">
<p align="center"><font size="3">
<input name="DB6" size="5" tabindex="1" style="background-color: #FFFF00"></font>

<td class="ContentCell" width="32%" bgcolor="#FFFFFF" rowspan="3" align="center">
&nbsp;</td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#FFFFFF">
&nbsp;</td>
<td class="DescriptorCell" bgcolor="#FFFFFF" width="25%">
&nbsp;</td>
<td class="ContentCell" width="5%" bgcolor="#FFFFFF">
<p align="center">
&nbsp;</td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#FFFFFF">
&nbsp;</td>
<td class="DescriptorCell" bgcolor="#FFFFFF" width="25%">
&nbsp;</td>
<td class="ContentCell" width="5%" bgcolor="#FFFFFF">
<p align="center">
&nbsp;</td>
</tr>



</table>


</body>
</html>


If I can follow the structure of this then I will use it for all the other pages I am now trying to hold tegether with php. Many thanks
 
1. We established that session information goes before all other output. Yes, even before doctype.
2. Using session_register is not recommended because it relies on register_globals being on. If you use the session (super)global array, you don't even need to do it.
3. In newer versions of php (post 4.1.0) you should use superglobal $_SESSION instead of $HTTP_SESSION_VARS.
4. Where does the $name variable come from? If it is from a form on a previous page, use $_GET['name'] or $_POST['name'], respectively, rather than just the variable name, which assumes register globals on (which is a bad, insecure thing).

Make these changes and you should be set.
 
Hello Vragabond, thanks for comming in again.

The code was based on what I saw in this link :

All I am trying to do is hold a value of DB6 that I can evetually get out later. Does superglobal $_SESSION have a $
before the word superglobal?

I probably have misread the use of the code for how I would use it. :

<?php session_start(); // This connects to the existing session
superglobal $_SESSION ("name"); // Create a session variable called name
superglobal $_SESSION ("DB6"); // Create a session variable called job
superglobal $_SESSION ["DB6"] = $name; // Set name = form variable $name
$HTTP_SESSION_VARS ["DB6"] = $DB6; // Set job = form variable $DB6
?>

Many thanks
 
Ooops, should have read:
<?php session_start(); // This connects to the existing session
superglobal $_SESSION ("name"); // Create a session variable called name
superglobal $_SESSION ["DB6"] = $name; // Set name = form variable $name
$HTTP_SESSION_VARS ["DB6"] = $DB6; // Set job = form variable $DB6
?>
 
superglobal" is not a PHP keyword. It is an English adjective that describes the type of variable $_SESSION is.

A superglobal variable means simply that the variable will be available to all variable scopes throughout a script.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks sleipnir,

I have reduced the code to this, and it still bombs out when it hits the 2nd line.



<?php session_start();
superglobal $_SESSION ("DB6V"); // Create a session variable called DB6V
superglobal $_SESSION ["DB6V"] = $DB6;
?>


Where the control name is called DB6, and I am trying to hold it in variable DB6V. Thanks

 
Thanks, now I am getting a fatal error using the code in my last posting muinus the word superglobal.

Fatal error: Call to undefined function: array() in /home/R2D2/public_html/Digi.php on line 2

Regards
 
replace the () with [] in the line:

$_SESSION ("DB6V")

to

$_SESSION [red][[/red]"DB6V"[red]][/red]

Chacal, Inc.[wavey]
 
Thanks a lot Chacalinc, that solved it. Stars are on me folks!
 
So far, so good. How do I get back the value in a final form.

I used this code

<?php
session_start();
echo "The value stored in your session: " $color; //retriving value from the session
?>

But its a blank page.

Am I carrying out the correct sequence, My opening page is named index.php. The first line of code is:

<?php session_start();
?>

From this form I goto (by button selection) to the nexr form, Digi.php. The first line of code is:

<?php session_start();
$_SESSION ["DB6V"]; // Create a session variable called name
$_SESSION ["DB6V"] = $DB6;
?>

A value in a control named DB6 is entered. I then move from that page either back to the index page or to another page that shows the value of the string DB6V.

Any suggestions where/what I'm doing wrong. Thanks
 
I don't understand.

If one script executes:

Code:
<?php
session_start();
$_SESSION['foo'] = 'bar';
?>

And another script executes:

Code:
<?php
session_start();
print $_SESSION['foo'];
?>

Then the second script will print the value "bar";


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
add the $_SESSION:

echo "The value stored in your session: " [red]$_SESSION["[/red]$color[red]"][/red]; //retriving value from the session

Cheers.

Chacal, Inc.[wavey]
 
oh!! and the dot

echo "The value stored in your session: "[red].[/red] $_SESSION["$color"]; //retriving value from the session

Chacal, Inc.[wavey]
 
Nope, still nothing. Final code update :

Generate Page

<?php session_start();
$_SESSION ['DB6V']; // Create a session variable called name
$_SESSION ['DB6V'] = $DB6;
?>


Retrieve Page
<?php
session_start();
echo "The value stored in your session: ". $_SESSION["$DB6V"]; //retriving value from the session
?>


All I get from the retieve page is:

The value stored in your session:

Maybe it's the server? Driving me mad.
 
No, it's your code.

In the first script, you're storing something in

$_SESSION ['DB6V']

But in the second, you're trying to retrieve something from

$_SESSION["$DB6V"]


In the first reference, the array index is a character string. In the second reference, the array index is an uninitialized variable. It seems to me, as I demonstrated in my working code previously, that you would want to do:

echo "The value stored in your session: ". $_SESSION["DB6V"];

In the second script.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
got shot sleipnir... I didn't realize the "$DB6V" inside the $_SESSION..

Chacal, Inc.[wavey]
 
I cannot urge you strongly enough to start reading the PHP online manual. It is well-organized and contains lots and lots of example code.

In particular right now, you need to understand the differences between constants, single-quoted strings, double quoted strings and variables. I think very strongly that you need to read follow these links to the PHP online manual and read what is presented there:

The part of Chapter 11 that deals with strings
Chapter 12: Variables
Chapter 13: Constants



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
No still nothing comming out. Can someone correct me, I thought the code prior to sleipnir214 saying it was wrong worked in this way - looked logical

<?php session_start();
$_SESSION ['DB6V']; // Create a session variable called name
$_SESSION ['DB6V'] = $DB6;
?>

Above dimensions a variable called DBV6, and fills it with a value from a control DB6. Then to get back whats held in the variable DBV6 I ask:

echo "The value stored in your session: ". $_SESSION["$DB6V"]; //retrieving value from the session

Or am I incorrect in the way I thought it looked logically. There again, what is logical !! Thanks

 
sleipnir stated in a previous post to remove the $ in the var:

echo "The value stored in your session: ". $_SESSION[[red]"$[/red]DB6V[red]"[/red]]; //retrieving value from the session

replace it with:

echo "The value stored in your session: ". $_SESSION[[red]'[/red]DB6V[red]'[/red]]; //retrieving value from the session

Chacal, Inc.[wavey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top