Reply to Re: newbie session question

Your name:

Reply:


Posted by amygdala on 08/20/07 01:16

<Morlaath@gmail.com> schreef in bericht
news:1187570826.109835.85610@w3g2000hsg.googlegroups.com...
> This is the important code from the index page which is causing the
> error:
>
> <?php
> if($_SESSION['logged']) { ?>
> <td class="welcome" ><b>You are logged in as <?php echo
> $_SESSION['username']; ?>.&nbsp;
> <a href="" onclick="//used to have session_destroy() here">Logout</
> a></b></td>
> <?php } else { ?>
> <td class="welcome"><b>You are not logged in. &nbsp;<a
> href="forms/login.php">Login here</a></b></td>
> <?php } ?>
>

Morlaath,

Each page that you want to (re-)use session variables in need to start with:

<?php
session_start();
if($_SESSION['logged']) { ?>

etc...

As a side note, also keep in mind that nothing should be outputted to the
users browser before you call session_start(). Not even whitespace
characters. This is often overlooked by people that have difficulty getting
sessions to work.

The reason is, that sessions (usually) use cookies. Cookies get send to the
browser using HTTP headers. Once PHP has started outputting content, headers
can't be sent anymore.

HTH

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация