• 0

PHP help sending data to script.pl file


Question

Hello,

I'm doing some small work for my company website that takes user input information on a traditional HTML form that then is processed by PHP to save to a file and then pass the original information over to a perl script file located on another server. Currently the website takes the form information as a POST method using an action of action="http://www.differentwebsite.com/scripts/formdata.pl". This script is hosted on a different site so we just can't modify it to do what we want right now unfortunately. So the goal is to write in PHP code that will capture information like city and state, dump it into a file without interrupting the same information that is being passed over to the script on the other site. Basically my company wants to have a 'demographics' log.

Anyway last night I started work on this and I successfully can have PHP capture the data and save it to a log, but can't have it pass it through to the perl script on the other website. I also was able to write the code that passes the information to the remote website's perl script, but unable to get it to capture and save the data to a log. It's been one or the other.

So far I have created PHP variables of $data1, $data2, etc at the top of the page before the form is used. Then later down in the actual form I inserted <input type="text" size="12" name="<?php echo $data1; ?>" value=""> which of course now I see this morning only passes the value of $data1 which I defined as $data1 = that field name.

Advice, help?!

Thanks!

Brad

6 answers to this question

Recommended Posts

  • 0

How are you trying to pass it on to the other server? I'd recommend using cURL: http://us.php.net/manual/en/book.curl.php

It allows you to do a regular HTTP POST so you'd just get the information POSTed to the PHP script and pass that along as a POST to the Perl script using cURL.

  • 0

I have been approaching it by trying not to interrupt the POST process that much if at all in the HTML form and have the PHP just siphon off the string data that the user inputs before it's transmitted to the perl script on the other server. I've attempted this in two ways. First having a data.php page with the HTML form, try to somehow capture the value the user inputs and pass it over to the POST/form. Save the data into a text and be done. I also looked into having two pages, data.php and data2.php. The data is captured in the first one, passed to the second where it's sent to the perl.pl script.

While I know basics and logic of programming, I'm a syntax rookie per say. My main hangup is how to get the string values a user enters and capture that into my variable. That I'm really just not sure how to do at the moment.

  • 0

I forgot to mention when I was trying the option of having an HTML form, instead of sending the data to the perl script on the other website, I sent it to data.php as POST and WAS able to get information into variables that way by using $variable = $_POST['variable'];. However once I got that information I had no idea of how to forward it over to the perl script. That's what made me change back to using the single data.php page and trying to not interrupt the actual POST ability of the form and siphon off the user input into a variable which I have almost working. Just don't have any idea of how to get the input thrown into a variable.

  • 0

Something like this should work to pass it on. You'd POST to the PHP script and that then passes it on. If you're using IP tracking, this will break that, but you can set an X-Forwarded-For header if the other side will make use of that.

&lt;?php
$field1Val = $_POST['field1'];
$field2Val = $_POST['field2'];
$city = $_POST['city'];
$state = $_POST['state'];

//do anything with the stuff above here

// create a new cURL resource to send to the Perl script
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.differentwebsite.com/scripts/formdata.pl");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);  // We are posting to this URL
curl_setopt($ch, CURLOPT_POSTFIELDS, array("field1" =&gt; $field1Val, "field2" =&gt; $field2Val));  //Set the POST data for it

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?&gt;

  • 0

Thanks for that information. That greatly helped!!

However am I able to pass passwords using curl to a perl script? One of the fields is a password for a user to enter in contains a password in the form I mentioned earlier. However implementing the code you gave works for all the fields except the password. Basically what happens is that I'm taken to a secondary page of the server/script I'm trying to pass the information onto with all the fields filled in with the correct info, except the password one.

I looked through the curl options and see several for the passwords but so far... no go. This part of php/curl is new to me so any advice?

Thanks!

  • 0

I also forgot to mention something else I noticed is that when the passing of the information to the script isn't successful, it pulls the page of the script.pl file back and displays it on my data2.php page which is the one that sits between the actual FORM page and the final destination. I also have it echo out the data in all the fields to ensure data is being passed, which in fact it is. It seems to hang up on the password portion and when it does, it loads the destination .pl page on data2.php.

Thoughts? Suggestions?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.