Session won't work.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thew
    New Member
    • Aug 2010
    • 69

    Session won't work.

    I want to create an admin session to display a div on my website with stats, unviewable for everyone except for me. So i wrote this script:


    AdminSessionLog in.php
    Code:
    <?php
    include 'header.php';
    
    $ip = $_SERVER['REMOTE_ADDR'];
    $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    $pass = $_POST['pass'];
    $adminsetpass = "AdminPass";
    
    if($ip = "My ip"){
    	if($hostname = "My ISP"){
    		echo '<form action="" method="post">
    		      <input type="password" name="pass">
    		      <input type="submit" value="sumbit"><br>
    		     ';
    	}
    	else
    	{
    	echo 'Hostname not right!';
    	}
    }
    else
    {
    echo 'ip Not right!!';
    } 
    
    if($_SERVER['REQUEST_METHOD'] == "POST"){
    	if($pass == $adminsetpass){
    
    		$_SESSION['admin'] = "true";
    		echo 'Done';
    
    	}
    	else
    	{
    		echo 'Pass not right!';
    	}
    }
    include 'footer.php';
    ?>
    Header.php:

    Code:
    <?php
    session_start();
     
    // a lot code
    
    // Now here is the place where the div has to be:
    
    if(isset($_SESSION['admin'])){
    	if($_SESSION['admin'] == "true"){
    	echo '<div style="display:block; bottom:0;   position:fixed; text-align: center; width: 900px; background-color:red; font-size:10px;">
    	      <?php include "online.php"; ?> 
    	      </div>
    	      ';
    	      
    	}
    }
    ?>
    I include header.php and footer.php and on every page, with the content between the includes.

    But now the div won't show up. Can you all help me out?
    Last edited by Thew; Aug 19 '10, 02:26 PM. Reason: Something wrong
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Try to see if loops are entered by echoing variable values to your page. See which values are showing up and which are not. I can't immediately see an error in your code, so try this suggestion first. If you can't find it, let us know...

    Steven

    Comment

    • Thew
      New Member
      • Aug 2010
      • 69

      #3
      Hi

      It worked thanks

      Thew

      Comment

      Working...