Page 1 of 1

NTLM Auth with PHP

Posted: Mon May 08, 2006 2:39 am
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

Posted: Mon May 08, 2006 3:51 am
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");

Posted: Mon May 08, 2006 5:15 am
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]

Posted: Mon May 08, 2006 12:10 pm
by Christopher
Well, you can find out the new URL.

There is a opt to follow redirects -- it is something like CURLOPT_LOCATIONFOLLOW.