tags:

views:

111

answers:

0

So I have this cURL script for remote login for a website. It works fine for some of the pages but not the page I need.

The remote server requires the url be like this:

 https://sub.example.com/a/b/thisPage.aspx?aVar=/a/b/c/d/File+Name.nev

When I manually enter enter it in my browser after being logged in, it pulls up the page just fine.

<?php  /* index.php */

$user = 'username';
$pass = 'password';
$url = "https://sub.example.com/a/b/";
$redirect = "home.aspx";
$page = $_GET['p'];
$log = $_GET['l'];

if(isset($page)){
 echo "Page before: $page";
//$page = str_replace("/", "%2F", $page); 
//$page = str_replace(":", "%3A", $page); 
 $redirect = $page;
}
/* Only runs if not logged in */
if($log != 1){
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
 curl_setopt($ch, CURLOPT_URL,$url."login.aspx");
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$user&password=$pass");
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

 ob_start();      // prevent any output
 curl_exec ($ch); // execute the curl command
 ob_end_clean();  // stop preventing output

 curl_close ($ch);
 unset($ch);
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ; 
curl_setopt($ch, CURLOPT_SSLVERSION,3); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
//curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");


curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL, $url.$redirect);//page to redirect to

$buf2 = curl_exec ($ch);
$html = str_replace('../images', $url.'../images', $buf2);
$html = str_replace('href="', 'href="index.php?l=1&p=', $html);
curl_close ($ch);

echo $html;
echo "<br />url is $redirect";


?>

Any ideas as to why it won't work on this particular page?