session problem
am 16.08.2007 11:58:18 von Rtenboer
Hello to all again :)
i have a problem with a session
this is my index page what will check if you are logged in or not if
you are logged in it should be displaying the session username
if(!isset($_SESSION["logged"]))
{
echo "
";
echo "je bent niet ingelogd";
echo "
";
}
else
{
echo "";
echo "welkom : ".$_SESSION["username"]."";
echo "
";
}
?>
my login page
session_start();
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$db = mysql_connect('localhost', 'mysqluser', mysqlpassword') or die
(mysql_error());
mysql_select_db("cms", $db);
if(isset($_POST['submit']))
{
$sql = "select * from users where username = '".$user."' and password
= '".$pass."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_fetch_assoc($res) > 1)
{
$username = $_POST['username'];
$password = md5($_POST['password']);
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
$_SESSION["logged"] = 'true';
header('location: index.php');
}
}
?>
well once i try to login it will redirect me to the index.php what is
correct
but now its should tell me on the index page what user is logged but
that isn't happening
anyone know what i did wrong?
greetings
Re: session problem
am 16.08.2007 13:12:57 von luiheidsgoeroe
On Thu, 16 Aug 2007 11:58:18 +0200, Rtenboer@gmail.com
wrote:
> Hello to all again :)
>
> i have a problem with a session
> this is my index page what will check if you are logged in or not if
> you are logged in it should be displaying the session username
>
> if(!isset($_SESSION["logged"]))
> {
> well once i try to login it will redirect me to the index.php what is
> correct
> but now its should tell me on the index page what user is logged but
> that isn't happening
On _every_ request that uses a session you have to call session_start()
before anything else. If you don't, no session is assumed & no $_SESSION
array is filled.
--
Rik Wasmus
Re: session problem
am 16.08.2007 17:18:00 von Rtenboer
On Aug 16, 1:12 pm, Rik wrote:
> On Thu, 16 Aug 2007 11:58:18 +0200, Rtenb...@gmail.com
>
> wrote:
> > Hello to all again :)
>
> > i have a problem with a session
> > this is my index page what will check if you are logged in or not if
> > you are logged in it should be displaying the session username
> >
> > if(!isset($_SESSION["logged"]))
> > {
> > well once i try to login it will redirect me to the index.php what is
> > correct
> > but now its should tell me on the index page what user is logged but
> > that isn't happening
>
> On _every_ request that uses a session you have to call session_start()
> before anything else. If you don't, no session is assumed & no $_SESSION
> array is filled.
>
> --
> Rik Wasmus
thx a lot .. :) problem solved