Private Label and Cobranded VoIP Solutions
BrainCast internet & phone based message/memo recording & reminder organization system
Internet Phone Service and Broadband Phone Service by ViaTalk

Go Back   VoIP Forums, Internet Phone Service Forums, & Web Hosting Forums > CoderForums - Programming Discussion > General Programming Issues > Programming Languages & Technologies > PHP

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-01-2002, 05:23 PM
waynew waynew is offline
Registered User
 
Join Date: Mar 2002
Posts: 2
PHP Session Variables

Unable to use session variables. Any help? I tried (below)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Test of PHP</title></head><body>
<?php
$count=3;
if (!session_is_registered('count')) {
session_register("count");
$count = 0;
}
else { $count++; }
echo "count $count";
?>
<h1>123</h1>
</body>
</html>


Warning: Cannot send session cookie - headers already sent by (output started at /home/xxxx/public_html/test3.php: in /home/xxxx/public_html/test3.php on line 12

Warning: Cannot send session cache limiter - headers already sent (output started at /home/xxxx/public_html/test3.php: in /home/xxxx/public_html/test3.php on line 12
count 0
123

-------- and ------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Test of PHP</title></head><body>
<?php
$count=4;
if (isset($HTTP_SESSION_VARS['count'])) {
$HTTP_SESSION_VARS['count']++;
}
else { $HTTP_SESSION_VARS['count'] = 0;
}
echo "count $count";
?>
<h1>124</h1>
</body>
</html>

count 4
124
--Wayne
Reply With Quote
  #2  
Old 03-01-2002, 05:43 PM
JoeF JoeF is offline
QL User
 
Join Date: Jan 2002
Posts: 71
You need to run session_start and session_register before you have any output from php
ie. you need to put it before the <html> etc..
__________________
--
Joe F
Reply With Quote
  #3  
Old 03-01-2002, 06:04 PM
waynew waynew is offline
Registered User
 
Join Date: Mar 2002
Posts: 2
Appears to have worked but still get warning error ??

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
session_start();
session_register("HiThere");
$HiThere="Hello world!";
if (session_is_registered('HiThere'))
{
echo "The content of HiThere is $HiThere<br>";
}else{ echo "Not registered"; }
?>
<html>
<head><title>Test of PHP</title></head>
<body>
test 5
</body></html>

Warning: Cannot send session cookie - headers already sent by (output started at /home/consult/public_html/test5.php:2) in /home/consult/public_html/test5.php on line 3

Warning: Cannot send session cache limiter - headers already sent (output started at /home/consult/public_html/test5.php:2) in /home/consult/public_html/test5.php on line 3
The content of HiThere is Hello world!
test 5
Reply With Quote
  #4  
Old 03-04-2002, 04:02 PM
alan92rttt alan92rttt is offline
Registered User
 
Join Date: Jan 2002
Posts: 12
Send a message via AIM to alan92rttt
You session start must be the first command.

Try changing the code from :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
session_start();
session_register("HiThere");
$HiThere="Hello world!";

to:

<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
session_register("HiThere");
$HiThere="Hello world!";
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump