Problems with session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
molandim
Forum Newbie
Posts: 19
Joined: Thu Feb 20, 2003 11:33 am
Location: Brazil
Contact:

Problems with session

Post by molandim »

THE IDEIA:
Hi everyone... Its is the problem.. I do a check in php, that build a session if the check is ok it build a session that build a variable 'validate' with value 1, and then redirect to another page called alvo.php.. In this php file it check it have this variable in session and if his value is 1.

If ok it , the page load normaly, if not redirect to another page...

THE PROBLEM:

THIS ALVO.PHP is not reading or not finding this variable in the session that i build in CHECK.PHP

THE CODE:

Check.php:

Code: Select all

<?php
$login = 'marcelo';
$senha = 'olandim';
if ($_POST['name']==$login & $_POST['password']==$senha){

session_start();
$_SESSION['validate'] = 1;
header("location: http://tange.com.br/alvo.php");
} 
else {
header("location: http://tange.com.br/denovo.html");
exit
}
?>

THE alvo.php

Code: Select all

<?php
if(!isset($_SESSION['validate']) && $_SESSION['validate']!=1){
header("Location: http://www.niagara.com.br/");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>
<body>

Oi pessoalm tudo bem, se vcs conseguem ver isto é que estão logados


</body>
</html>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You need a call to session_start() at the top of any page that sets or tries to access session variables, basically you need one at the top of alvo.php.

Mac
molandim
Forum Newbie
Posts: 19
Joined: Thu Feb 20, 2003 11:33 am
Location: Brazil
Contact:

I still don't working

Post by molandim »

I allready put the session_start(); in the top of alvo.php...but still don't working

Code: Select all

<?php 
if(!isset($_SESSION&#1111;'validate']) && $_SESSION&#1111;'validate']!=1)&#123; 
header("Location: http://www.niagara.com.br/"); 
&#125; 
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried putting:

Code: Select all

echo '<pre>';
print_r($_SESSION);
echo '</pre>';
after the call to session_start() to see what it says is in the array.

Mac
molandim
Forum Newbie
Posts: 19
Joined: Thu Feb 20, 2003 11:33 am
Location: Brazil
Contact:

Just a little problem

Post by molandim »

Now it is working.. just have a small problem....

In the first time that I send my name and password to the check.php, he process ok, with no problem, and redirect to the alvo.php... But redirect to the error page, but if i came back to the page to send again my name and password, works well.....

Works only in the second send..

WHY ???

(Thanks guys, if you dies you to heavens)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

See this thread to offer help:
viewtopic.php?t=6818

Mac
Locked