PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    please help

    Share
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    please help

    Post  jknocks on Mon Apr 12, 2010 12:30 am

    i would love to use this login script.....i have all the database info and everything set up i'm kinda a complete newbie when it comes to php the problem i'm having is on the main.php file where he shows a example of a main page and he says you can add it to all your pages....i don't know where to add that to my pages so it will work??? can anyone help me please....thank you in advanced
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Mon Apr 12, 2010 1:18 am

    are you talking about adding the session to all of your pages so they can be password protected? if you are, try adding this to the very top of all of the pages you wish ot password protect:
    [code]<?php
    include("include/session.php");
    ?>[\code]


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Mon Apr 12, 2010 12:30 pm

    Linchpin311 wrote:are you talking about adding the session to all of your pages so they can be password protected? if you are, try adding this to the very top of all of the pages you wish ot password protect:
    [code]<?php
    include("include/session.php");
    ?>[\code]


    i tried that and got a error message..unless i did it wrong???. but what i was refering to was the main.php page where jp said it was a example of what a mian page could look like...i'm assuming i can put that html he has with the php in it on my pages so people will get the option to login or register...and once logged in have the options it has like edit account and if they are a admin it has the link to the admin center....or do i just have to password protect the pages and put links on my pages to that stuff?????

    also where it shows this on the main.php page
    /**
    * User has already logged in, so display relavent links, including
    * a link to the admin center if the user is an administrator.
    */
    if($session->logged_in){
    echo "<h1>Logged In</h1>";
    echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
    ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] "
    ."[<a href=\"useredit.php\">Edit Account</a>] ";



    i added a line after the link to the user edit that included one of my pages so it looked like this

    /**
    * User has already logged in, so display relavent links, including
    * a link to the admin center if the user is an administrator.
    */
    if($session->logged_in){
    echo "<h1>Logged In</h1>";
    echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
    ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] "
    ."[<a href=\"useredit.php\">Edit Account</a>] ";
    include("whatever.php");

    and it loaded the page once i logged in but the things i had on the page was out of place and on the very bottom of the page it added the link to view user info and logout and that was it....
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Mon Apr 12, 2010 10:57 pm

    alright, so just to make sure we are on the same path... you are trying to adapt the script to your needs and add additional pages under the script so they can be password protected, but when you try to include the session at the top of your pages you are getting an error?

    please share, word for word, this error with us so we can figure out the next step to solving your problem.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Tue Apr 13, 2010 3:00 am

    im not getting a error thing now when i add that small php code you said to add it goes right to the page it doesnt even ask me to login??? and im not logged in so it isn't protecting the page....so am i not going to be able to add the main.php page to my pages or add the include part to it like i did??? cause when i added the include part to the main.php page it loads the page i want it to load but it is messed up a little
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Tue Apr 13, 2010 7:32 am

    alright, i think were moving to quickly with this. lets start from the beginning. are you able to make a fresh install of the login script work without changing any of the code? if you can get the script working correctly from the beginning then try including one single page from main.php like you did. if you are able to make this work, take small incremental steps and change the code to suit your needs until you get the result you want.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Tue Apr 13, 2010 12:47 pm

    yes i uploaded it to my host just fine and was able to type my address in the url and go directly to the main.php file itself and create a account with the register link and was able to sign in so i know it is set up with the database fine..i was able to view the edit my account and once i switched it to admin level was able to get into the admin center....when i added the code to the main.php page inculde("whateverfile.php");

    it loaded the page after i logged in but it messes all the objects on the page up it pretty much resizes the page and looks funny....and other then that dont know what i would need to change to the code...im fairly new with php and know some html
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Wed Apr 14, 2010 10:32 pm

    alright well if the page loads "whateverfile.php" and you are still logged in then we are talking more about a design (perhaps css) issue more so than a script issue. if this is the case then we will have to move the thread and take it from there, but just to be sure why dont you post main.php for us so we can see what you have going on in there.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Wed Apr 14, 2010 11:57 pm

    well i tired a new page i made and it dont seem to mess it up that much when i put that page on the include part i added to the main.php page where if you recall up top where i explained where i put it...on the new page i tired it on it shows the edit link on top and the log out link on the bottom of the page...the thing i noticed is it shrinks the right wall of the template to the left.. but here is the link main.php
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Thu Apr 15, 2010 10:47 am

    can you post the code to main.php so we can have a look at it?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Thu Apr 15, 2010 11:57 am

    <?
    /**
    * Main.php
    *
    * This is an example of the main page of a website. Here
    * users will be able to login. However, like on most sites
    * the login form doesn't just have to be on the main page,
    * but re-appear on subsequent pages, depending on whether
    * the user has logged in or not.
    *
    * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
    * Last Updated: August 26, 2004
    */
    include("include/session.php");
    ?>

    <html>
    <title>Jpmaster77's Login Script</title>
    <body>

    <table>
    <tr><td>


    <?
    /**
    * User has already logged in, so display relavent links, including
    * a link to the admin center if the user is an administrator.
    */
    if($session->logged_in){
    echo "<h1>Logged In</h1>";
    echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
    ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
    ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
    include("test.php");
    if($session->isAdmin()){
    echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
    }
    echo "[<a href=\"process.php\">Logout</a>]";
    }
    else{
    ?>

    <h1>Login</h1>
    <?
    /**
    * User not logged in, display the login form.
    * If user has already tried to login, but errors were
    * found, display the total number of errors.
    * If errors occurred, they will be displayed.
    */
    if($form->num_errors > 0){
    echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
    }
    ?>
    <form action="process.php" method="POST">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
    <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
    <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
    <font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="hidden" name="sublogin" value="1">
    <input type="submit" value="Login"></td></tr>
    <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
    <tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
    </table>
    </form>

    <?
    }

    /**
    * Just a little page footer, tells how many registered members
    * there are, how many users currently logged in and viewing site,
    * and how many guests viewing site. Active users are displayed,
    * with link to their user information.
    */
    echo "</td></tr><tr><td align=\"center\"><br><br>";
    echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
    echo "There are $database->num_active_users registered members and ";
    echo "$database->num_active_guests guests viewing the site.<br><br>";

    include("include/view_active.php");

    ?>


    </td></tr>
    </table>


    </body>
    </html>
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Thu Apr 15, 2010 12:14 pm

    ok so if you are saying the page is not being displayed correctly this is definately a design issue, and not a login script issue.

    just a tip to hopefully get the page to render like you want it... try moving include("test.php"); to after the link for the log out.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Thu Apr 15, 2010 2:13 pm

    ok i did that and that put the logout link up top with the other links...but it still re-sizes the template but i think i can live with it i have to test it on the other pages first....i guess the problem i have now is i tried adding this code on my other pages <?php
    include("include/session.php");
    ?>

    so it would protect them, but it didn't protect them they still loaded, when im assuming it should be stopping me since i'm not signed in???
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Thu Apr 15, 2010 6:06 pm

    by just adding <?php include('include/session.php'); ?> your page is now included in the session (along with main.php process.php and all the others). but this alone wont stop users from accessing the page if they are not logged in. you need a little code to tell the page what to do if a user is logged in and what to do if a user isnt.

    try something like this in a page named test.php.
    Code:
    <?php

    include('include/session.php');

    if($session->logged_in){

        echo 'you are logged in and can see this page.';

    }
    else{

        echo 'you are not logged in. please log in to see this page.';

    }

    ?>

    that is the general idea of what you have have going on inside of all of your password protected pages. including session at the top of your pages just passes some info around from page to page (ie. is the user logged in? what is this user's username? etc.) from there, its up to you to tell your individual pages what to display.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Fri Apr 16, 2010 1:04 pm

    i got it workin now thanks for the help... i had to add something to the code to get it to work a friend that finally got on gave me the info........where you said put this

    <?php

    include('include/session.php');

    if($session->logged_in){

    echo 'you are logged in and can see this page.';

    }
    else{

    echo 'you are not logged in. please log in to see this page.';

    }

    ?>



    i had to do this to get it to work

    <?php

    include_once('include/session.php');

    if($session->logged_in){

    echo 'you are logged in and can see this page.';

    }
    else{

    echo 'you are not logged in. please log in to see this page.';
    exit;
    }

    ?>
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Sat Apr 17, 2010 3:46 am

    well i thought it was all working... Sad im having one problem now i made a page that you have to be a admin to view so i tried adding this code to the page

    <?php

    include_once('include/session.php');

    if($session->isAdmin){

    echo 'you are logged in and can see this page.';

    }
    else{

    echo 'you are not logged in. please log in to see this page.';
    exit;
    }

    ?>

    and it logs in cause it shows the links for edit account and the admin center but it gives me the message you are not logged in. please log in to see this page. and doesn't load the page
    any idea why it is giving me that message???
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Sat Apr 17, 2010 10:07 am

    wow, just adding exit; solved your problem? thats quite odd, what version of php are you using?

    and in regards to your new problem instead of if($session->isAdmin){ try if($session->isAdmin()){


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Sat Apr 17, 2010 1:25 pm

    Linchpin311 wrote:wow, just adding exit; solved your problem? thats quite odd, what version of php are you using?

    and in regards to your new problem instead of if($session->isAdmin){ try if($session->isAdmin()){


    ok thanks that worked.... the host im using right now to test everything to make sure it works has php 5.2.10 but the actual host im goin to use once i have it working has 5.2.11 and the exit line stopped the page from loading if i wasn't logged in and i had to add the once statement to where it would include the seesion.php cause i guess it was pullin it twice and i was getting a error but my friend said to add the once statement and it worked fine...but adding those extra parenthesis worked on the admin part thanks for the help
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Sat Apr 17, 2010 1:27 pm

    no problem. glad you got it working now!


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Sat Apr 17, 2010 2:00 pm

    sorry to bother you again but one last question in the file main.php i tried adding the target="_blank" to the edit and my account links so when someone clicked on them it would open in a different window but i got a error message when i tried loading the main.php page assuming it prob doesnt like how i added the target code???

    if($session->logged_in){
    echo "<h1>Logged In</h1>";
    echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
    ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
    ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";

    if($session->isAdmin()){
    echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";


    that is the links i tried adding the target part to so it would look like this

    if($session->logged_in){
    echo "<h1>Logged In</h1>";
    echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
    ."[<a href=\"userinfo.php?user=$session->username\" target="_blank">My Account</a>] &nbsp;&nbsp;"
    ."[<a href=\"useredit.php\" target="_blank">Edit Account</a>] &nbsp;&nbsp;";

    if($session->isAdmin()){
    echo "[<a href=\"admin/admin.php\" target="_blank">Admin Center</a>] &nbsp;&nbsp;";

    the error i got was Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/vhosts/ghostbustersfamily.freeoda.com/main.php on line 33

    am i entering the blank code so it will open the link in a new window wrong??? i removed the blank code i added and it works fine but i'd like to make it so it opens the links in a new window....
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Sat Apr 17, 2010 2:17 pm

    no bother at all, thats what this forum is for!

    your problem is the quotation marks you are using... or i should say the fact that you arent escaping your quotes. try typing target=\"_blank\" instead.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    jknocks

    Number of posts : 18
    Registration date : 2010-04-12

    Re: please help

    Post  jknocks on Sat Apr 17, 2010 2:42 pm

    Linchpin311 wrote:no bother at all, thats what this forum is for!

    your problem is the quotation marks you are using... or i should say the fact that you arent escaping your quotes. try typing target=\"_blank\" instead.


    thanks that worked..looks like php is stricter then html...what does the back slashes do or tell it to do???
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: please help

    Post  Linchpin311 on Sat Apr 17, 2010 3:36 pm

    the forward slash tells php to escape the next character. in this case you are telling php to echo everything inside of the double quotation mark. so when php comes across target=" it thinks you are done with echo and is expecting a semi-colon to finish things off. but when php sees _blank", it throws an error.

    the whole quotation mark thing can really confuse programmers who are new to the language so try this quick read and see if it makes any more sense.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.

    Sponsored content

    Re: please help

    Post  Sponsored content


      Current date/time is Sun Oct 22, 2017 4:56 pm