Login problem

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

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

Login problem

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:
In the first time that the user log, the alvo.php show the error page, because it don't read the session variable, but in the second try its ok, work well....
WHY DAMMET :twisted: :twisted:

THE CODE:

Check.php:
PHP:

Code: Select all

<?php 
$login = 'marcelo'; 
$senha = 'olandim'; 
if ($_POST&#1111;'name']==$login & $_POST&#1111;'password']==$senha)&#123; 

session_start(); 
$_SESSION&#1111;'validate'] = 1; 
header("location: http://tange.com.br/alvo.php"); 
&#125; 
else &#123; 
header("location: http://tange.com.br/denovo.html"); 
exit 
&#125; 
?>




THE alvo.php
PHP:

Code: Select all

<?php 
session_start();
if(!isset($_SESSION&#1111;'validate']) && $_SESSION&#1111;'validate']!=1)&#123; 
header("Location: http://www.niagara.com.br/"); 
&#125; 
?> 
<!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
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if(!isset($_SESSION['validate']) && $_SESSION['validate']!=1){
header("Location: http://www.niagara.com.br/");
}
you redirect if the session element is not set AND set to something != 1 ?
Certainly you want

Code: Select all

if(!isset($_SESSION['validate']) || $_SESSION['validate']!=1){
    header("Location: http://www.niagara.com.br/");
    die();
}
Post Reply