1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Login Problem

Discussion in 'PHP' started by killaklown, Nov 9, 2007.

  1. #1
    Sure enough when i edit the post saying the header includes the database information.. i double check it and its not there :p
     
    killaklown, Nov 9, 2007 IP
  2. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #2
    I guess i have another question... How to i get it to show information about the session (ie username, email, name, etc)?

    My login has
    
    session_register('fullname');
    $_SESSION['fullname'] = $row['fullname'];
    
    PHP:
    for all the things i want, and then i put

    
    <? $_SESSION['fullname']; ?>
    
    PHP:
    where I want it to display but it just comes up blank. (i am starting the session)




    Also, how do i end a session? I try:
    
    <?
    session_start();
    session_destroy();
    ?>
    
    PHP:
    But i am still logged in.
     
    killaklown, Nov 9, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    You forgot the echo.

    And session_register() is deprecated.
     
    nico_swd, Nov 9, 2007 IP
    killaklown likes this.
  4. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #4
    tried with and without echo, still doesnt show anything.

    and what do you mean by "And session_register() is deprecated."?

    Thanks.. +rep




    Just wanted to make it clear
    
    session_register('fullname');
    $_SESSION['fullname'] = $row['fullname'];
    PHP:
    is on the login.php page, do i need to transfer this to all pages that require a session?











    Heres my full login.php:
    
    <? include'inc/header.php'; ?>
    <div id="home">
    <b>Please Login</b>
    <hr noshade>
    <p>
    <center>
    <? if(session_id()!=''){
    echo'Your already logged in.';
    }else{
    ?>
    <?
    if($_GET['i'] == "2") {
    $email = stripslashes($_POST['email']);
    $password = md5(stripslashes($_POST['password']));
    
    $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password'");
    $login_check = mysql_num_rows($sql);
    if($login_check > 0){
        while($row = mysql_fetch_array($sql)){
    
            $_SESSION['fullname'] = $row['fullname'];
            $_SESSION['address1'] = $row['address1'];
            $_SESSION['address2'] = $row['address2'];
            $_SESSION['city'] = $row['city'];
            $_SESSION['state'] = $row['state'];
            $_SESSION['country'] = $row['country'];
            $_SESSION['email'] = $row['email'];
            $_SESSION['paypal'] = $row['paypal'];
            $_SESSION['offers'] = $row['offers'];
            $_SESSION['completedoffers'] = $row['completedoffers'];
            $_SESSION['pendingoffers'] = $row['pendingoffers'];
            $_SESSION['pendingbalance'] = $row['pendingbalance'];	
            $_SESSION['balance'] = $row['balance'];
    		
            mysql_query("UPDATE members SET lastlogin=now() WHERE email='$email'");
    		
    		echo'Login Successful';
    		 }
    }else{
    		echo 'The information you entered is not correct.';
    }
    
    	
    
    }else{
    ?>
    <form action="login.php?i=2" method="POST">
    Email<br /> <input size="20" type="text" name="email" class="signup"> <br />
    Password<br /> <input size="15" type="password" name="password" class="signup"> <br /><br />
    <input type="submit" value="Login">
    </form>
    <?
    }
    }
    ?> 
    </center>
    </p>
    </div>
    <? include'inc/footer.php'; ?>
    
    PHP:
    And heres a page where I want to show data from the session:
    
    <? include'inc/header.php'; ?>
    <div id="home">
    <? if(session_id()!=''){ ?>
    <? include'inc/menu.php'; ?><br />
    <hr noshade>
    <br />
    Full Name: <? $_SESSION['fullname']; ?> <br />
    Address 1: <? $_SESSION['address1']; ?> <br />
    Address 2: <? $_SESSION['address2']; ?><br />
    City: <? $_SESSION['city']; ?><br />
    State: <? $_SESSION['state']; ?><br />
    Country: <? $_SESSION['country']; ?><br />
    Zip Code: <? $_SESSION['zip']; ?><br /> <br />
    <br />
    
    <input type="submit" value="Change">
    <?
    }else{
    echo'Your Not Logged In.';
    }
    ?>
    </div>
    <? include'inc/footer.php'; ?>
    
    PHP:

    The header file contains the session_start(); and db information.
     
    killaklown, Nov 9, 2007 IP
  5. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What's the code that's in your inc/header.php?
     
    armatik, Nov 9, 2007 IP
  6. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #6
    
    <? session_start();
    include'inc/db.php'; ?>
    
    PHP:
    the rest is just html.
     
    killaklown, Nov 9, 2007 IP
  7. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You need to make your header.php code like so:

    <?
    ob_start();
    session_start();
    include'inc/db.php';
    
    --other stuff--
    
    ?>
    PHP:
    Make sure that ob_start(); is at the beginning of the document, no matter what. That should make it work.

    ***By the way, make sure you go into your footer.php and put in ob_end_flush(); at the very bottom, so it shuts that all down.
     
    armatik, Nov 9, 2007 IP
  8. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #8
    i fixed it...


    I added

    $_SESSION['login'] = true;

    to the login page, and i changed

    if(session_id()!='')

    to

    if($_SESSION['login'])


    I just have one question, would doing "$_SESSION['login'] = true;" limit the number of people who can be online at a time?
     
    killaklown, Nov 9, 2007 IP