NameSilo

PHP Fopen To Curl?? Help plz...

Spaceship Spaceship
Watch

rankwarrior

New Member
Impact
0
Hi everyone

I have recently changed servers, and one of my scripts is not functioning on the new server, as fopen is not enabled?

Is it possible to change the following code to use the CURL function instead?

Hope someone can help!
PHP:
<?php

$postToFileName = 'http://www.somesite.com/postfile.aspx';

$postArr = array(

'NM' => $row['Lead_Name'],

'EM' => $row['Lead_Email'],

'PH' => $row['Lead_Tel'],

);

$opts = array(

'http'=>array(

'method' => 'POST',

'header' => "Content-type: application/x-www-form-urlencoded\r\n",

'content' => http_build_query($postArr)

)

);

$context = stream_context_create($opts);

$fp = fopen($postToFileName, 'r', false, $context);

$returnedMessage = '';

while (!feof($fp)) {

$returnedMessage .= fgets($fp);

}

fclose($fp);

if ($returnedMessage == '') {

$returnedMessage = 'No Message';

} else if (strlen($returnedMessage) > 250) {

$returnedMessage = substr($returnedMessage,0,250);

}

$returnedMessage = preg_replace("/[\r\n]/", '', $returnedMessage);

$returnedMessage = mysql_real_escape_string($returnedMessage, $sql);

$q = "UPDATE leads SET Data_Sent = '$returnedMessage' WHERE Lead_ID = $id";

mysql_query($q, $sql);

array_push($leadsSent, $id);

}

}

mysql_close($sql);

return $leadsSent;

}



?>
 
Last edited by a moderator:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
You can try:

PHP:
$ch = curl_init($postToFileName);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postArr));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$returnedMessage = curl_exec($ch);
curl_close($ch);

No need for the following code if the above works:
PHP:
$opts = array(

'http'=>array(

'method' => 'POST',

'header' => "Content-type: application/x-www-form-urlencoded\r\n",

'content' => http_build_query($postArr)

)

);

$context = stream_context_create($opts);

$fp = fopen($postToFileName, 'r', false, $context);

$returnedMessage = '';

while (!feof($fp)) {

$returnedMessage .= fgets($fp);

}

fclose($fp);
 
1
•••
Yes, make sure php.ini safe mode = off

,especially run curl stuffs.

(Hit the nail much in the past :blink: )
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back