Little problens 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

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

Little problens with session

Post by molandim »

Hi everyone...

The ideia:
One html form send two variables that the user have writed. 'name' and 'pass', to a file called check.php.

In this check php, it build another two variables, one called 'name2' and another 'pass2'... after that, the script compare the values of the variables that the user send to the values builded in the check.php.
If they are equals, the script redirect the user to another page called 'teste.php' and build a session with variable 'validate' = 1...

In the teste.php, it first of all, see if the _session['validate'] have the value 1, if not, it direct the user to an error page...

I do that, because if the user try get arrive in the page teste.php with out going to check, he can't see the page.

But this is don't working.. Why...
I will pass the code.

check.php

Code: Select all

<?php

$name2 = 'marcelo'
$pass2 = 'olandim'


if ($_POST['name'] == $name2 & $_POST['pass'] == $pass2){

session_start();

$_SESSION['validate'] = 1;

header ("location: http://tange.com.br/teste.php");
exit
}
else{
header ("location: http://tange.com.br/denovo.html");
exit


?>
teste.php

Code: Select all

<?php
if($_session['validate != 1'){
header("Location: http://www.niagara.com.br/");
}
?>
The problem is that if the user is going to teste.php without going to pass to check, the teste.php don't redirect the user to the page with error
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

1. it needs to be $_SESSION['validate'], not $_session['validate'] (case-sensitive).
2. Check to see if $_SESSION['validate'] exists or not:
if(!isset($_SESSION['validate']) || $_SESSION['validate']!=1){//redirect}
molandim
Forum Newbie
Posts: 19
Joined: Thu Feb 20, 2003 11:33 am
Location: Brazil
Contact:

Thanks I will try now

Post by molandim »

Very thanks... :) :) :) :) :) :) :) :)
Post Reply