• 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

    • Crowdstrike the same service provider that caused millions of in damages? I hate disliking a company for a singular failure but they really screwed up.
    • I see you subscribe to the Linux/macOS approach to winning over converts...
    • As we get closer to October 2025 and the end of Windows 10 support, Windows 11 will pick up its pace and soon become the most popular desktop operating system worldwide. That's an assertion. It's also quite possible that the only growth will come from attrition as people and companies buy new machines that only come with Win11. It's also possible that we'll get a literal repeat of Win XP and Win 7, where a large number of users just waited until Microsoft gave in and fixed the core problems that the consumers were complaining about in Win Vista and Win 8 when they released Win 7 and Win 10.
    • It's significant growth for Linux considering the market share, so it could have had that effect I described.
    • Microsoft and Crowdstrike announce partnership on threat actor naming by Pradeep Viswanathan Whenever a cyberattack is discovered, companies disclose it to the public and assign it a unique name based on their internal procedures. Unfortunately, this leads to inconsistencies, as each company has its own naming conventions. As a result, the same threat actor behind a cyberattack may end up with multiple names, causing delays and confusion in response efforts. For example, a threat actor that Microsoft refers to as Midnight Blizzard might be known as Cozy Bear, APT29, or UNC2452 by other security vendors. To address this issue, Microsoft and CrowdStrike are teaming up. These companies will align their individual threat actor taxonomies to help security professionals respond to cyberattacks with greater clarity and confidence. It’s important to note that Microsoft and CrowdStrike are not attempting to create a single naming standard. Instead, they are releasing a mapping that lists common threat actors tracked by both companies, matched according to their respective taxonomies. The mapping also includes corresponding aliases from each group’s naming system. You can view the joint threat actor mapping by Microsoft and CrowdStrike here. Although this threat actor taxonomy mapping is a joint effort between Microsoft and CrowdStrike, Google/Mandiant and Palo Alto Networks' Unit 42 are expected to contribute to this initiative in the future. Vasu Jakkal, Corporate Vice President of Microsoft Security, wrote the following about this collaboration with CrowdStrike: As more organizations join this initiative, the collective defense against cyber threats will undoubtedly be improved.
  • Recent Achievements

    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
    • Reacting Well
      sultangris earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      173
    2. 2
      ATLien_0
      125
    3. 3
      snowy owl
      122
    4. 4
      Xenon
      116
    5. 5
      +Edouard
      93
  • Tell a friend

    Love Neowin? Tell a friend!