NTLM Auth with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
javi_arboleya
Forum Newbie
Posts: 6
Joined: Thu Mar 30, 2006 2:46 am

NTLM Auth with PHP

Post by javi_arboleya »

Hi,

I need to authenticate into a project server from a PHP script in order to use Project Web Services (PDS), my problem is that I need to use NTLM Auth to get the security token that permits me execute the services.

My question is, what is the best method to do this auth in php?, I suppose that PHP has some libraries to do this so I would like to know what is the best option.

Thanks in advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You probably want to use the CURL library. Specifically look at:

Code: Select all

curl_setopt(CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt(CURLOPT_USERPWD, "$username:$password");
(#10850)
javi_arboleya
Forum Newbie
Posts: 6
Joined: Thu Mar 30, 2006 2:46 am

Post by javi_arboleya »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I use the following piece of code:

Code: Select all

$ch=curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  curl_setopt($ch, CURLOPT_USERPWD, "$myuser:$mypass"); 
//  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  $xml = curl_exec ($ch);
  curl_close ($ch);

  echo '***' . $xml;
and the response obtained is:

Object Moved
This object may be found here.***1

and "here" has a link that points to "http://localhost/PI/SesStart.asp?ref=lgnintau.asp&au=1". But SesStart.asp isn't there because project server is in http://projectserver/projectserver instead of localhost/PI (here is the php script).

Also variable $xml has a value of 1 that it's the response status of the request.

any idea?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Well, you can find out the new URL.

There is a opt to follow redirects -- it is something like CURLOPT_LOCATIONFOLLOW.
(#10850)
Post Reply