You are here: Re: [PHP] PHP Sessions? « PHP « IT news, forums, messages
Re: [PHP] PHP Sessions?

Posted by Jochem Maas on 03/02/05 23:39

rory walsh wrote:
> The problem there is that I have to test if the user has logged on so I
> need to include the if statement?

there are 2 tests to do:

1. check to see whether the user is logged on already
2. check to see whether the user is trying to log on

> Can the session_start not be called
> from within an if statement?

not really, well you can but I can't think
of any reason that you would want to conditionally start the
session.

> Does it really have to be the very first
> thing in the script,

you have to call it before you use the session
(i.e. data stored in it).

> if so I imagine that this means a single script
> cannot be used to manage a complete website?

it can. maybe if I rewrite you code a little
it will help you understand:


<?php

session_start(); // always start the session.

// you want something more secure as a login procedure!
if($_POST["username"]=="rory") {
// if user logs in as rory
// then mark the user as logged in
// in the session
$_SESSION['loggedin'] = "yes";
}

if ($_SESSION['loggedin'] == "yes") {
header("Cache-control: private");
}
>
> Chris W. Parker wrote:
>
>> rory walsh <mailto:rorywalsh@ear.ie>
>> on Wednesday, March 02, 2005 11:19 AM said:
>>
>>
>>> <?php
>>> if($_POST["username"]=="rory"){//if user logs in as rory start session
>>> session_start();
>>> header("Cache-control: private");
>>> $_SESSION['loggedin'] = "yes";
>>> }
>>
>>
>>
>> Put session_start(); at the *very* beginning of your script. See if that
>> helps.
>>
>>
>>
>> Chris.
>
>

 

Navigation:

[Reply to this 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

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