...

View Full Version : Why Header does not work?



auriaks
06-26-2010, 01:39 AM
I have a problem, but don't know where...
I start session with[this is just a part of all script - $nick and $password are correct]:


session_start();

$sess_browser=$_SERVER['HTTP_USER_AGENT'];

$_SESSION['id'] = $id;

$hash = md5($nick.$password.$sess_browser);
$_SESSION['hash'] = $hash;
setcookie("hash", "$hash");

Then I brake this session with:


if($_GET['act'] == 'logout') {
session_start();
session_unset($_SESSION['hash']);
session_unset($_COOKIE['hash']);
session_destroy();
}

After that, My auth.php must redirect me to login page, but it doesn't work...


<?php
session_start();

$host = $_SERVER['HTTP_HOST'];
$link = "http://$host/login.php";

if($_COOKIE['hash'] != $_SESSION['hash']){
header("Location: $link");
}

?>

Header is not working... Maybe session is not destroyed or it has both empty values and they are equal... How I can solve this??

Thanks in advance :)

mlseim
06-26-2010, 03:37 AM
How about this thought ...

You have this:
if($_COOKIE['hash'] != $_SESSION['hash']){
header("Location: $link");
}

If you think about it, both the cookie and the session are gone ...
so they DO equal each other?

Perhaps you only need to check for the SESSION to be set ...

if(isset($_SESSION['hash'])){
// user is still logged in ... do nothing
} else {
// user is no longer logged in.
header("Location: $link");
}

pageguy
06-27-2010, 02:36 AM
if(!isset($_COOKIE['hash']) || !isset($_SESSION['hash']) || $_COOKIE['hash'] != $_SESSION['hash']{
header("Location: $link");

And of course, could just be a silly white space or something messing up the header.

alstonwillman
06-30-2010, 12:05 PM
If you are sending it to services like hotmail or yahoo they may filter it for spam if the headers don't meet rfc standards.
To send a from field, either use the email address or the proper format such as
$headers = "From: \"Your Name Here\" <you@yoursite.com>";

To add more than one header make sure to separate each one with \r\n and not just a \n.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum