PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 6th, 2002, 06:51 AM
freddy freddy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 freddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Matt's Authorization script

Hi,

I'm trying to use Matt's Authorization script (http://codewalkers.com/seecode.php?id=74), but I have no idea how to drop it into real files. I would like to have a setup just like on codewalkers.com. user/pass with login button. Once the user enters the user/pass and it is correct, they can 'do extra stuff' on the site or logout. I will also use the usersOnline script once the authorization is working :-) Any help would be amazing.

Matt - a cut & paste would be perfect - it would teach the new guys (like me) how to do stuff properly.

thanks.

Reply With Quote
  #2  
Old February 6th, 2002, 07:09 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Matt's Authorization script

OK, let me give you a couple of examples...first off to check if someone is logged in or not, do this
php Code:
Original - php Code
  1.  
  2. $auth = new authenticate;
  3. $logged = $auth->checkLogin();
  4. if($logged) {
  5.    do whatever you want when they are logged in
  6. } else {
  7.    do whatever you want when they are not logged in.
  8. }


As an example, I use that exact same thing for the sidebar to see if I should display a login box, or the box that has the preferences, profiles and change password links.

In order to get a user name, like how I have it at the top of myCodewalker box when you are logged in...do this
php Code:
Original - php Code
  1.  
  2. $auth = new authenticate;
  3. $username = $auth->getName();
  4. echo $username;


Here's the code I use to display to log in form:
php Code:
Original - php Code
  1.  
  2. echo "<FORM ACTION="/cw_user.php" METHOD="POST"
  3. name="loginform">n";
  4. echo "Username:<BR>n";
  5. echo "<input type="text" size=15 name="uname"><BR>n";
  6. echo "Password:<BR>n";
  7. echo "<input type="password" size=15
  8. name="pword"><BR><BR>n";
  9. echo "<input type="submit" class="button"
  10. name="login" value="Login">Â*n";
  11. echo "<input type="submit" class="button"
  12. name="newuser" value="New User">n";
  13. echo "</FORM>n";


and here is what I use to actually log a user in (contained in the script the form calls)
php Code:
Original - php Code
  1.  
  2. if($HTTP_POST_VARS['pword'] && $HTTP_POST_VARS['uname']) {
  3. if($auth->login($uname,$pword)) {
  4. header("Location: $HTTP_REFERER");
  5. }
  6. } else {
  7. echo "Problem logging you in. Try again.n";
  8. }
  9. }


And the code for the new user stuff in the script that form calls I have another form that the user fills in, and then it gets submitted and sent to $auth->createUser($uname,$pword,$email)..

Well, I hope that gets you started a bit, if you run into snags along the way, let me know!

Reply With Quote
  #3  
Old February 6th, 2002, 07:34 AM
freddy freddy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 freddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

Matt - superb. Thanks a million. Not sure where you are, but it is 12:34AM where I am, and I appreciate the help.


Reply With Quote
  #4  
Old February 6th, 2002, 07:42 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Matt's Authorization script

It's the same time here, and I'll be up for quite some time. You may have seen the threads about my new son. I'm pulling night duty to let my wife get rest


Reply With Quote
  #5  
Old February 6th, 2002, 10:40 PM
freddy freddy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 freddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

Matt - I started to assemble the script, using your code as guide.

The function make_seed() is missing from the authorization code. Searched the PHP docs - not there either.

Any ideas ?


Reply With Quote
  #6  
Old February 7th, 2002, 12:25 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Matt's Authorization script

Yep...

function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}

Sorry about that!

Reply With Quote
  #7  
Old February 7th, 2002, 03:48 AM
freddy freddy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 freddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

Matt,

How does your cw_user.php script look like ? I would guess it validates the user, sets some global variables and goes back to the referrer page ? Those global variables hold user/pass and allow you to stay logged in until you press the logout button - right ?

I guess I'm still too new to this to fully get it just yet. A peek at your cw_user.php would solve the mystery - I think ?

Reply With Quote
  #8  
Old February 7th, 2002, 04:22 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Matt's Authorization script

php Code:
Original - php Code
  1.  
  2. if($HTTP_POST_VARS['pword'] && $HTTP_POST_VARS['uname']) {
  3.    if($auth->login($uname,$pword)) {
  4.      header("Location: $HTTP_REFERER");
  5.    } else {
  6.      echo "Problem logging you in. Try again.n";
  7.    }
  8.   exit;
  9. }


That is the code in the cw_user.php that handles the user login. I would post the whole thing for you, but it would just serve to confuse as I do alot of other sorta unrelated stuff in there. Also, I don't use that exact authorization scheme anymore since I have it integrated with this forum...


Reply With Quote
  #9  
Old February 7th, 2002, 05:01 AM
freddy freddy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 freddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

Ok - I know I'm being a pain, but here is what I got so far and I'm getting a weird error:

"Error: A problem was encountered while executing this query."

Seems to point to the do_user.php script I think.

I'm using your authentication script exactly - called it core_auth.php

index.php
------------------
<?php include ("core_auth.php"); php?>

<html>
<body>

<?php

$auth = new authenticate;

$logged = $auth->checkLogin();

if($logged) {
echo "<b>LOGGED IN</b> as ";
$username = $auth->getName();
echo $username;
} else {
echo "<b>NOT LOGGED IN</b>";

echo "<FORM ACTION="do_user.php" METHOD="POST" name="loginform">n";
echo "Username:<BR>n";
echo "<input type="text" size=15 name="uname"><BR>n";
echo "Password:<BR>n";
echo "<input type="password" size=15 name="pword"><BR><BR>n";
echo "<input type="submit" class="button" name="login" value="Login"> n";
echo "</FORM>n";
}
php?>

</body>
</html>
--------------------------------


do_user.php
--------------------------------
<?php
include ("core_auth.php");

$auth = new authenticate;

if ($HTTP_POST_VARS['pword'] && $HTTP_POST_VARS['uname']) {
if($auth->login($uname,$pword)) {
header("Location: $HTTP_REFERER");
} else {
echo "Problem logging you in. Try again.n";
}
exit;
}

php?>
----------------------------

Can you help ?

Reply With Quote
  #10  
Old February 7th, 2002, 05:15 AM
freddy freddy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 freddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

AHA - found my own BUG !!! Excellent. Off to the races.

Freddy

Reply With Quote
  #11  
Old February 10th, 2002, 01:47 PM
alex alex is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 alex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

where's the error? (

the script i tryed it doesn't work!
sigh!

Reply With Quote
  #12  
Old February 11th, 2002, 01:35 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Matt's Authorization script

Alex,

What kind of error are you getting?


Reply With Quote
  #13  
Old November 10th, 2002, 09:03 PM
seanne1 seanne1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 seanne1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Matt's Authorization script

Matt,

I am getting the error "Problem logging you in. Try again." I know the username and password is correct because it has been validated and created in the users table.

As for my code, it is the exact same as listed in freddy's last post where he listed his code. At the time it looked like he was having problems too, but he never posted his fix.

Do you know what could be wrong? I am kinda new to the use of classes, so I am a bit confused.

Thanks.

Reply With Quote