Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP & Perl


  • Please log in to reply
12 replies to this topic

#1 dubek

dubek

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 22 July 2014 - 12:35 PM

Hi,

I'm  trying to run a php script within perl or if there is a better way to do this, i'm open to ideas.

I have an html form, when submitted, runs a perl script. I would also like it to run a PHP script.

Since i couldn't find a way to do two actions for one button, i am going down this path.

i tried playing around  with the exec() & system() command without any progress.

How can i run the script within perl? or run a perl script within php?

If it matters, my Apache Server is hosted by hosmonster.

Thanks!



BC AdBot (Login to Remove)

 


#2 neilbuddy

neilbuddy

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Rochester MN
  • Local time:11:10 AM

Posted 22 July 2014 - 12:41 PM

You would have to use exec or system in PHP to execute a perl script.  Any data would have to be passed through the command line.  So running the Perl command from PHP would look like:

system("/usr/bin/perl yourperlscript.pl data data2");

I would suggest porting one of the scripts to the other language if possible.



#3 neilbuddy

neilbuddy

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Rochester MN
  • Local time:11:10 AM

Posted 22 July 2014 - 12:46 PM

Another option would be to use curl to submit data to the other script.

<?php
  $postData = '';
  foreach($_REQUEST as $key => $val){
    $postData .= '&'.$key.'='.urlencode($val);
  }

  $ch = curl_init('http://www.yoursite.com/perlscript.pl');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_exec($ch);
?>


#4 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 22 July 2014 - 01:56 PM

Thanks for the quick reply.

 

I have this form

<form name='feedback' method='POST' action='test.php' accept-charset='UTF-8'>

 

This code:

test.php

<?PHP
session_start();

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: login.php");
}

$name = $_SESSION["valid_user"];
$pin = $_SESSION["valid_pin"];

echo "Welcome $name.<br/>You Have Successfully Logged In.";

$DELETE = "$name||$pin";

$data = file("list.txt");

$out = array();

     foreach($data as $line) {
         if(trim($line) != $DELETE) {
             $out[] = $line;
         }
     }

     $fp = fopen("list.txt", "w+");
     flock($fp, LOCK_EX);
     foreach($out as $line) {
         fwrite($fp, $line);
     }
     flock($fp, LOCK_UN);
     fclose($fp);  

system("/usr/bin/perl tfmail.pl");
?>

 

I've added the system part after seeing your reply. tfmail.pl doesn't lunch though.

 

Did i put the code at the wrong place?

 

I'm not agaisn't porting this php code to the already existing tfmail.pl code but i have no clue what to do when it comes to perl...



#5 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 22 July 2014 - 01:59 PM

Now that i'm thinking about it, the perl script takes data from the form so i do believe i would have to run a PHP script from perl and not the other way around. Any way you can help?



#6 neilbuddy

neilbuddy

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Rochester MN
  • Local time:11:10 AM

Posted 22 July 2014 - 03:04 PM

Using the system() command in php would not pass any of the POST data from the form.  But if you set it up to call the PHP script from the perl script the PHP sessions would not work.  Using the PHP curl method should work to pass the POST data from PHP to the perl script.



#7 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 22 July 2014 - 03:28 PM

Ok so i put the curl method php code in the .pl ?

 

Thanks.



#8 neilbuddy

neilbuddy

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Rochester MN
  • Local time:11:10 AM

Posted 22 July 2014 - 03:43 PM

You would put it at the bottom of the PHP script.  All you have to change is the http://www.yoursite.com/perlscript.pl to the URL of your tfmail.pl script



#9 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 23 July 2014 - 07:44 AM

Hi again.

 

This partially works. The perl script brings up a webpage with the selections the user entered in the survey. It then submits the same results by email.

 

1. I don't get the page displaying the results (not a big deal but would ne nice)

2. Results sent by email are funny looking.

 

Here is what it should look like:

 

Web site information request on Thursday, July 10, 2014 at 08:12:41.

----------------------------------------------------------------------

 

(DUB200)First & Last Name:: Kevin

 

Will you attend an evening Staff Christmas Party?: No

 

----------------------------------------------------------------------

 

Here is what i get:

 

Web site information request on Wednesday, July 23, 2014 at 06:32:46.

----------------------------------------------------------------------

 

Will_you_attend_an_evening_Staff_Christmas_Party?: No

 

PHPSESSID: 04rbqfqnit24jvclffa7eiikt6

 

----------------------------------------------------------------------

 

DUB200 is the result of $name = $_SESSION["valid_user"];

 

Thanks for all the help so far!


Edited by dubek, 23 July 2014 - 08:06 AM.


#10 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 24 July 2014 - 03:24 PM

Any ideas? I've tried passing the php session variable from php to perl without success.

 

Thanks!



#11 neilbuddy

neilbuddy

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Rochester MN
  • Local time:11:10 AM

Posted 24 July 2014 - 04:03 PM

The curl_exec($ch); returns the content from the perl script, so you could just print that out.

$output = curl_exec($ch);
echo($output);


#12 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 27 July 2014 - 02:23 PM

 

The curl_exec($ch); returns the content from the perl script, so you could just print that out.

$output = curl_exec($ch);
echo($output);

Duh! Thanks for reminding me.

 

What about passing php session to perl? Or any ideas why the output is different?


Edited by dubek, 28 July 2014 - 09:04 AM.


#13 dubek

dubek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:12:10 PM

Posted 28 July 2014 - 10:45 AM

I was able to get this by changing the "&" for "AND"

 

(DUB200)First AND Last Name:: Kevin

 

Will you attend an evening Staff Christmas Party?: No

 

PHPSESSID: 04rbqfqnit24jvclffa7eii76769

 

I'm not sure why it spits out the PHPSESSID and i don't need it but whatever. It works now thanks.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users