• 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 would love to see Musk's face! 🤣🤣🤣
    • I think each AI option has their ups and downs. For Copilot, I find it more personable in how it talks compared to GPT & Gemini. I also appreciate the open ended questions it often provides at the end of its responses to keep the conversation going.
    • Microsoft offers free access to AI video creation with Bing Video Creator by Pradeep Viswanathan Two years ago, Bing Image Creator became one of the first major online services that allowed users to create images from text using OpenAI’s DALL-E model. Today, Microsoft is introducing Bing Video Creator, powered by OpenAI’s Sora, allowing users to create videos with text prompts. Despite announcing Sora last year, OpenAI has not been able to expand its availability to millions of ChatGPT users due to huge AI infrastructure requirements. It is still only available to ChatGPT Pro subscription users, which costs about $200 per month. Recently, Google announced its Veo 3 video generation model, which performs significantly better than OpenAI’s Sora, to all Gemini paid subscribers, making video generation accessible to even Gemini Pro subscribers, which costs just $20 per month. Now, Microsoft is democratizing access to video generation models by making Bing Video Creator free for all Bing users. Bing Video Creator is rolling out today globally (excluding China and Russia) on the Bing Mobile App, and it will be coming soon to the Bing desktop experience within Copilot Search. Bing Video Creator users will have the ability to choose between Fast and Standard generation speeds. Each user will have 10 Fast creations; following that, users can redeem 100 Microsoft Rewards points for each Fast creation or continue with Standard creation speeds. Once you have downloaded the Bing mobile app, here’s how you can access the Video Creator feature: Open Video Creator within the Bing Mobile app by clicking on the menu in the bottom right corner and selecting “Video Creator.” Just type in a text description of the video you want to create in the prompt box. Once the prompt text is ready, just tap “Create.” Or you can also just type directly into the Bing mobile app search bar "Create a video of..." to create a video. You’ll receive a notification when your video is ready to view. If required, you can also download the video or share it via social media or email. You will also have the ability to copy a direct link to the video for easy sharing elsewhere. Microsoft will be storing the generated videos for up to 90 days in your account for easy access later. Microsoft noted that the Bing Video Creator videos are 5 seconds long and can be created only in 9:16 format for now. Microsoft will be adding the 16:9 format soon. When you are waiting for your video to be created, you can also queue up another two videos. Once one of the slots becomes available, you can add another one to the queue. When Bing Video Creator becomes available on desktop, you can visit Bing.com/create for both image and video creation needs.
    • AMD 9060 XT performance benchmarks vs Nvidia 5060 Ti, 5060, AMD 9070 XT, 7600 XT, leaks by Sayan Sen AMD is preparing to launch the RX 9060 XT next and it will be available in two variants, one with 16 GB VRAM and another with half of that at 8 GB. The company publicly defended the latter explaining how it felt there is still a huge market for it as many users do not actually need more than that. We recently wrapped up our review of the AMD Radeon 9070 series with the RX 9070 scoring a 9 out of 10 for AI testing and 7.5 out of 10 in gaming. If you read our reviews you will see that the performance of the is decent for the price but it is definitely more efficient than its XT counterpart. Thus we already have a fairly good idea of how it performs. With the RX 9060 XT launch scheduled for June 5 later this week, reviewers are starting to test the GPU. As such, one such review has accidentally leaked early and it has revealed the performance of the RX 9060 XT variant against the likes of AMD's own 9070 series, 7700 XT, 7600 XT, as well as Nvidia's RTX 5060 Ti, 5060, and more. On average at 1440p, the 9060 XT 16 GB model appears to be a bit slower than the 7700 XT as well as Nvidia's 5060 Ti 16GB. Interestingly though the Radeon GPU does seem to be offering better minimums so maybe we could see a smoother gaming experience overall despite a lower average. AMD says that it is expecting better than 5060 Ti 8GB performance with the 9060 XT 16 GB. The former has an MSRP of $379 while the latter is priced $349. Versus the $299 GeForce 5060 (8GB), the 9060 XT 16 GB is about 10% better but the minimums are a whopping 43% higher. AMD's 9060 XT is also showing excellent performance in case of ray tracing (RT) as you can see in Cyberpunk 2077 above where it is giving comparable throughput as the 7800 XT and is miles better than its preceeding 7600 XT with 63% boost. We see a similar situation in Black Myth: Wukong as well which is another RT heavy game. To understand how AMD achieved the ray tracing gains on RDNA 4, you can read our architecture overview article here. Source and images: BasedDaemonTargaryen (Reddit)
  • Recent Achievements

    • 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
    • First Post
      ClarkB earned a badge
      First Post
    • Week One Done
      Epaminombas earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      149
    2. 2
      Xenon
      122
    3. 3
      ATLien_0
      122
    4. 4
      snowy owl
      99
    5. 5
      +Edouard
      95
  • Tell a friend

    Love Neowin? Tell a friend!