Sending server response with CURL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilbit02
    New Member
    • Nov 2007
    • 22

    Sending server response with CURL

    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]
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    are you looking for something like in this user note?

    Comment

    • lilbit02
      New Member
      • Nov 2007
      • 22

      #3
      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.


      Code:
      POST /vendor_script.php HTTP/1.0
      Host: posts.keiserschools.net
      Content-Length: 307
      User-Agent: Mozilla/4.0 (compatible; MSIE 4.0;Mac_PowerPC)
      Content-Type: application/x-www-form-urlencoded
      
       
      
      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

      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][code=html]
      <HTML><HEAD><TI TLE>Inquiry Confirmation</TITLE>
      <SCRIPT language="JavaS cript" type="text/javascript">
      <!-- Yahoo! Search Marketing
      // Segment Id Name: Default Conversion Type
      // Event Type Name: Conversion
      if (typeof(window. ysm_customData) != 'object') window.ysm_cust omData = new Object();
      window.ysm_cust omData.segment_ 1CQC39V79I8FQ0 = "event=1,transI d=,currency=,am ount=";
      // -->
      </SCRIPT>
      <SCRIPT language="JavaS cript" type="text/javascript">
      <!-- Yahoo! Search Marketing
      var ysm_accountid = "1BJPH3R98L58CB 16AFELFBNRQ2G";
      document.write( "<SCR" + "IPT language='JavaS cript' type='text/javascript' "
      + "SRC=//" + "srv3.wa.market ingsolutions.ya hoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid
      + "></SCR" + "IPT>");
      // -->
      </SCRIPT>
      <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
      </script>
      <script type="text/javascript">
      _uacct = "UA-1131017-1";
      _udn="none";
      _ulink=1;
      try{urchinTrack er();}catch(err ){}
      </script>
      </HEAD><BODY topmargin="0" bgcolor="#00000 0"><TABLE align="center" BORDER=0 BGCOLOR="#00000 0" CELLSPACING=0 CELLPADDING=0> <TR> <TD> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR>
      <TD align=center VALIGN=top height="31" bgcolor="#00000 0"> <img border="0" src="http://www.keiserUnive rsity.edu/ecampus/images/top_header.jpg" alt="Keiser University eCampus Distance Education"> </TD> </TR> <TR> <TD VALIGN=top bgcolor="#FFFFF F"><DIV align=center><C ENTER><TABLE cellSpacing=0 cellPadding=0 width=600 border=0><TBODY ><TR>
      <TD><FONT face=Verdana size=2>Thank you for your inquiry into Keiser University eCampus.<br>
      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>
      <!--<br>I will be contacting you soon to provide more information on your program of interest.<br>--><br>Admissio ns Department<br>K eiser University eCampus<br><a href="http://online.keiserUn iversity.edu">h ttp://online.keiserUn iversity.edu</a><br>Toll Free: 888-453-4737 or 888-4Keiser <br></FONT></TD></TR></TBODY></TABLE></CENTER></DIV><DIV align=center><C ENTER><p align="center"> <font face="Arial" size="1"><font color="#808000" ><a href="http://www.keiserUnive rsity.edu/general_info.ht m">General Information</a> | <a href="http://www.keiserUnive rsity.edu/how_to_apply.ht m">How to Apply</a> | <a href="http://www.keiserUnive rsity.edu/prog.htm">Progr ams</a> | <a href="http://www.keiserUnive rsity.edu/online_degree.h tm">Online Education</a><br><br> <a href="http://www.keiserUnive rsity.edu/kserv.htm">Stud ent Services</a> | <a href="http://www.keiserUnive rsity.edu/dept.htm">Depar tments</a> | <a href="http://www.keiserUnive rsity.edu/k_news.htm">New s & Events</a> | <a href="http://www.keiserUnive rsity.edu/default.htm">Ho mepage</a><br><br><br> </p></center></div>"</TD></TR></TBODY></TABLE></CENTER></DIV> </TD> </TR> </TABLE> </TD> </TR> </TABLE></BODY></HTML>[/code]
      Last edited by pbmods; Nov 15 '07, 02:24 AM. Reason: Added CODE tags and line breaks.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, lilbit02.

        So a vendor's application posts data to your script and you want to respond with a status message. Is this correct?

        Comment

        • lilbit02
          New Member
          • Nov 2007
          • 22

          #5
          Originally posted by pbmods
          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?

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            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?

            Comment

            • lilbit02
              New Member
              • Nov 2007
              • 22

              #7
              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]

              Comment

              • lilbit02
                New Member
                • Nov 2007
                • 22

                #8
                You know what I misread what you said. The vendors post to me. My script is the script that is suppose to handle everything.

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  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:

                  [code=php]
                  if( isset($_POST['responseType']) and $_POST['responseType'] == 'HTML' )
                  {
                  echo '
                  <html>
                  .
                  .
                  .
                  </html>';
                  }
                  else
                  {
                  echo 'OK';
                  }
                  [/code]

                  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:
                  [code=html]
                  <input type="hidden" name="responseT ype" value="HTML" />
                  [/code]
                  Last edited by pbmods; Nov 15 '07, 04:52 AM.

                  Comment

                  • lilbit02
                    New Member
                    • Nov 2007
                    • 22

                    #10
                    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!!!!

                    Comment

                    Working...