Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Why Header does not work?

    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]:
    PHP Code:
    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:
    PHP Code:
    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 Code:
    <?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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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");
    }

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    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.

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •