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.

Member log in

Discussion in 'PHP' started by bmtpep, Apr 9, 2007.

  1. Eran-s

    Eran-s Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #21
    You right, my mistake...
    And I did another mistake that I put the js version. :eek:
    SEMrush
    Last code:
    
    <?php
           if(!isset($_SESSION['first_name']))
                die("<meta http-equiv='Refresh' content='2; URL=login.php'/>");
    ?>
    
    PHP:
     
    Eran-s, Apr 9, 2007 IP
    SEMrush
  2. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #22
    ok did it , im sooo close, its funny though i put the code you said made a few changes to go with my pop up and all , works great !! im excited but look what happens to it when you get the pop up message, it is suppose to bring me back to the login.php but it actually doubles it , go look at www. thetruthdiscovered.com/ members/ grattitude, then click on the menu about us , the about us is where i am testing the log in :) let me know :)

    you have to put the link together they wont let me post that here , dont no why i think i have to wait 7 days :(

    ELaine
     
    bmtpep, Apr 9, 2007 IP
  3. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #23
    ok i got it i took out the java with the pop up and used the meta , it works great now i just have to post the notification on the page !

    i just want to thank all of you for helping i have been to MULTIPLE forums with the same problem and you guys are the only ones that took the time to help me and walk me through it step by step ! i want to say thank you oh so very much and God bless !!

    Thank you again,

    Elaine !
     
    bmtpep, Apr 9, 2007 IP
  4. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #24
    Ok hold on now lol , i logged in , but it still redirects me to the page ? so it does that even though im logged in ! any ideas?

    Elaine
     
    bmtpep, Apr 9, 2007 IP
  5. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #25
    ok so i got the loggedin.php file as follows:
    
    <?php    
    if(!isset($_SESSION['username'])); 
     {
        
         echo("<meta http-equiv='Refresh' content='2; URL=../login.php'/>");
    }
    ?>
    
    PHP:
    it redirects me to the log in page , works great ! but you have to remember im not very experienced with this , but it seems that , thats all it does, no matter what , cause when i go to this page while im logged in it redirects me anyways , it is like it is not going to check if i am logged in , it just redirects me no matter what , am i missing something ?

    Elaine
     
    bmtpep, Apr 9, 2007 IP
  6. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #26
    Yeah, I would put it in the 'else' statement, you know, the one where it tells you that you were unable to log in. That way it tells you that and then sends you over to the next page. Put in a delay if you want, not sure how to do that.
     
    D_C, Apr 9, 2007 IP
  7. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #27
    yea i try to put the else, but it says the error :

    unexpected T_ELSE

    maybe im doing it wrong?

    ELaine
     
    bmtpep, Apr 9, 2007 IP
  8. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #28
    i have this :

    
    <?php   
    
    if(!isset($_SESSION['username'])) 
     {
        echo "The if statement evaluated to true";
    
    }else{
         echo("<meta http-equiv='Refresh' content='2; URL=../login.php'/>");
    }
    ?>
    
    PHP:
    it always gives me the first result, even if i am not logged in

    anyone ?

    Elaine
     
    bmtpep, Apr 9, 2007 IP
  9. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #29
    
    else { 
        echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>"; 
        include 'login.php'; 
        echo "<meta http-equiv='Refresh' content='2; URL=../login.php'/>";
    
    PHP:
    That should work. If not, tell me what error you get.

    Leave the rest of your code the way it was at the start.
     
    D_C, Apr 9, 2007 IP
  10. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #30
    i have this now:
    
    <?php   
    
    if(!isset($_SESSION['username'])) 
     {
        echo "The if statement evaluated to true";
    
    }else
    {     
    echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";     
    include 'login.php';     
    echo "<meta http-equiv='Refresh' content='2; URL=../login.php'/>";
    }
    ?>
    
    PHP:
    and when i go to the page , NOT logged in , i get the first result still , it should give me the second one and redirect me but it doesnt

    Elaine
     
    bmtpep, Apr 9, 2007 IP
  11. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #31
    Ok here it all is, step by step
    first of all there is the log in page


    
    
    <title>The Truth Discovered -  Log In</title>
    <?php include("header.php"); ?>
    
    <p align="center"><font face="Calligraphic" font color="white" size="5">Log In</font>
    
    <center>
    <form action="checkuser.php" method="post">
    <table align="center" border="0" cellspacing="0" cellpadding="3">
    <tr><td><font face="Calligraphic" font color="white">Username:</td><td><input type="text" name="username" maxlength="30"></td></tr>
    <tr><td><font face="Calligraphic" font color="white">Password:</td><td><input type="password" name="password" maxlength="30"></td></tr>
    <tr><td colspan="2" align="center"><input type="submit" name="sublogin" value="Login"></font></td></tr>
    
    </table>
    </form>
    </center>
    
    <br>
    <p align="center"><font face="Calligraphic" size="3" font color="white">Do not have an account ?<br> Please Click on the link to proceed to the <a href="form.php"><font face="Calligraphic" size="3" font color="white"><u>Registration Form</u></font></a><br> Thank you </font>.  
    </form>
    
    <br>
    <br>
    
    <?php include 'footer.php'; ?>
    
    
    PHP:


    you log in it goes to the checkuser.php




    
    
    <?php 
    /* Check User Script */ 
    session_start();  // Start Session
    include 'db.php'; 
    $msg = "You could not be logged in! Either the username and password do not match or you have not validated your membership! Please Try again!";
    $msga = "Please enter ALL the information!";
    // Conver to simple variables 
    $username = mysql_real_escape_string($_POST['username']); 
    $password = $_POST['password']; 
    if((!$username) || (!$password)){
        echo "<script langauge=\"javascript\">alert(\"".$msga."\");</script>"; 
        include 'login.php';
        exit();
    }
    
    // Convert password to md5 hash 
    $password = md5($password);
    // check if the user info validates the db 
    $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'"); 
    $login_check = mysql_num_rows($sql);
    if($login_check > 0){ 
        while($row = mysql_fetch_array($sql)){ 
        foreach( $row AS $key => $val ){ 
            $$key = stripslashes( $val ); 
    
        } 
            // Register some session variables! 
            session_register('first_name'); 
            $_SESSION['first_name'] = $first_name; 
            session_register('last_name'); 
            $_SESSION['last_name'] = $last_name; 
            session_register('username'); 
            $_SESSION['username'] = $username;
            session_register('email_address'); 
            $_SESSION['email_address'] = $email_address; 
            session_register('special_user'); 
            $_SESSION['user_level'] = $user_level;
            mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
            header("Location: members/login_success.php"); 
        } 
    } else { 
        echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>"; 
        include 'login.php'; 
    } 
    ?> 
    
    
    
    PHP:


    then it brings you to the welcome page (please excuse me this isnt all finished to perfection )



    
    
    <?php include 'headermem.php'; ?>
    <center>
    <table border="1" width="900"><td>
    <center><font face="Calligraphic" size="4" font color="#FFFFFF"> Welcome !! <br> You have made it to the members area! 
    
    <br><br> <a href=logout.php>Logout</a></font></center>
    </td>
    </table>
    </center>
    <?php include 'footermem.php'; 
    ?>
    
    
    PHP:

    (which is not in the root directory anymore it is in a folder off the root)
    then once your in the welcome page which should be the members area, there is a link to go aboutus.php page , which i am using to test this log in verification , the code is as follows:




    
    
    <?php
    include 'headermem.php';
    include_once("loggedin.php");
    include 'footermem.php';
    ?>
    
    
    PHP:

    which obviously is nothing yet , but the header and footer
    directs that page to go to the loggedin.php page which should verify if your logged in or not , which is this :


    
    
    <?php
        // This blurb starts the session for the users.
        session_start();
        header("Cache-control: private"); // Fix for ie6
    
    ?>
    // NOW you can put your code here:
    <?php   
    if(!isset($_SESSION['username'])); 
    
     {
        
         echo("<meta http-equiv='Refresh' content='2; URL=../login.php'/>");
    }
    ?>
    
    
    PHP:


    there you have it , all in a nutshell! and i cant seem to figure it out why it is not verifying ! UGH!

    Help !!

    Thanks alot ALL !!

    Elaine
     
    bmtpep, Apr 9, 2007 IP
  12. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #32
    anyone have any ideas on this ?

    Thanks,
    Elaine
     
    bmtpep, Apr 10, 2007 IP
  13. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #33
    Lets test something, if you don't mind. I want to see if your session registration thing is working.

    
    session_register('username'); 
            $_SESSION['username'] = $username;
    
    PHP:
    get rid of that for a moment. Now when you try to log in it should have no choice but to show that it is false and then redirect you to login.php . If it does, then we know something is wrong with that command (i'm not sure what though...). If it does not, well we can rule that out and get looking at some less obvious things.
     
    D_C, Apr 10, 2007 IP
  14. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #34
    it does the same thing , like always , it goes automatically to the log in page , it always has , you log in , then go to the aboutus.php page , which should give you the aboutus.php page , since i am logged in , but it doesnt it redirects me back to the log in page , it seems like it never checks the database to see if you are logged in or not

    Elaine
     
    bmtpep, Apr 10, 2007 IP
  15. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #35
    ok so i finally got it ! amazing to me , i just put this

    
    <?php   
    if(!isset($_SESSION['username']))  
    {    
    echo "The if statement evaluated to true";
    }
    else
    {     
    echo("<meta http-equiv='Refresh' content='2; URL=../login.php'/>");
    }
    ?>
    
    PHP:
    but that wasnt working, so what i did was simply switch it around to this:
    
    <?php   
    if(!isset($_SESSION['username']))  
    {  
    echo("<meta http-equiv='Refresh' content='2; URL=../login.php'/>");  
    }
    else
    {     
    echo "The if statement evaluated to true";
    }
    ?>
    
    PHP:
    now it works, it verifies that your logged in and brings you to the second result , and if your not logged in redirects you to the log in page ! amazing a simple change like that !

    Well i want to thank everyone for helping me ! in the end it is all worth it all this frustration :)

    Thank you again,
    Elaine
     
    bmtpep, Apr 10, 2007 IP
  16. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #36
    That is interesting though. isset checks to see if the var exists and then sets it to true, else false. (I'm pretty sure that is how it works.)

    I think I made a stupid mistake >.>. I thought you wanted it to redirect it to your login.php page if you did not log in sucessfully. So I got it backwords, that is my fault. But yeah, that is the correct solution and good luck with your website.
     
    D_C, Apr 10, 2007 IP
  17. bmtpep

    bmtpep Guest

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #37
    Thank you :)

    i appreciate all the help you gave me :)

    Elaine
     
    bmtpep, Apr 10, 2007 IP