Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

PHP cURL Dynamic Address

General discussions related to php

Moderators: macek, egami, gesf

PHP cURL Dynamic Address

Postby saur » Fri Jul 06, 2012 3:30 am

In my organization, I can access all the printer details by typing the IP of that printer in the Browser's URL. The Logs page of the printer has a dynamic URL(with a 'dummy' variable changing at each instant..their source code involves usage of the Date and getTime functions).Basically i am accessing remote ui of Canon iR3570 . Well this is the code i wrote for generating the dynamic http address of the logs page.

<html>
<head>

<script type="text/javascript">
function getu() {
var now_time = new Date();
var cgi_str = "http://<ip>/jlp.cgi?Flag=Html_Data&LogType=0&Dummy=" + now_time.getTime();
document.getElementById("address").value=cgi_str ;
}
</script>
</head

<body onLoad="getu()">

<form id="mldsform" action="curlexp2.php" method="get" >
<input type="hidden" id="address" name="address" />
<input type="submit" name="submit" value="Log In" />

</form>

</body>
</html>


-------And the curlexp2.php has the code:-------------------

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$_GET["address"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1');
$result= curl_exec($ch);
echo $result;
curl_close ($ch);


This is what i get on execution:

User information is disabled.
This operation cannot be accepted. User certification is invalid or date expired.
Update page.

However when i just echo out $_GET["address"], i am able to get the correct address. Any clues anyone?? Thanks in advance for your help.
saur
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jul 06, 2012 3:10 am

Re: PHP cURL Dynamic Address

Postby johnj » Fri Jul 06, 2012 7:10 am

curlopt_url is expecting a string. Are you sure that $_GET["address"] is returning a string?

What I mean is ...it should be something like thuis..."http://www.abcde.com" and not just http://www.abcde.com

Also, do error checking:
if($result === false)
{
echo 'Curl error: ' . curl_error($ch);
}
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP cURL Dynamic Address

Postby johnj » Fri Jul 06, 2012 7:13 am

Assign $_GET["address"] to a variable, check if it has a value and then pass it to curl.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP cURL Dynamic Address

Postby saur » Sat Jul 07, 2012 2:32 am

$_GET["address"] has the required URL. I am able to echo out the address and visit that page when i just copy paste the required URL in my browser.
saur
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jul 06, 2012 3:10 am


Return to PHP General

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.