• 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.
  • Posts

    • Trump is a low-class guy who thinks painting everything in gold makes him look fancy.
    • Don't forget second season pass, that's not part of the superdeluxe edition.
    • Forza Motorsport gets IndyCar, Career mode improvements, and more by Taras Buria Turn 10 Studios announced the next Forza Motorsport update, which includes new content and various game improvements. Update 21 follows the previous Anniversary Update and adds IndyCar, a free expansion for Career mode, Featured Tours, new reward cars, and more. IndyCar is back in the game, allowing you to get behind the wheel of the latest-generation open-wheel racing cars. New vehicles include the 2025 Chevrolet IndyCar and the 2025 Honda IndyCar. There is also the all-new IndyCar Series in Featured Multiplayer. Career mode now has the Champions Cup, a new home for racecar-focused tours in single-player racing. There, you can drive a variety of modern and classic racecars from one-make series to endurance legends. Completing the Champions Cup will give you various high-reward cars like the 1979 BMW #6 BMW Motorsport M1 Procar, the 1998 Nissan #23 Pennzoil NISMO Skyline GT-R, the 2014 Dodge #93 SRT Motorsports Viper GTS-R, and more. Developers also adjusted the in-game pricing for most racecars to make the Champions Cup more accessible. Another change in Update 21 is the return of previous Featured Tours. The game will feature an additional Tour every month, allowing you to earn some of the previous reward cars and participate in the now-ended events. Here is a brief overview of other changes and improvements: Featured Multiplayer has been reorganized, incorporating player feedback, with the goal of providing players with even more event variety. Click here for a rundown of these changes. We’ve implemented BoP Spec changes to the Forza GT2, Forza GT3, Forza Touring Car, and Forza Proto-H divisions with help from participants in the Forza Insiders Program. See the release notes for an overview of the adjustments that have been made. The Challenge Hub menu has been reorganized to more effectively communicate where rewards can be earned as well as the type of rewards available to unlock. We’ve fixed an issue for players using the Fanatec DD2 racing wheel that would assign the peripheral an incorrect mapping profile. All Builders Cup Tours are now immediately unlocked, which means you no longer need to complete the Modern Tour to access the 3 other Builders Cup Tours. In addition, select Builders Cup Series have been updated to feature additional eligible cars and post-launch tracks. A detailed overview of these changes has been included in the release notes. There are also numerous fixes to AI behavior and competitiveness in single-player racing. You can read more about Forza Motorsport Update 21 in a post on the official Forza website.
    • If it ever gets to a reasonable level of parity, I think more real competition in the Windows space would be a good thing. What I like about this is that it's not just another reskinned Linux distro (with all of those inherent problems). It's meant to literally boot and work like Windows NT+. That could be an interesting development one day -- note that this has been in development since 1996, btw.
    • I simply don't get why this "OS" exists. Who cares? Great, you can now run a Windows 95-era stupid game, super cool...
  • Recent Achievements

    • Explorer
      treker_ed went up a rank
      Explorer
    • Apprentice
      CHUNWEI went up a rank
      Apprentice
    • Veteran
      1337ish went up a rank
      Veteran
    • Rookie
      john.al went up a rank
      Rookie
    • Week One Done
      patrickft456 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      639
    2. 2
      ATLien_0
      273
    3. 3
      +FloatingFatMan
      172
    4. 4
      Michael Scrip
      155
    5. 5
      Steven P.
      140
  • Tell a friend

    Love Neowin? Tell a friend!