Http Authentication using PHP ( cURL )

I have two IP Camera from DLINK DCS 2121 and I want to see both both on one web page.

The camera requires http authentication. I was trying to authenticate using the attached code , but it won't work.

The reposnse is code 500 internal server error .


Any help would be highly appreciate it.

<?php
// create cURL resource
$ch = curl_init();
 
// set options
curl_setopt($ch, CURLOPT_URL, "http://mydomain.com.org");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, base64_encode('admin:pw001');
 
// grab URL and pass it to the browser
curl_exec($ch);
 
// close cURL resource, and free up system resources
curl_close($ch);
?>

Open in new window

LVL 1
phaeberleCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

phaeberleCEOAuthor Commented:
Here's the Camera's API

NetIPCamAPI-1.4.pdf
0
quincydudeCommented:
Try out this template from
http://blog.taragana.com/index.php/archive/how-to-use-curl-in-php-for-authentication-and-ssl-communication/

/ The usual - init a curl session and set the url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url);
 
// Set your login and password for authentication
curl_setopt($ch, CURLOPT_USERPWD, 'login:pasword');
 
// You can use CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE,
// CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE
//
// You can use the bitwise | (or) operator to combine more than one method.
// If you do this, CURL will poll the server to see what methods it supports and pick the best one.
//
// CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST |
// CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
//
// CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE |
// CURLAUTH_NTLM
//
// Personally I prefer CURLAUTH_ANY as it covers all bases
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 
// This is occassionally required to stop CURL from verifying the peer's certificate.
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a
// common name and also verify that it matches the hostname provided)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 
// Optional: Return the result instead of printing it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
// The usual - get the data and close the session
$data = curl_exec($ch);
curl_close($ch);

Open in new window

0
phaeberleCEOAuthor Commented:
Same thing : 500 internal server error
0
phaeberleCEOAuthor Commented:
There were 2 problems with my primary code.

First on line 9 i missed on parenthesis and second, on the same line, there's no need to encode the user & password.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
File Sharing Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.