PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 22nd, 2002, 10:46 AM
Jezzmin Jezzmin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Jezzmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
http-auth without pop-up window...

Hi there

Can some1 tell me how I can use http authantification (using either htaccess file or mysql database) without getting the authantification window?...

for example using a usual form instead...I've searched in a whole bunch of pages but didn't find anything...

plz help

Reply With Quote
  #2  
Old August 22nd, 2002, 11:49 AM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

have this piece of code in a function or something somewhere :
php Code:
Original - php Code
  1. <?
  2.     if ($path[0] != "/") { $path = "/".$path; }
  3.    
  4.     $fp = fsockopen ($host, $port, $errno, $errstr, 30);
  5.     if ($fp) {
  6.         fputs($fp, "GET $path HTTP/1.0rn");
  7.         fputs($fp, "Host: $hostrn");
  8.         fputs($fp, "Authorization: Basic ".base64_encode("$config[username]:$config[pwd]")."rn");
  9.         fputs($fp, "rn");
  10.         $str = fgets($fp,128);
  11.         while (!feof($fp)) {
  12.             fgets($fp,128);
  13.         }
  14.         fclose ($fp);
  15.         $splt = explode(" ",$str);
  16.         //print_r($splt);
  17.         if ((integer)$splt[1] < 400) {
  18.             return true;
  19.         }
  20.     }
  21. ?>


then you need to have a single locked directory.. not the same dir as the php page you're in. set $path to go point there (without http://domainname, just "/lockeddir/index.htm")

Set $host to whichever machine has the locked dir (ie. you can use the authentication userbase from another machine), $port to 80 (if using standard http) and that should be that..

you will need to modify the code slightly for your use (ie. put into a function), i can't copy my entire function coz it's inside a bunch of other stuff..

good luck

Reply With Quote
  #3  
Old August 22nd, 2002, 12:37 PM
Jezzmin Jezzmin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Jezzmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: http-auth without pop-up window...

call me stupid but I don't really know how to use it...

well, the

print_r($splt);

works fine. It says bla bla 200 OK if i remove the .htaccess, but when I add the .htaccess access it says 401 Authorization Required...

so...do I have to add anything, that it really authorizes or something?

I'm no newb, but actually never hat to deal with auths and so on ;)

Reply With Quote
  #4  
Old August 22nd, 2002, 12:45 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

you are using basic authentication right?

btw : you have also set $config["username"] and $config["pwd"]?

else, try posting the .htaccess, maybe i can spot something

Reply With Quote
  #5  
Old August 22nd, 2002, 12:54 PM
Jezzmin Jezzmin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Jezzmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: http-auth without pop-up window...

.htaccess:

AuthType Basic
AuthName "Clients Login"
AuthUserFile /not/important/i/guess
require valid-user

config[username] and config[pwd] I've set to a default user (for testing)

Reply With Quote
  #6  
Old August 22nd, 2002, 01:19 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

And it displays the page when you go to the actual URL and type in the username+pwd?

The fputs($fp, "Authorization: Basic ".base64_encode("$config[username]:$config[pwd]")."rn"); bit is what handles the authorization, and I took the format from the HTTP RFC, so it's supposed to work fine.. hmm.. maybe you need extra content, but that's way weird, coz i've been using it quite a bit..

But then, we've been using it in conjunction with IIS (as the auth host), maybe there's something slightly different in Apache, but as far as i know, they're supposed to handle authentication in the same way..

maybe try posting your entire modified script? (even a simplified version that almost if there's stuff you don't want anybody else to see ;))

Reply With Quote
  #7  
Old August 22nd, 2002, 01:29 PM
Jezzmin Jezzmin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Jezzmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: http-auth without pop-up window...

*slaps herself*

uhm...now thats what I call dumb

the .htpasswd was in the wrong dir, cause it's a subdomain and I mixed somethings up

it says 200 OK now ...one final problem now...

the login.php (where your code is) says OK...why doesnt it show up the locked site, which it has authed for, directly?...it just stays white ...do I have to insert some kind of redirect or something?

waaah I feel like a newb bothering u with such questions

Reply With Quote
  #8  
Old August 22nd, 2002, 01:46 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

my code simply uses the locked site for authentication and returns true or false. If it returns true, you need to write your php to show the site and the content and stuff..

ie. this code is really just like "check if user can login and see site" thing. you have to do the rest to show it..

don't worry, i'm a patient guy... besides, this stuff was quite an interesting ride for myself to figure out a while ago

Reply With Quote
  #9  
Old August 22nd, 2002, 02:01 PM
Jezzmin Jezzmin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Jezzmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: http-auth without pop-up window...

oohh thx a lot

i thought i missed a part where u redirect or something to the locked site

didnt expect to page to be php

used a header(Location bla) now, and it works fine (cause actually the pages are plain html )

thx a lot

Reply With Quote
  #10  
Old August 22nd, 2002, 02:06 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

Anytime! I'm glad i could help ;)

Reply With Quote
  #11  
Old August 22nd, 2002, 02:15 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

btw: if you do a header("location:"), is it going to the locked site? if not, what stops people from just going straight there? if it is locked, i'm surprised that it actually works.

Reply With Quote
  #12  
Old August 22nd, 2002, 03:08 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: http-auth without pop-up window...

actually it works...i mean....ur code already authed the locked part...so why shouldnt it work?

Reply With Quote
  #13  
Old August 22nd, 2002, 03:14 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: http-auth without pop-up window...

Yeah, but it authed it from the locked part.... using itself as the authentication machine and doesn't send the "successfully authed" bit back to the browser.

If you go to the same place the header("location:") takes you, i bet you don't need to log in there..... if it is properly locked, then i'm one very confused person.

Reply With Quote
  #14  
Old August 22nd, 2002, 03:15 PM
Jezzmin Jezzmin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 Jezzmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: http-auth without pop-up window...

uhm...why did i post as anonymous?

ok actually it doesnt work...maybe the browser was still authed, when i entered the pass in the usual pop up window....just tried it at another pc and it didnt work

got any hints how i can solve this?....i'm kinda confused now

Reply With Quote