PHP calling Bash-script

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have real problems getting this PHP-script "search.php" that is called from a "form.htm" to work. What am I doing wrong here?

php
   $old_path = getcwd();
   chdir('/var/www/html/SOKHJALPMEDEL/');
   $term1 = $_POST['query1'];
   $argument1 = $_GET['$term1'];
   $term2 = $_POST['query2'];
   $argument2 = $_GET['$term2'];
   echo $nu_kor_vi1;
   $outcome = shell_exec("sokare $argument1 $argument2");
   chdir($old_path);
   echo "
$outcome
"
; ?>

The script is calling a Bash-script "sokare" that is executable systemwide and residning in "/usr/local/bin". The variables $argument1 and $argument2 are passed from the "form.htm" via $term1 = $_POST['query1']; and $term2 = $_POST['query2']; . The Bash-script looks like this. It is supposed to search any PDF-files residing in "/var/www/html/SOKHJALPMEDEL/" for pages containing both searchwords.

#!/bin/bash

pdfgrep -Hn $1 /var/www/html/SOKHJALPMEDEL/*.pdf | cut -f1,2 -d':' > /tmp/sok1.tmp
pdfgrep -Hn $2 /var/www/html/SOKHJALPMEDEL/*.pdf | cut -f1,2 -d':' > /tmp/sok2.tmp
grep -f /tmp/sok1.tmp /tmp/sok2.tmp

exit 0

I keep on getting this error in "/var/log/apache2/error.log" : PHP Notice: Undefined index: $term2 in /var/www/html/SOKHJALPMEDEL/search.php on line 7, referer: http://localhost/SOKHJALPMEDEL/form.htm

Any help clearing my mess up is beautiful:-)

/Paul

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community