Page 1 of 1

Little problens with session

Posted: Wed Feb 26, 2003 11:55 am
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

Posted: Wed Feb 26, 2003 12:08 pm
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}

Thanks I will try now

Posted: Wed Feb 26, 2003 1:27 pm
by molandim
Very thanks... :) :) :) :) :) :) :) :)