473,775 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending server response with CURL

22 New Member
Can someone please help me with this. I have gone to forum after forum and read books and just have no idea how to do this.

I need to send a server response in PHP. I'm attempting to do with CURL. I might be making this harder than need be because I over think things and then I get myself all confused.

This is the scenario...I have vendors that post to PHP script. I grab the information and put it in the database. My delimna is my vendors want a success/failure server response. One of the catches is...I have to go to a confirmation and send this server response. How do I go about doing this? My code is below if you have a better way of doing it please let me know. Please help!!!! My logic below is a little different. I was trying to get the URL that sent me the post so that I could send them a response. I might be going about it wrong.

[PHP]$request = '';
foreach ($_GET as $key => $value) {
$value = urlencode(strip slashes($value) );

if ( $request != '' ) {
$request.= '&';
}
$request.= "$key=$valu e";
}



$curl_handle = curl_init();
$url = getenv("HTTP_RE FERER");
curl_setopt($cu rl_handle, CURLOPT_URL, $url);
curl_setopt($cu rl_handle, CURLOPT_HEADER, 1);
curl_setopt($cu rl_handle, CURLOPT_USERAGE NT, $_SERVER['HTTP_USER_AGEN T']);
curl_setopt($cu rl_handle, CURLOPT_POST, 1);
curl_setopt($cu rl_handle, CURLOPT_POSTFIE LDS, $request);
curl_setopt($cu rl_handle, CURLOPT_RETURNT RANSFER,1);

$response = curl_exec ($curl_handle);
echo $response;
[/PHP]
Nov 14 '07 #1
9 5584
ak1dnar
1,584 Recognized Expert Top Contributor
are you looking for something like in this user note?
Nov 14 '07 #2
lilbit02
22 New Member
I don't know enough about cURL to say yes to that. It involves cookies and text files and I simply want to send a response back to the the URL that post to me saying SUCCESS or FAILURE.

That seems so complex. What is occuring seemingly is the vendors are using HTTP_HEADERS tools and based on the response from that they are determing if a lead is good or not.

This is what they get because I send a confirmation page thereafter but they just want a one word response.


Expand|Select|Wrap|Line Numbers
  1. POST /vendor_script.php HTTP/1.0
  2. Host: posts.keiserschools.net
  3. Content-Length: 307
  4. User-Agent: Mozilla/4.0 (compatible; MSIE 4.0;Mac_PowerPC)
  5. Content-Type: application/x-www-form-urlencoded
  6.  
  7.  
  8.  
  9. firstname=strckwendy&middlename=&lastname=strckchew &suffix=&email=strckkeisertest%40strck.com&home=510-541-5267&work=510-541-5267&other=&program=BABA- IBT&address1=134+mine+st.+&city=OAKLAND&state=CA&zip=94601 &age=25&expectedstart=immediately&education=High+School&gradyear=1990&comments=&form=MonsterNetwork
  10.  

HTTP/1.1 200 OK
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: PHP/5.2.0
MicrosoftOffice WebServer: 5.0_Pub
X-Powered-By: ASP.NET
Date: Fri, 19 Oct 2007 18:57:51 GMT
Connection: close



[/code]
Expand|Select|Wrap|Line Numbers
  1. <HTML><HEAD><TITLE>Inquiry Confirmation</TITLE>
  2. <SCRIPT language="JavaScript" type="text/javascript">
  3. <!-- Yahoo! Search Marketing
  4. // Segment Id Name: Default Conversion Type
  5. // Event Type Name: Conversion
  6. if (typeof(window.ysm_customData) != 'object') window.ysm_customData = new Object();
  7. window.ysm_customData.segment_1CQC39V79I8FQ0 = "event=1,transId=,currency=,amount=";
  8. // -->
  9. </SCRIPT>
  10. <SCRIPT language="JavaScript" type="text/javascript">
  11. <!-- Yahoo! Search Marketing
  12. var ysm_accountid  = "1BJPH3R98L58CB16AFELFBNRQ2G";
  13. document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " 
  14. + "SRC=//" + "srv3.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid 
  15. + "></SCR" + "IPT>");
  16. // -->
  17. </SCRIPT>
  18. <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
  19. </script>
  20. <script type="text/javascript">
  21. _uacct = "UA-1131017-1";
  22. _udn="none";
  23. _ulink=1;
  24. try{urchinTracker();}catch(err){}
  25. </script>
  26. </HEAD><BODY topmargin="0" bgcolor="#000000"><TABLE align="center" BORDER=0 BGCOLOR="#000000" CELLSPACING=0 CELLPADDING=0>      <TR>         <TD>            <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>               <TR>
  27.  <TD align=center VALIGN=top height="31" bgcolor="#000000">                     <img border="0" src="http://www.keiserUniversity.edu/ecampus/images/top_header.jpg" alt="Keiser University eCampus Distance Education">                  </TD>               </TR>               <TR>                  <TD VALIGN=top bgcolor="#FFFFFF"><DIV align=center><CENTER><TABLE cellSpacing=0 cellPadding=0 width=600 border=0><TBODY><TR>
  28.   <TD><FONT face=Verdana size=2>Thank you for your inquiry into Keiser University eCampus.<br>
  29.     For over 30 years, Keiser University has provided quality career education in pace with technology and today?s job market demands.<br>Our entire staff is dedicated to your educational and career success through superior student care.<br>Our degree programs start monthly so your career goals are truly only a click away.<br>
  30. <!--<br>I will be contacting you soon to provide more information on your program of interest.<br>--><br>Admissions Department<br>Keiser University eCampus<br><a href="http://online.keiserUniversity.edu">http://online.keiserUniversity.edu</a><br>Toll Free: 888-453-4737 or 888-4Keiser <br></FONT></TD></TR></TBODY></TABLE></CENTER></DIV><DIV align=center><CENTER><p align="center"><font face="Arial" size="1"><font color="#808000"><a href="http://www.keiserUniversity.edu/general_info.htm">General Information</a> | <a href="http://www.keiserUniversity.edu/how_to_apply.htm">How to Apply</a> | <a href="http://www.keiserUniversity.edu/prog.htm">Programs</a> | <a href="http://www.keiserUniversity.edu/online_degree.htm">Online Education</a><br><br> <a href="http://www.keiserUniversity.edu/kserv.htm">Student Services</a> | <a href="http://www.keiserUniversity.edu/dept.htm">Departments</a> | <a href="http://www.keiserUniversity.edu/k_news.htm">News & Events</a> | <a href="http://www.keiserUniversity.edu/default.htm">Homepage</a><br><br><br></p></center></div>"</TD></TR></TBODY></TABLE></CENTER></DIV>                  </TD>               </TR>            </TABLE>         </TD>      </TR>  </TABLE></BODY></HTML>
Nov 14 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, lilbit02.

So a vendor's application posts data to your script and you want to respond with a status message. Is this correct?
Nov 15 '07 #4
lilbit02
22 New Member
Heya, lilbit02.

So a vendor's application posts data to your script and you want to respond with a status message. Is this correct?
Yes this is correct. Can you help?
Nov 15 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya, lilbit.

Sounds like all you'd need to do is echo the response that you want to send, and the vendor's script should do the rest.

Do you have an example of a vendor script that you need to respond to?
Nov 15 '07 #6
lilbit02
22 New Member
Firstly, let me say thiank you soo much for helping me!!! No one has been able to help me with this.

Now that's my issue. I know that's how you do it but I have to print out a confirmation page.

I'm on a windows server. PHP and windows they have their fights.
Some of the vendors just post to the URL and others need a confirmation because the information is posting from a form. So one of the issues is if I code a redirect, I get an error because I'm putting the information posted to us into a database. That's one of those PHP mssql querks.

So as a result I'm printing out a confirmation page inside of the script.

The code is horribly long I would hate to have to put it's entirety here because it has many if/else stmts but I cut it down so you can get a general idea and it's below. This is how I currently have it. I thought to resort to cURL but I'm all out of ideas now. I've been fighting with this for weeks.

[PHP]<?php

@extract($_POST );


if(count($_POST )>0)
{
$server="server ";
$username="user name";
$password="pass word";

$connect=mssql_ connect($server , $username, $password);
mssql_select_db ("db", $connect);

global $body;

if(isset($form) )
{
$Vendor=$form;
}
elseif(isset($F orm_Name))
{
$Vendor=$Form_N ame;
}
elseif(isset($F ormName))
{
$Vendor=$FormNa me;
}
elseif(!isset($ Vendor))
{
$Vendor="";
}


mssql_query("IN SERT into table(Vendor, Last_Name, Actual_Start_Da te, Campus, leadid, Other_Source, Home_Phone_Num, Home_Phone, hphone1, hphone2, hphone3, Home_Phone_CC, Home_Phone_Area , Work_Phone_Area , Work_Phone_Num, Work_Phone_CC, wphone1, wphone2, wphone3, Other_Phone_CC, Other_Phone, Other_Phone_Are a, Other_Phone_Num , ophone1, ophone2, ophone3, Comments, Province, RawData, Work_Phone_Ext, Language, Lead_Source, Lead_Type, First_Name, Program, Address1, Address2, Email_Address, City, State, Zip, Country, Age, Expected_Start_ Date, Education, Grad_Year, Middle_Name, Suffix, Work_Phone, gpa, uscitizen) VALUES ('$Vendor', '$Last_Name', '$Actual_Start_ Date2', '$Campus2', '$leadid', '$Other_Source2 ', '$Home_Phone_Nu m2', '$Home_Phone2', '$hphone1_2', '$hphone2_1', '$hphone3_1', '$Home_Phone_CC 2', '$Home_Phone_Ar ea2', '$Work_Phone_Ar ea2', '$Work_Phone_Nu m2', '$Work_Phone_CC 2', '$wphone1', '$wphone2', '$wphone3', '$Other_Phone_C C2', '$Other_Phone2' , '$Other_Phone_A rea2', '$Other_Phone_N um2', '$ophone1_2', '$ophone2_1', '$ophone3_1', '$Comments2', '$Province2', '$Prerequisites 2', '$Work_Phone_Ex t2', '$Language2', '$Lead_Source2' , '$Lead_Type2', '$First_Name2', '$Program2', '$Address1_2', '$Address2_1', '$Email_Address 2', '$City2', '$State2', '$Zip2', '$Country2', '$Age2', '$Expected_Star t_Date2', '$Education2', '$Grad_Year2', '$Middle_Name2' , '$Suffix2', '$Work_Phone2', '$gpa', '$uscitizen')") ;



$body="This LandingPg submission was received on " . date(DATE_RFC82 2);

foreach($_POST as $key => $value)
{
$body .= "\n $key: $value";

}

//mail message
$to="email";
$from="email";
$subject="subje ct
mail($to, $subject, $body, "From: $from");

}

[confirmation page goes (here simple html document)]

?>

[/PHP]
Nov 15 '07 #7
lilbit02
22 New Member
You know what I misread what you said. The vendors post to me. My script is the script that is suppose to handle everything.
Nov 15 '07 #8
pbmods
5,821 Recognized Expert Expert
Heya, Lilbit.

I'm confused. Is your script supposed to output an HTML confirmation for a human to read, or is it supposed to output something like 'OK' so that the script that sent the request knows that it executed successfully? Or does it handle both cases?

It sounds like the problem is not that the recipient needs to know what you're sending, but that you need to know whether you're getting your data from a form or from an automated script.

My recommendation in that case would be to do what Google (and others) do. Simply add a 'responseType' or similar parameter:

Expand|Select|Wrap|Line Numbers
  1. if( isset($_POST['responseType']) and $_POST['responseType'] == 'HTML' )
  2. {
  3.     echo '
  4. <html>
  5. .
  6. .
  7. .
  8. </html>';
  9. }
  10. else
  11. {
  12.     echo 'OK';
  13. }
  14.  
Naturally, the vendor scripts should leave the 'responseType' parameter alone, whereas you should add a hidden input to any form that is supposed to receive an HTML response:
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="responseType" value="HTML" />
  2.  
Nov 15 '07 #9
lilbit02
22 New Member
Ok. I'll do that. I send an email blast telling the vendors if they post from a to add that hidden value to their posts. Thanks so much for your help!!!! You don't know how happy and helpful you have been to me!!!!
Nov 15 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

17
3213
by: Stefan Richter | last post by:
Hi, I would like to conect to a server by a SSL Conection, to send an SMS. The company that offers the SMS service provided some Code for a http connection, but not for a https connection. Here is the code to send an SMS by http, which works great. Can you help / or do you know a good tutorial / website for php and ssl ??? thanx,
2
2372
by: NurAzije | last post by:
I am trying to make afunction to get information from one file and print it or put it in an array, the problem in headers I can't figure that it is giving me this: ******** HTTP/1.1 400 Bad Request Date: Fri, 21 Oct 2005 14:48:06 GMT Server: Apache Connection: close Content-Type: text/html; charset=iso-8859-1 Bad Request Your browser sent a request that this server could not understand. Request header field is missing colon separator.
2
2442
by: jdonnell | last post by:
How can I send an http request with php that is similar to the following? Notice the raw (unnamed) post data. HTTP/1.1 200 OK Date: Mon, 12 Aug 2002 01:31:10 GMT Status: 200 OK Connection: Close Content-Length: 510 Content-Type: text/xml; charset=UTF-8
4
12152
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes without the user having to wait. I'm doing this (with fsockopen) by sending an http request to a page that does the time consuming stuff and then immediatly closing, without having read any of the response. This way, I don't have to wait for the...
1
9613
by: manikandan.r | last post by:
Hi I am accessing remote url through curl in my script. Sometimes i am getting the curl response as 'Empty reply from server', when the program runs. Can someone help me? --- Mani
0
1520
by: existatus | last post by:
In a form there are entries like this: <input type="text" name="first_name" size="24" /> <input type="text" name="last_name" size="24" /> <input type="hidden" name="must_have" value="12345" /> <input type="hidden" name="recipient" value="myemail@comcast.net" /> <input type="hidden" name="redirect" value="http://mywebsite.com" /> <input type="hidden" name="subject" value="Topic In Question" />
2
6308
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata enctype="multipart/form-data" method="post" name="testform">
3
4031
by: empiresolutions | last post by:
I'm new to sending, receiving, and reading XML. I'm trying to send and receive XML data via cURL. I am using curl because it was so easy with just arrays. I am using the following code to generate the XML and the PHP script that is presently not working. It would be great if some great code god can explain whats wrong to me. build_xml.php <?php '<?xml version="1.0"?>' $xml = "<member><name>name</name></member>"; echo $xml; ?>
6
9981
by: lakmarket | last post by:
Hi, I am trying to send some querysting using cURL. This is the working API http://smpp4.routesms.com:8080/bulksms/bulksms?username=xxxxxxx&password=xxxxxxx&type=0&dlr=0&destination=94xxxxxxxxxx&source=testing&message=testmessage. The infomation given by Routesms.com: Port: 2345
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10048
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9916
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.