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 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: 3
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: 3
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: 3
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: 3
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: 3
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: 3
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: 25
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: 3
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
  #15  
Old August 22nd, 2002, 03: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: 3
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...

i'm guessing, but try this :

header("Authorization: Basic ".base64_encode("$config[username]:$config[pwd]"));

before the header("location");

I'm sucking this out my thumb.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > http-auth without pop-up window...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek