Session Stuff

Discussion in 'PHP' started by D-Fraz, Jun 13, 2008.

  1. #1
    Hey. I'm having troubles with this admin session.

    
    <?php if ($_SESSION['admin'] == "$admin" ) {  echo "IP Address"; }else echo "none";   ?>
    PHP:
    But even when I'm logged out it will show "Ip Address" when it should show "none"

    Anyone know the problem?

    Thanks
     
    D-Fraz, Jun 13, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    if ($_SESSION['admin'] == $admin ) {  
       
       echo "IP Address"; 
    
    }else{
    
       echo "none"; 
    
    }
    PHP:
     
    php-lover, Jun 13, 2008 IP
  3. D-Fraz

    D-Fraz Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Still don't work :(
     
    D-Fraz, Jun 13, 2008 IP
  4. Strike X

    Strike X Active Member

    Messages:
    162
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Try this:

    
    <?php
    
    session_start();
    
    
    if ($_SESSION['admin'] == $admin ) { 
       
       echo "IP Address";
    
    } else {
    
       echo "none";
    
    }
    
    ?>
    
    PHP:
     
    Strike X, Jun 13, 2008 IP
  5. D-Fraz

    D-Fraz Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nope don't work :( i don't really know whats the prob.
     
    D-Fraz, Jun 13, 2008 IP
  6. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #6
    
    
    //When you logout you must unset($_SESSION['admin'])
    
    
    if ($_SESSION['admin'] == $admin ){
    
        echo "IP Address";
    
    } else {  
    
      echo "none";
    
    }
    PHP:
     
    php-lover, Jun 13, 2008 IP
  7. D-Fraz

    D-Fraz Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You see, It thinks I'm an admin when I'm logged out so this script is right, But something else is wrong. Anyone know?
     
    D-Fraz, Jun 13, 2008 IP
  8. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Can you post all your code
     
    php-lover, Jun 13, 2008 IP
  9. D-Fraz

    D-Fraz Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    members.php

    <style type="text/css">
    <!--
    .style1 {
    	font-size: 18px;
    	font-weight: bold;
    }
    -->
    </style>
    <div id="container">
    <?php include("config.php"); include("include/menu.php"); ?>
    <div id="content">
    
    </h1>
    <div align="left"><span class="style1">Octi-Might Members
      </h1>
      </span><br />
      <strong>Username / Email / Group / Age / Joined / <?php
       $admin = 'root';
    
    $_SESSION['admin'] = 'root';
    
    if ($_SESSION['admin'] == $admin ){
    
        echo "IP Address";
    
    } else { 
    
      echo "none";
    
    } ?></strong><br><br />
      <?php  $result = mysql_query("SELECT * FROM members");
      while($row = mysql_fetch_array( $result )) {
      echo $row['username']; echo " - "; echo $row['email'];
       echo "<hr>"; } ?>
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
        <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      </div>
    PHP:

    config.php
    <?php session_start();
    mysql_connect("localhost","root") or die(mysql_error());
    mysql_select_db("maindb") or die(mysql_error()); 
    if($_SESSION['username']) $result = mysql_query("UPDATE `online` SET `online`='yes' WHERE $id='$id'");
    
    $result = mysql_query("SELECT groupname FROM members WHERE username='$username'");
    $row = mysql_fetch_assoc($result); // The results are stored in an sql result array -we need to extract them
    $groupname = $row['groupname']; // Since we extracted it into an array, get the correct index of the array
     if ($_SESSION['admin'] == $admin ) { 
    
    }
      if ($groupname == "$guest" ) { } else {
     
     if ($groupname == "$user" ) { 
    
    
    }else { 
    if ($groupname == "$admin" ) { 
    
    
    }else { 
    
    if ($groupname == "$moderator" ) { 
    
    
    }else { 
    }
    }
    }
    }
    
     ?> 
    PHP:
     
    D-Fraz, Jun 13, 2008 IP
  10. D-Fraz

    D-Fraz Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Sorry, here is the part in members.php if ($_SESSION['admin'] == $admin ){

    echo "IP Address";

    } else {

    echo "none";

    }
     
    D-Fraz, Jun 13, 2008 IP
  11. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I think you should initialize the variable $admin=root, in a common file like config.php so that all file can access the variable.

    Thanks
    Samir
     
    samirkumardas, Jun 13, 2008 IP