0

I am working on a task of localserver 192.168.1.1. I want to fetch the data of a page

192.168.1.1/userRpm/SystemStatisticRpm.htm?Num_per_page=100

I want to display the HTML code returned by this file.

When I am running curl command on terminal like curl -u admin:admin PageURL ( Its returning the code of page)

But when I am using PHP curl then its redirecting me to 192.168.1.1

Can anybody help me ?

My code is :

<?php
$json_url="http://192.168.1.1/userRpm/SystemStatisticRpm.htm?Num_per_page=100";
$username="admin";
$password="admin";
$ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $json_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type:application/json')); 
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

  $result=curl_exec($ch);
  curl_close ($ch);
0

2 Answers 2

2

Please check this

$ch= curl_init();
curl_setopt ($ch1, CURLOPT_URL, 'http://192.168.1.1/userRpm/SystemStatisticRpm.htm?Num_per_page=100' );
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1,CURLOPT_VERBOSE,1);
curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
curl_setopt ($ch1, CURLOPT_REFERER,'http://www.google.com');  //just a fake referer
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1,CURLOPT_POST,0);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 20);

$htmlContent= curl_exec($ch1);
Sign up to request clarification or add additional context in comments.

4 Comments

I got the html code displaying on my screen. Can I get few lines from this code.I mean I just want to get few array values(coming in Javascript array in head section) from this HTML ?
yes sure you can explode the html output at the required portion and get you code
My html code contains this code that is showing on the screen : <SCRIPT language="javascript" type="text/javascript"> var statList = new Array( 0, "192.168.1.179", "88-53-95-28-2B-AF", 194280, 101141053, 0, 0, 0, 0, 0, 0, 0, 0, 1, "192.168.1.170", "60-C5-47-10-37-FD", 132316, 65860791, 0, 0, 0, 0, 0, 0, 0, 0, 2, "192.168.1.151", "68-5D-43-21-76-95", 9887, 3898646, 0, 0, 0, 0, 0, 0, 0, 0); </SCRIPT> I want to fetch IP address and Mac addresses from this code.
First explode at <SCRIPT language="javascript" type="text/javascript"> then you will get the values in one array then try to explode that array or process it with php functions
1

Try this:

$ch = curl_init("addrress");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);

2 Comments

Its still redirecting me to 192.168.1.1 instead of showing the code of file.
Try and wrap a <pre> around the output, or escaping the characters it's returning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.