Jump to content

Everything works except the curl


liberate

Recommended Posts

Anyone willing to help a newbie?

 

I am trying to receive form_1, add data retrieved from mysql then send (post) the combined data to signup,php and send an email. All but sending to signup.php is working.

 

Please Note: I do not know php code, at best I can only follow the logic of it.

 

Also keep in mind what I need to add for security reasons.

 

 

 

<?php

// code to make Form_1 values $user1 $user2 $fname $lname $list and $email available to Stage1_signup.php - Working

if (isset($_POST['submit'])) {

$list = $_POST['list'];
$user1 = $_POST['user1'];	
$user2 = $_POST['user2'];		
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
}

//connect to database
function dbc() {
//connect to database.
mysql_connect("localhost","foo","bar");
mysql_select_db("fou");
}

// Retreive data from mysql based on user2 - Working
dbc();
$row = mysql_query("select user2,user4,user5,user6,user10 from lm_users where list = 1 and user2 = '".addslashes($user2)."';");
list($user2,$user4,$user5,$user6,$user10)=mysql_fetch_row($row);

// Not Working
// code to send all values of Form_1 and values from mysql to signup.php
// This is the form that the curl is supposed to post

//<form method=post action=http://example.com/mail/signup.php>
//<input type=hidden name=list value=2>
//<input type=text name=fname>
//<input type=text name=lname>
//<input type=text name=email>
//<input type=text name=user1>
//<input type=text name=user2>
//<input type=text name=user4>
//<input type=text name=user5>
//<input type=text name=user6>
//<input type=text name=user10>
//<input type=submit name=sup value="Subscribe Me!">
//</form>

// This code is courtesy of http://www.html-form-guide.com/php-form/php-form-submit.html
//create array of user to be posted
$post_data['list'] = '$list';
$post_data['user1'] = '$user1';
$post_data['user2'] = '$user2';							
$post_data['user4'] = '$user4';
$post_data['user5'] = '$user5'; // does the order need to match the form?
$post_data['user6'] = '$user6';
$post_data['user10'] = '$user10';
$post_data['fname'] = '$fname';
$post_data['lname'] = '$lname';
$post_data['email'] = '$email';

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$curl_connection = curl_init('http://www.example.com/mail/signup.php');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' .
//curl_error($curl_connection);				

//close the connection
curl_close($curl_connection);

// echo all working
echo "$fname";
echo "$lname";
echo "$email";
echo "$user1 $user2 $user4 $user5 $user6 $user10"; // These are all echoing correctly, retrieve from mysql working
echo "$list";

// code to send mail to $user6, an email address retrieved from mysql - mail is working
$to = "$user6";
$subject = "Form Submitted";
$message = "$fname, $lname, $email, $user1"; // working correctly
$from = "mail@email.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
?>

 

 

Any help would be

Edited by liberate
Link to comment
Share on other sites

Here you can have what I have named my gethtml(); function; does the entire curl command in one function.

 

/**
* cURL Run command processes cURL and returns data/headers
*
* @param string $url URL to download
* @param string $cookie Filename of cookie file to store cookie data; false no cookie file used.
* @param string $refer Header to include traffic origination.
* @param mixed $postdata array of postdata or query string.
* @param bool $nbd No Body Download; Returns only request headers.
* @param bool $ssl Use Secure Socket Layer.
* @return string The data returned from the cURL Call.
*/
function gethtml($url, $cookie = false, $refer = false, $postdata = false, $nbd = false, $ssl = false) {
if (preg_match('%(.*/)%', $_SERVER['SCRIPT_FILENAME'], $regs))
$dir = $regs[0];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
if($postdata) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
}
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17");
($cookie)?curl_setopt($ch, CURLOPT_COOKIEFILE, $dir.$cookie):false;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
($nbd)?curl_setopt($ch, CURLOPT_NOBODY, true):false;
($nbd)?curl_setopt($ch, CURLOPT_HEADER, true):false;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $refer);
($cookie)?curl_setopt($ch, CURLOPT_COOKIEJAR, $dir.$cookie):false;
if($ssl)
{
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

$html = curl_exec ($ch);
curl_close($ch);
return $html; //string
}

 

Then simply call it like:

$result = gethtml('http://www.example.com/mail/signup.php', false, false, $post_string);

Edited by DarkerAngel
Link to comment
Share on other sites

Thank you DarkerAngel for your assistance.

 

I don't get any error messages, but it seems to freeze at the curl. Things below the curl that were working are no longer, the echos and the mail. DarkerAngel can no doubt code like a demon but I am obviously doing something wrong.

 

< ?php 

// Please Note: I do not know php code, at best I can only sometimes follow the logic of it.
//
// Also keep in mind what I need to add for security reasons.

// code to make Form_1 values $user1 $user2 $fname $lname $list and $email available to Stage1_signup.php - Working
if (isset($_POST['submit'])) {

$list = $_POST['list'];
$user1 = $_POST['user1'];
$user2 = $_POST['user2'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
}

//connect to database
function dbc() {
mysql_connect("localhost","foo","bar");
mysql_select_db("fou");
}

// Retreive data from mysql based on user2 - Working
dbc();
$row = mysql_query("select user2,user4,user5,user6,user10 from lm_users where list = 1 and user2 = '".addslashes($user2)."';");
list($user2,$user4,$user5,$user6,$user10)=mysql_fetch_row($row);

// Not Working
// code to send all values of Form_1 and values from mysql to signup.php
// This is the form that the curl is supposed to post
//<form method=post action=http://example.com/mail/signup.php>
//<input type=hidden name=list value=2>
//<input type=text name=fname>
//<input type=text name=lname>
//<input type=text name=email>
//<input type=text name=user1>
//<input type=text name=user2>
//<input type=text name=user4>
//<input type=text name=user5>
//<input type=text name=user6>
//<input type=text name=user10>
//<input type=submit name=sup value="Subscribe Me!">
//</form>
/**
* cURL Run command processes cURL and returns data/headers
* Script courtesy of DarkerAngel [url="http://forums.phpfreaks.com/user/59496-darkerangel/"]http://forums.phpfreaks.com/user/59496-darkerangel/[/url]
*
* @param string $url URL to download
* @param string $cookie Filename of cookie file to store cookie data; false no cookie file used.
* @param string $refer Header to include traffic origination.
* @param mixed $postdata array of postdata or query string.
* @param bool $nbd No Body Download; Returns only request headers.
* @param bool $ssl Use Secure Socket Layer.
* @return string The data returned from the cURL Call.
*/
function gethtml($url, $cookie = false, $refer = false, $postdata = false, $nbd = false, $ssl = false) {
if (preg_match('%(.*/)%', $_SERVER['Stage1_signup'], $regs)) //original was SCRIPT_FILENAME
$dir = $regs[0];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
if($postdata) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
}
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57
Safari/537.17");
($cookie)?curl_setopt($ch, CURLOPT_COOKIEFILE, $dir.$cookie):false;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
($nbd)?curl_setopt($ch, CURLOPT_NOBODY, true):false;
($nbd)?curl_setopt($ch, CURLOPT_HEADER, true):false;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $refer);
($cookie)?curl_setopt($ch, CURLOPT_COOKIEJAR, $dir.$cookie):false;
if($ssl)
{
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
$html = curl_exec ($ch);
curl_close($ch);
return $html; //string
}
$result = gethtml('http://www.example.com/mail/signup.php', false, false, $post_string); //actual site hidden


// echo Not Working
echo "$fname";
echo "$lname";
echo "$email";
echo "$user1 $user2 $user4 $user5 $user6 $user10"; // None echoing , Nort working
echo "$list";

// code to send mail to $user6, an email address retrieved from mysql - mail is Not working
$to = "$user6";
$subject = "Form Submitted";
$message = "$fname, $lname, $email, $user1"; // working correctly
$from = "[email="mail@email.com"]mail@email.com[/email]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
?>

 

Once again, newbie needing some help.

Thanks in advance

Tom

Link to comment
Share on other sites

The host is Bluehost bluehost.com

gooogling "bluehost" and "curl" to see what I find...

 

Here is the answer of the Bluehost support:

"Our servers allow cURL to work properly and don't require cURL to be run through a proxy server unlike some other hosts. The only thing that might prevent a cURL connection to another server would be the port it's trying to connect on when you activate the plugin. We only allow connections via port 80. If it's any other port, you would need to purchase a dedicated IP address and let us know which port is being used so that we may open it up for you."

 

It mentions "when you activate the plugin".... Looking....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.