Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-27-2004, 01:54 AM   #1 (permalink)
pexeter
Registered User
 
Join Date: Jun 2004
Posts: 2
pexeter is on a distinguished road
PHP Newbie

Hi, Im just getting started with php and I ran into some problems with an example from a book. The code Im using is:

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Chapter 1 Example. Figure 1.2</title>
</head>
<body>
<?php
if(!session_is_registered('nCount'))
{
session_register('nCount');
$nCount = 1;
}
else
{
$nCount++;
}
?>

<p>Hello, you have seen this page <?php echo $nCount; ?> times.</p>

<p>To continue, <a href="somepage.php?<?php echo strip_tags(SID)?>">click here (sompage.php?<?php echo strip_tags(SID)?>)</A></p>

</body>
</html>

When I run it I get the following error:

Warning: session_register(): Cannot send session cookie - headers already sent by (output started at C:\apache\public_html\example01_01.php:7) in C:\apache\public_html\example01_01.php on line 10

Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at C:\apache\public_html\example01_01.php:7) in C:\apache\public_html\example01_01.php on line 10

Can anyone please help?
pexeter is offline   Reply With Quote
Old 06-27-2004, 06:23 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
session information is header information. it needs to execute before anything is printed to the browser.

move your script above the html, with NO whitespace above the opening php tag.

also, i think you might need a session_start(); at the very top of the page.
__________________
Mike
sde is offline   Reply With Quote
Old 06-27-2004, 11:36 AM   #3 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Aside from what sde mentioned (and it doesn't appear that you have session_start() at all in your script, else the error message would have mentioned it), both session_register() and session_is_registered() are deprecated and you should instead use the superglobal $_SESSION. I would guess that the book you're using is outdated.

Please read the PHP Manual sections on Session handling functions, specifically the pages for session_register() and session_start().
bdl is offline   Reply With Quote
Old 06-27-2004, 01:23 PM   #4 (permalink)
pexeter
Registered User
 
Join Date: Jun 2004
Posts: 2
pexeter is on a distinguished road
Thanks to both of you for your help. I finaly got it to work. I just find it weird that code taken from the cd that accompanied the book would be wrong. Thanks again.
pexeter is offline   Reply With Quote
Old 06-27-2004, 05:04 PM   #5 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Quote:
Originally posted by pexeter
Thanks to both of you for your help. I finaly got it to work. I just find it weird that code taken from the cd that accompanied the book would be wrong. Thanks again.
Very good. I wouldn't necessarily say that the book or the code that accompanied the book is 'wrong', it's just a little outdated. I've responded to many questions along these same lines due to two main factors: the usage of global variables and the usage of superglobals, which are related for the most part and which have become a big factor since PHP v4.2. So some changes were made, and instantly every PHP book on the market is outdated. Most books now have been re-released with the new information, however.
bdl is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
new to php jhoop2002 PHP 12 08-06-2003 02:45 PM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
PHP Command-Line Arguments? Antagony PHP 3 05-02-2003 12:26 PM


All times are GMT -8. The time now is 07:35 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting