Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Http Authentication using PHP ( cURL )

Posted on 2008-11-11
4
Medium Priority
?
11,102 Views
Last Modified: 2013-11-22
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

0
Comment
Question by:phaeberle
  • 3
4 Comments
 
LVL 1

Author Comment

by:phaeberle
ID: 22934738
Here's the Camera's API

NetIPCamAPI-1.4.pdf
0
 
LVL 15

Expert Comment

by:quincydude
ID: 22936005
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
 
LVL 1

Author Comment

by:phaeberle
ID: 22936661
Same thing : 500 internal server error
0
 
LVL 1

Accepted Solution

by:
phaeberle earned 0 total points
ID: 22975578
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question