HOWTO: Log users into a members area with DA username

try changing:
PHP:
if ($loggedin) {
            // user is logged in, lets setup some session vars for use in our scripts
            $_SESSION['LOGGEDIN'] = true;
            $_SESSION['USERNAME'] = $_REQUEST['username'];
            $_SESSION['PASSWORD'] = $_REQUEST['password'];
            include 'include.php';

TO
PHP:
if ($loggedin) {
            // user is logged in, lets setup some session vars for use in our scripts
            $_SESSION['LOGGEDIN'] = true;
            $_SESSION['USERNAME'] = $_REQUEST['username'];
            $_SESSION['PASSWORD'] = $_REQUEST['password'];
            $_SESSION['SERVER'] = $_REQUEST['domain'];
            include 'include.php';

then on your form set the action to:
action="http://<?php echo $_SESSION['SERVER']; ?>:2222/CMD_LOGIN"
 
Now I need some more help

On my site at http://www.razorblue.com/rbsite_final_header/

I've got a login box - using the members script I want to do something like this for the login box:

If logged in
echo - logged in as <username>
else (ie not logged in)
(display the logon box)

can anyone help me with the code for this please :confused:

Thanks,

Dan
 
You might want to change

PHP:
} else {

            // use did NOT log in successfully (or something went wrong), you might want a message here

            // saying that they did not login correctly

            $_SESSION['LOGGEDIN'] = false;

            echo "login failed";

        }

TO

PHP:
} else {
            // use did NOT log in successfully (or something went wrong), you might want a message here
            // saying that they did not login correctly
            $_SESSION['LOGGEDIN'] = false;
            include ( 'loginfailed.php');
        }

and make a "loginfailed.php" which would contain a failed login message
 
Hi thats not quite what I want to do -

In the members.php file - with the code in it to log into DA i'm doing a header to the index file. Thats that bit.

Now for this bit - if you take a look at the url above you'll see theres a login box in the top corner - I want it to check to see if the user is logged in - if they are - display "logged in as ..."

otherwise (ie if theyre not)

Put the logon fields there - ie username, password, etc to allow the user to log on.

Thanks,

Dan
 
if they are getting to your include.php, then they are logged in.

There is a session variable that holds their username ($_SESSION['USERNAME']) which you can use.

eg:
PHP:
Welcome back <?php echo $_SESSION['USERNAME']; ?>
 
Hi,

I've got the script working - but what i want to know is how to keep the user logged in if they leave that page by using cookies - i've never used cookies before so could someone show me how to do it in this situation.

Thanks,

Dan
 
Last edited:
Not a lot really - I fixed the last bit though was missing a ; - please see my edited post above as this is my next problem.

Sorry to be a nuisance,

Dan
 
If i get time i'll re-write the whole thing for you this morning to use the new API funtions, and to integrate with sites a bit better.
 
I've edited it slightly so that it's based into my webpage as the logon box - it works perfectly - i just need it to stay logged in once you're logged in - aparently that can be done with a cookie - so thats all i need for perfection

Thanks.
 
this script is far from perfection, its not even OOP!!!

add as the very first line of you page:
<?php session_start(); ?>

and then you can check if a user is logged in with:
PHP:
<?php
if ( isset ( $_SESSION['USERNAME'] ) )
{
    // TO DO: Logged in
}
else
{
    // TO DO: Login Form
}
?>
 
I've put that bit at the top of the page:

Basically what i'm doing is having my static page at http://www.razorblue.com/index.php - include the page, the script and the logon form all in the one page and then im going to use index.php?action=whatever to include the various content files in the page.

Im not quite sure what you been by the below - but i'll have a play with it.

Dan
 
Hi,

Still no luck with the above - can you put it into the script above please so I can see where i need to put everything - it seems to me like some parts need to be taken out but im not sure what.

Thanks
 
Last edited:
can't get the damn thing to logout - lol - i cant get it to stay logged in - and now i cant logout lol :D
 
Can someone offer an updated version of this script (allowing for any changes in the API) that will:
  • Once the user is logged in successfully, they are redirected to a specific URL/Page
  • If the user is not successful with login, it will give them 2 more attempts then block them (by ip?) and redirect to another URL/page
  • Log unsuccessful attempts to a flat file giving the attempted domain, username and IP.
I'm not a coder or I would give this a stab myself. Any help would be greatly appreciated!
 
Back
Top