• 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

    • I don't usually complain about articles here, but this is just ridiculous, you couldn't ask your precious AI to write something about tech instead? This literally has nothing to do with tech.
    • Microsoft's "Athena" AI: A blueprint for your own dev team's productivity boost by Paul Hill Last month, Microsoft made many developer-oriented announcements at its annual BUILD conference. One of the tools that it announced at the time was called Athena, an artificial intelligence agent that lives in Microsoft Teams and aims to speed up product development processes. Now, however, Microsoft has released the blueprint of Athena so anyone can begin implementing a similar helper for their work. Rather than just another chatbot, Athena is a deeply integrated agent accessible through Teams that helps to connect people, tools, and data throughout the product development process. Athena is smart enough to work out what needs to happen next and helps team members get it done without having to go to different applications - Athena controls it all from Teams and you just have to communicate in natural language. Athena can be embedded in several developer workflows including Teams, Azure DevOps, and GitHub. Perhaps the greatest thing about Athena is that it’s not a new product being sold by Microsoft, but rather a methodology and open-source template (Dex) that organizations or individuals can take to build their own AI agents, allowing for more customization. To get started with Athena, you'll want to set up the Dex agent. Microsoft has also published a breakout session video about Athena so you can take a deeper dive. Who it affects, and how The primary beneficiaries of Microsoft’s decision to release Athena open source are engineering teams everywhere who will be freed from boring, repetitive tasks such as pull request (PR) reviews, work item management, and security checks. This will let them get on with coding new features and innovating - something that Microsoft has been pushing hard for since the start of the latest AI revolution. For product managers and engineering leaders, Athena also looks set to be incredibly useful as they will get better real-time visibility into the status of projects, if a release is truly ready for launch, and to ensure the team is aligned. Organizations from small to large will be able to benefit from using Athena. Due to its open-source nature, Athena can be tailored to meet specific development processes. This could unlock faster delivery cycles and improve code quality across the board. Why it's happening Athena is already being used internally at Microsoft by over 2,000 of its engineers. The Redmond giant explained that this has led to “measurable gains” in speed, quality, and focus. Aside from faster review cycles for developers, Athena is also surfacing release-blocking bugs earlier, enabling the consistent completion of security and privacy workflows, and providing quicker health assessments so that teams can gauge the overall health of their software delivery. By handling all these more boring tasks, Athena can free up developers to build more features into their projects. It also has the potential to speed up delivery times so that end users can use the new software faster, and with potentially less bugs. We often hear the term “democratization” in tech, a process that makes technologies more accessible and affordable. According to this definition, Microsoft’s release of Athena delivers on democratizing AI for developers as its open source and allows people to integrate AI Into their workflows, without starting from scratch. The move also aligns with Microsoft's AI strategy, that is, putting it all throughout its products. Copilot is probably the most notorious for its omnipresence in essentially every Microsoft product including Windows and Edge. Unlike Copilot, developers get a bit more freedom with Athena, but it’s still tied up with Microsoft products, namely Teams and GitHub. Caveats and what to watch for While it’s great that Microsoft is making its Athena blueprint accessible, one issue is that developers may still find it a bit complex to implement as there are still specific customizations organizations will want to make. Additionally, this solution involves a more involved setup process as outlined in the GitHub README. Another thing organizations should be wary about is data privacy and security implications when it comes to integrating with sensitive internal systems. Organizations that are working on secretive projects probably wouldn’t want to use Athena as this could put sensitive code in the hands of third parties. It’s not only technical issues that need considering either, there is also the human element. Some people may have concerns about AI hallucinating or ethical concerns around job security that could hurt adoption. To this end, Microsoft has reaffirmed that Athena is supposed to assist teams only, not replace team members. While Athena can be extremely useful, as shown by the results internally at Microsoft, human oversight and judgment will still be vital. Complex decision and creative problem-solving in development are some areas where a human still needs to be involved. Source: Microsoft
    • How could it not be optional? ChatGPT isn't going to guess people's credentials :P
  • Recent Achievements

    • First Post
      James courage Tabla earned a badge
      First Post
    • Reacting Well
      James courage Tabla earned a badge
      Reacting Well
    • Apprentice
      DarkShrunken went up a rank
      Apprentice
    • Dedicated
      CHUNWEI earned a badge
      Dedicated
    • Collaborator
      DarkShrunken earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      383
    2. 2
      +FloatingFatMan
      176
    3. 3
      ATLien_0
      169
    4. 4
      snowy owl
      169
    5. 5
      Xenon
      133
  • Tell a friend

    Love Neowin? Tell a friend!