Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-11-2012, 08:01 PM   PM User | #1
eve8080
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
eve8080 is an unknown quantity at this point
PHP Curl Response Issue

Server 1 (file1.php) - File Content:
PHP Code:
 $ch curl_init('www.pasydypremium.com/postme.php');
 
curl_setopt ($chCURLOPT_POST1);
 
curl_setopt ($chCURLOPT_POSTFIELDS"email=info@domain.com&username=qaqaqa&password=1111111");
 
curl_setopt($chCURLOPT_HEADERtrue);
 
$result curl_exec($ch);
 return 
$result;
 
curl_close ($ch); 
Server 2 (file2.php) - File Content:
PHP Code:
$email $_POST['email'];
$username $_POST['username'];
$password $_POST['password'];
//check for duplicate
$duplicate = @mysql_num_rows(@mysql_query("SELECT email FROM table WHERE email='$email'"));

if(
$duplicate == 0){
//Add email into our database
$result = (int)$query = @mysql_query("INSERT INTO users2 (email) VALUES ('$email')");
if(
$result){
$error "Email Inserted";
}else{
$error "Query Error";
}
}else{
$error "Email Duplilcate";

My Question is, i want the second server (file2.php) to send the first server (file1.php) the $error message:
Case 1: email was inserted successfully
Case 2: query could not be excuted
Case 3: Duplicate found

how can then be done?

Thank you.
eve8080 is offline   Reply With Quote
Old 09-11-2012, 08:23 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Not sure I understand the relationship between these two files.

Since the curl code is literally all hard coded from what is in file1, you can simply include it as necessary into file2, and it will have direct access to the $error variable to do with whatever you have to do. Otherwise, you can put it with file_get_contents and provide it with an http wrapper and a querystring with the $error, or even use curl once again to connect to file1.php. I'd opt for the include myself.
Fou-Lu is offline   Reply With Quote
Old 09-11-2012, 08:32 PM   PM User | #3
eve8080
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
eve8080 is an unknown quantity at this point
Basically, we have provided our client file1.php to be located into their server and file2.php is located on our server, every time the clients add an email to their database, file1.php is executed and the email is send to us, our database must also include a copy of the email.

We are looking for a solution!! Client server must send us the email and we must send them back the response.
eve8080 is offline   Reply With Quote
Old 09-11-2012, 08:52 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,665
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
So why are you using cURL to post to postme.php instead of file2.php?

Am I missing something? ???

As for the result of your call to file2.php OR postme.php, it should be contained in the $result variable from file1.php.. if I'm understanding your code and principle correctly and seeing as you're referring to file2.php and postme.php I'm not entirely sure I am.

Confused? Imagine how I feel!
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 09-11-2012, 08:57 PM   PM User | #5
eve8080
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
eve8080 is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
So why are you using cURL to post to postme.php instead of file2.php?

Am I missing something? ???

As for the result of your call to file2.php OR postme.php, it should be contained in the $result variable from file1.php.. if I'm understanding your code and principle correctly and seeing as you're referring to file2.php and postme.php I'm not entirely sure I am.

Confused? Imagine how I feel!
Sorry I just forgot to rename “postme.php” to “file2.php” on this thread, the script is working fine, file2.php is receiving the email and is being inserted into our database, and the problem comes with the response messages.
eve8080 is offline   Reply With Quote
Old 09-11-2012, 09:00 PM   PM User | #6
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,665
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by eve8080 View Post
the problem comes with the response messages.
So what does that mean? You're not getting them at file1.php, you're getting blank messages, PHP error messages?

You're not really telling us what your problem is in order for us to help.

You might want to print $result so that the url request can get the text.. I don't see a print command anywhere.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 09-11-2012, 10:02 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I think I see what you are doing here.
Add a return transfer for the curlopt: curl_setopt(CURLOPT_RETURNTRANSFER, 1);. Now this file will be able to pull the results of the curl_exec call and store it in a variable.
Then with the script its connecting to, just output what is required. If this is exactly what the second script uses, I'd actually return the results as integers and handle it in the receiving file1 script. So on success, print 0, failure print 1. And for a sql error such as a duplicate, I'd push something different.

Now, this is if you want to use curl. This is actually a perfect example of the use of soap services. It takes some work to set up soap server and client's properly, but when you do they sure become easy. What happens here is the client file1 would establish a soap client connection to the remote server. The remote server would present it with a method called say, insertEmailAddress. This method is called much like a regular PHP function, and the results can be captured as a part of the soap protocols for returning. Super easy to use. Soap is somewhat tough to set up on PHP I find.
Fou-Lu is offline   Reply With Quote
Old 09-12-2012, 12:20 PM   PM User | #8
vroom
New Coder

 
Join Date: Sep 2012
Posts: 71
Thanks: 0
Thanked 8 Times in 8 Posts
vroom is an unknown quantity at this point
You could also roll your own XML if you were hesitant to deal with soap. Just define a private protocol and build the string...

<response>
<username>x</username>
<duplicate>0</duplicate>
<email>nobody@nowhere.no</email>
</response>

Be sure to follow encoding rules for the values though.
__________________
I'm sure some folks around here would be happy to get more involved if people posted tasks here and offered a few bucks.

Beware, code snippets in my posts are meant as examples... they certainly may contain typos.
vroom is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:10 AM.


Advertisement
Log in to turn off these ads.