473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Basic Authentication

I need to send a request from my server
running PHP to another server which is using
Basic Authentication.

How is this done?

I know the realm, username, and password.

Thanks,

Andrew
Jul 17 '05 #1
5 8550
Andrew wrote:
I need to send a request from my server
running PHP to another server which is using
Basic Authentication.

How is this done?

I know the realm, username, and password.


Basic realm authentication:

$fp = fsockopen("host.com", 80);
fputs($fp, "GET / HTTP/1.0\r\n");
fputs($fp, "Host: host.com\r\n");
fputs($fp, "Authorization: basic
".base64_encode("login:password")."\r\n\r\n");

fpassthru($fp);
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
fputs($fp, "Authorization: basic
".base64_encode("login:password")."\r\n\r\n");


Watch for newsreader line breaks, this header should be on one line:

fputs($fp,
"Authorization: basic " .
base64_encode("login:password") .
"\r\n\r\n"
);
JW

Jul 17 '05 #3
Basic realm authentication:

$fp = fsockopen("host.com", 80);
fputs($fp, "GET / HTTP/1.0\r\n");
fputs($fp, "Host: host.com\r\n");
fputs($fp, "Authorization: basic
".base64_encode("login:password")."\r\n\r\n");

fpassthru($fp);


Thanks for the info.

I have a couple more questions:

1. Is required to send the realm?

2. I want to use ImageCreateFromJPEG(URL)
to grab the image from the password protected
server. Can I use the authentication code above
to "unlock" the server then just call this function?

Regards,

Andrew

Jul 17 '05 #4
Andrew wrote:
1. Is required to send the realm?

Only its type, in this case 'basic'.
2. I want to use ImageCreateFromJPEG(URL)
to grab the image from the password protected
server. Can I use the authentication code above
to "unlock" the server then just call this function?


No, you will first have to retrieve the image data and store it in a
variable or a temporary file before you call the imagecreatefromjpeg()
function.
JW

Jul 17 '05 #5
"Andrew" <an****@nowherenohow.com> wrote in message
news:lC*****************@newsread2.news.pas.earthl ink.net...
I need to send a request from my server
running PHP to another server which is using
Basic Authentication.

How is this done?

I know the realm, username, and password.

Thanks,

Andrew


The cleanest way is to use stream_context_create() to create a HTTP context
for POST, then pass the context to fopen(). This method requires a fairly
up-to-date version of PHP, however.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------- This function will utilize the ability to use HTTP-based WWW Authentication, checking for the global...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
1
by: Oran | last post by:
I am trying to integrate an application into our extranets. The extranet technology has its own authentication system requiring a domain user but uses anonymous authentication (from the...
4
by: Joseph | last post by:
I have an intranet application that I setup using windows authentication through IIS basic authentication. Is there a way to set a timeout, so that after ten minutes the user will be prompted...
4
by: Dave | last post by:
Hi, Is there anyway to mimic forms authentication's loginUrl and RedirectFromLoginPage functionality using Windows authentication? We are developing intranet sites using basic authentication...
4
by: Barry | last post by:
The MS fix for IE broke how users access our site (if they patch their browsers), so I need a solution to get users logged onto our site transparently. Basically we used to log on to the site...
2
by: Chad Beckner | last post by:
Hi everyone, I am developing a site in which the root will be set with Anonymous & Basic permissions. Past that I will have an application (directory) in which I will be developing...
3
by: sefe dery | last post by:
hi ng, i try to create a asp.net 1.0 website on windows server 2003(Servername: ServerX) with iis 6.0. PROBLEM: The user should login with his windows credentials in basic.aspx and...
3
by: Martin | last post by:
How does one set up basic authentication on an HttpListener? I know I need to set the HttpListener.AuthenticationSchemes to AuthenticationSchemes.Basic but then I'm unsure how and against what...
0
by: =?Utf-8?B?S29uc3RhbnRpbg==?= | last post by:
I am currently working on the application that need to simulate basic authentication programmatically using user's credentials that are known. Basically, the need is for a single sign on with a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.