Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Ajax/Php login system ?

Options
  • 06-09-2008 3:13pm
    #1
    Registered Users Posts: 8,070 ✭✭✭


    Hey guys,
    Have a wordpress blog, need to have login functionality at the side,
    lets say in index.php within <div id="featured">

    What is the best way possible to say someone logs in and it takes them to the same page but the content within 'featured' now has welcome BLAH BLAH instead of the login bit.

    i can do the login with php + cookies/session but any links to how on login would change say whatevers in the div etc ?

    i assume on login it would first take you to the same page using header("Location:......

    Thanks


Comments

  • Registered Users Posts: 4,276 ✭✭✭damnyanks


    Just whack in a in statement to check for the cookie.

    If the cookie exists update the div. If it doesnt leave as is.


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    yeah but how do i overwite the div?


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    Placebo wrote: »
    yeah but how do i overwite the div?

    do you want the page login to disappear instantly after login or is there a page refresh?


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    instant is not required at all, i suppose i could have forwarded on login to index2.php that checks for cookies at the start?

    anyway thinking of using
    document.getElementById('divID').innerHTML="";


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Placebo wrote:
    anyway thinking of using
    document.getElementById('divID').innerHTML="";
    Well yes, this is how you change the content of a Div. Remember the xmlHTTP object keeps the returned text from the request so you can display the returned stuff in the Div or even check it for something. If (success) update Div.


  • Advertisement
  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    Placebo wrote: »
    instant is not required at all, i suppose i could have forwarded on login to index2.php that checks for cookies at the start?

    anyway thinking of using
    document.getElementById('divID').innerHTML="";

    why not do a php statement that says if(!notLoggedin){ print login } else {print welcome user }


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    i see nothing wrong with this, wont work

    this is all in login.php , i take it on login it will not show welcome cookie message as id have to refresh in which case i code use header etc to force a refresh ?
    but in anycayse upon login, it says welcome but upon refresh it takes me back to login........


    [PHP]<?php
    $logged = $_COOKIE["live"];
    ?>
    <html>

    <?php
    if(empty($logged))
    {
    ?>
    <div id="theform">
    <font face="arial" size="2"> log in</font>
    </p>
    <form action="login.php" method="post" name="apply">
    <table>
    <tr><td><font face="arial" size="2">Email Address:</font></td><td><input type="text" name="email"></td></tr>
    <tr height="10"><td colspan="2" align="center"></td></tr>
    <tr><td><font face="arial" size="2">Access Code:</font></td><td><input type="text" name="code"></td></tr>
    <tr height="10"><td colspan="2" align="center"></td></tr>
    <tr><td colspan="2" align="center"><input type="submit" value="Log In"></td></tr>
    </table>
    </form>
    </div>
    <?php
    }
    else
    {
    echo "Welcome";
    echo $_COOKIE["live"];
    echo '<a href="logout.php"> Log Out </a>';
    }


    $email = $_POST;
    $code = $_POST;
    $check_code = md5($code);

    //CONNECTION

    $query ="select reg_id, full_email_address, code from registration where full_email_address = '$email'";
    $execute = mysql_query($query) or die("Cant execute query: ".$query." ".mysql_error());

    $result = mysql_fetch_array($execute);
    $id = $result;
    $dbcode = $result;


    $checkval = strcmp($check_code, $dbcode);

    if ($checkval == 0){
    $expire = 0;
    setcookie("live", "whatever", time()+3600, "/", false);

    echo "Welcome";
    echo '<a href="http://www.mediatize.com/vodafone/lyonstea/logout.php"&gt; Log Out </a>';


    }
    else
    {
    echo "bad username or pass";
    }
    ?>
    </html>[/PHP]

    Just noticed the cookie does not register,
    although cookie code works as a standalone :/ ?


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    You've outputted stuff to browser before setting cookie - IE headers were sent already.

    Try placing ob_start(); at top of script or at least remove lines 4 and 5. These get sent regardless so stuff is outputed. You are then trying to set a cookie down further.

    Hope this sends you on the right path.


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    that worked, thanks a million/
    Never thought of it as im reworking a site and its working fine for them, perhaps cause the form was linked to an external .php file :(


  • Closed Accounts Posts: 10 uasal2000


    Not sure if this is what you want. Usually I figure all the pages I want to secure in the app and include login.php in the first line, this checks if the user is loggedin if the are it prints out the login form and returns otherwise it allows php to continue processing the page, in which case you get the intended ouput


  • Advertisement
Advertisement