PHP - Variables In Exec Not Working As They Should?
I've got a mailing list (uses DadaMail) which provides a perl script (subscribe_email.pl) so that I can pass subscribers to it thorugh a PHP script.
Info he http://dadamailproject.com/support/documentation-5_0_1/COOKBOOK-subscriptions.pod.html#command_line_utility___subscribe_email_pl The trouble is I can get it working when variables are passed to it via URL query strings, but when I try to hard-code variables into it it stops working. I can't see any reason for this, it's got me really confused. This works: - Code: [Select] <?php // example usage: - // http://www.domain.com/ds1.php?sendto=user@domain.com&title=Mr&forename=John&surname=Doe&company=None&country=UK if (isset($_GET['sendto'])) { $email = $_GET['sendto']; } if (isset($_GET['title'])) { $title = preg_replace("/[^A-Za-z ]/", "", $_GET['title']); } if (isset($_GET['forename'])) { $forename = preg_replace("/[^A-Za-z\-. ]/", "", $_GET['forename']); } if (isset($_GET['surname'])) { $surname = preg_replace("/[^A-Za-z\-. ]/", "", $_GET['surname']); } if (isset($_GET['company'])) { $company = preg_replace("/[^A-Za-z()\-.& ]/", "", $_GET['company']); $company = str_replace('&', 'and', $company); } if (isset($_GET['country'])) { $country = preg_replace("/[^A-Za-z\-.& ]/", "", $_GET['country']); $country = str_replace('&', 'and', $country); } if (isset($email)) { $exec_command = 'perl ./subscribe_email.pl --list mylist --email '. $email; if (isset($title)) $exec_command .= ' --fields title '. $title; if (isset($forename)) $exec_command .= ' --fields forename '. $forename; if (isset($surname)) $exec_command .= ' --fields surname '. $surname; if (isset($company)) $exec_command .= ' --fields company '. $company; if (isset($country)) $exec_command .= ' --fields country '. $country; exec(escapeshellcmd($exec_command)); } else { echo 'Nothing to do'; } ?> The mail address and all the parameters are passed to the subscribe_email.pl script. But, this doesn't work: - Code: [Select] <?php $subscriber_email = 'user@domain.com'; $subscriber_title = 'Mr'; $subscriber_forename = 'John'; $subscriber_surname = 'Doe'; $subscriber_company = 'None'; $subscriber_country = 'UK'; if (isset($subscriber_email)) { $email = escapeshellcmd($subscriber_email); } if (isset($subscriber_title)) { $title = preg_replace("/[^A-Za-z ]/", "", $subscriber_title); } if (isset($subscriber_forename)) { $forename = preg_replace("/[^A-Za-z\-. ]/", "", $subscriber_forename); } if (isset($subscriber_surname)) { $surname = preg_replace("/[^A-Za-z\-. ]/", "", $subscriber_surname); } if (isset($subscriber_company)) { $company = preg_replace("/[^A-Za-z()\-. ]/", "", $subscriber_company); $company = str_replace('&', 'and', $company); } if (isset($subscriber_country)) { $country = preg_replace("/[^A-Za-z\-. ]/", "", $subscriber_country); $country = str_replace('&', 'and', $country); } if (isset($email)) { $exec_command = 'perl ./subscribe_email.pl --list mylist --email '. $email; if (isset($title)) $exec_command .= ' --fields title '. $title; if (isset($forename)) $exec_command .= ' --fields forename '. $forename; if (isset($surname)) $exec_command .= ' --fields surname '. $surname; if (isset($company)) $exec_command .= ' --fields company '. $company; if (isset($country)) $exec_command .= ' --fields country '. $country; exec(escapeshellcmd($exec_command)); } else { echo 'Nothing to do'; } ?> In the second example, only the list and email parameters are passed, all the others are lost (or ignored). All that's different between the two is the way the variables are inititally set, I can't for the life of me figure out why the second one isn't working . Even stranger, I tried testing with just: - Code: [Select] <?php exec("perl ./subscribe_email.pl --list mylist --email user@domain.com --fields title Mr --fields forename John--fields surname Doe --fields company None --fields country UK") ?> and this doesn't work fully either (again just the list and email parameters are passed). Unfortunately, it's the second method I need to use as it's tagged on to the end of a contact form processing script which initiates the subscription if a checkbox is left ticked...and all variables will be coming from this form script. Any help greatly appreciated! Similar TutorialsHi, I have a java file that needs to be executed from my php script, the command I have in it works perfectly when I execute directly in the command line, but when I execute it from php it returns this: array(0) { } I have tested that the exec works by using antiword, which does return results as expected, but its not working for the code below. But I would much rather use apache tika. Also your thoughts on whether this is good practice please. I am using this to extract text from CV's and store that in the db to be able to search through. I need to extract from: pdf, doc, rtf and docx. this is the only tool I have found that can handle them all. your help on the exec problem and any suggestions will be much appreciated. Code: [Select] <?php exec('java -jar /etc/tika-app-1.0.jar -t /var/www/html/cvdatabase/400001.doc', $output); var_dump($output); ?> I have a username alam for the server I have sudo access to execute linux commands. I could configure almost all files the root can do. I wrote this script on the server for test as I need to provide the server some functionality ----------------- Code: [Select] <?php $cmd="ls -l"; echo exec($cmd,$ret_value) . "<br />DONE"; echo "<pre>".shell_exec($cmd)."</pre>DONE"; ?> ------------------ I get the OUTPUT as follows - ------------------ DONE DONE -------------------- I am novice user of Linux however any kind of help will be appreciated .......... Hello All, In below script, I'm using another script called "SimpleImage.php" to upload and resize photos for a news site. The problem comes with renaming the photos. I need to name the photo based off of the story id. I have everything right to get the story id, but saving it as the variable is what's confusing me. Here's what I have: <?php include ("newsconnection.php");?> <?php $picturename = $_POST['newstoryid']; include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['uploaded_image']['tmp_name']); $image->resizeToWidth(300); $image->save('$picturename'); ?> It's the $image->save('$picturename'); line that's messing me up. Any help would be great!! Hello all, I'm passing variables through a URL. This will work: echo $v4; But neither of these will: echo "<a href='test.php?v4=$v4'>Places</a>"; echo "<a href='test.php?v4=".$v4."> Places</a>"; It WILL work if I hardcode v4, like so: echo "<a href='test.php?v4=Utah'>Places</a>"; But that's useless to me, as I don't want to have to write 50 If statements for every database entry. Does anyone know how to fix this? Thanks! I have no idea and there is no reason why this should not be working. im simply trying to add three variables into a database, and only one works. the other two do not work for any reason i can find. can someone point out my error, if any? code: <?php $date = date("Y-m-d"); $dbc = mysqli_connect('localhost', 'root', '', 'timer') or die('Error connecting to DB'); $query = @"INSERT INTO sessions (date, user, sessiontime) VALUES ('$date', '$user', '$sessiontime')"; $user = @$_GET['user']; $sessiontime = @$_GET['clock']; if (@$_GET['addDB'] == "Session Complete") { mysqli_query($dbc, $query) or die( '<br>Query string: ' . $query . '<br>Produced error: ' . mysqli_error($dbc) ); } ?> Form: Code: [Select] <label for="user"><b><em>Your name: </b></em></label><br /><input type="text" name="user" value="Admin/User" /> <input id="clock" name="clock" type="text" value="00:00:0" readonly><br> <input id="startstopbutton" type="button" value="S t a r t" onClick="startstop();" style="font-weight:bold"><br> <input type="submit" name="addDB" value="Session Complete" /> See, all the variables match up!? I dont get what im doing wrong? hi,
I'm new to php. I tried to get sum of two variables using java script. Value of one variable come from a php variable, Other one is a static value. here is the code
$price_per_day=100; it displays correctly. but when i try to add it with another variable it displays nothing. Please help me.
<!DOCTYPE html> I am trying to run a mysql query to get the sum of a column. When I type out the column name it works. When the column name is stored in a variable it does not seem to work. Code: [Select] <?php $total = $_GET['total']; if ($order != "" && $total != ""){ $query2 = "SELECT SUM('.$type2.') FROM customers WHERE sched=1"; $result2 = mysql_query($query2) or die(mysql_error()); while($row = mysql_fetch_array($result2)){ echo "Total ". " = $". $row["SUM('.$type2.')"]; echo "<br />"; } } ?> Any Help would be appreciated. Hi everyone, I am trying to implement an OAuth system in PHP. I've got the code working but the very first time a fresh, new browser window is opened, the code doesn't work. If I refresh the page and try again, then it works. I have a few suspicions as to where the problem might be but other than that I am stumped. I have two classes: OAuthServer and OAuthClient. I create and store an object of the appropriate class in session variables. I know this is tricky but I am serializing and unserializing properly. To fetch responses from the Server, I am using curl. As curl uses a different session from the browser, I am doing a session_write_close before initializing curl and passing the appropriate parameters to curl. But my code needed to further write session variables even after session_write_close was called and to achieve this, I am calling session_start(), once again, after the curl code is finished. I found that this works but PHP was throwing warnings saying that the header info had already been sent or something like that, but I have suppressed such warnings. I suspect the error has something to do with this but I'm not sure. The part that doesn't work the very first time is that on the server-side, the session variable that is supposed to contain the OAuthServer object is NULL. But if I do a refresh of the page(flow: login_page->error_page), it works. Can anyone tell me why I am encountering the above error and if I am doing things correctly or not. Any help would be greatly appreciated. Thanks & Regards, GarbageGigo
I figure I’m doing something basic wrong.
$cmd = “at $wtime $wdate <<< “sftp -a -r -P xxx xxx@xxx.xxx.net:”.$file.” /mnt/TRFR” ; the “at” command is never generated atq returns blank. But if I copy the output of the echo from the web page into bash the “at” job gets created.
What am I missing here? Edited April 9, 2020 by Henry_WhoI'm trying to open a batch file in php with these contents: Code: [Select] @echo off java -classpath rscd.jar;lib/mina.jar;lib/xpp3.jar;lib/slf4j.jar;lib/xstream.jar;lib/hex-string.jar; org.rscdaemon.server.Server pause My PHP code is simply Code: [Select] $run = "C:\\Users\\Zorian\\Desktop\\EasyRSC\\Server\\run-win.bat"; echo exec("cmd.exe /c " . $run); It should open up a java applet, instead it just echos: Code: [Select] Press any key to continue . . . i have a bash script that i was running with cron jobs: #! /bin/bash start=1000 homedir="/home/alin/NetBeansProjects/Fragger2" numberofprocess=`expr $start + $2` i=$start currentnumber=`ps ax | grep index | grep -c php` case "$1" in start) while [ $i -lt $numberofprocess ] do if [ `ps axo cmd | grep index | grep php | grep -c $i` -lt 1 ] ; then /server/php/bin/php $homedir/index.php $i & fi; i=`expr $i + 1` done ;; stop) while [ $currentnumber -ne 0 ] do kill -9 `ps ax | grep php | grep index | awk {'print $1'} | head -n 1`; currentnumber=`ps ax | grep index | grep -c php` done ;; *) echo "Usage : " $0 "start|stop" ;; esac exit 0 and it was working fine, now i'm tring to make it run from a page . if(isset ($_POST['stop'])){ $conn->update("update `links` set `proccess`=0 "); exec("/home/alin/NetBeansProjects/Fragger2/Trans stop 0"); } if(isset ($_POST['start'])){ if(!preg_match("/^[0-9]+$/", $_POST['proccess'])) echo "proccess should be only a number!"; exec("/home/alin/NetBeansProjects/Fragger2/Trans start ".$_POST['proccess']); } and i don't know why it is not working, i have set for this folder all the permision for this folder "chmod -R 777 /home/alin" it doesn't stop running and i can't figure out why i have to kill the procces from the comand line to stop Hi guys! I have a php script that works and outputs info: <?php echo exec("uptime"); ?> and another that doesn't output anything: <?php echo exec("MP4Box"); ?> Why? Hello, I was just seeing if someone could push me in the right direction. I have a form that uploads items to a database and it also includes uploading images to a directory as a part of that. That all works, but I was thinking for security it'd be best not to leave that directory as 0777 for permissions. In researching this I found the exec() function. I'm still figuring out the relation of who the permissions are associated with and why. All I know is if the directory has 0777 for permissions my script works just fine. I was just seeing if using exec to change the permissions during the process of uploading the images and then change back would be cumbersome and leave open other problems (there won't be any user-based input being passed to that) or if that actually would be the way to go for this. Thanks! -Frank I would like PHP to kick off the following command: Code: [Select] arp -a|sed 's/ /,/g'>arp.csv I also have an executable makeArpFile.sh: Code: [Select] #!/bin/bash arp -a|sed 's/ /,/g'>arp.csv And I have tried executing it in php with the following: $arp = exec("bash makeArpFile.sh", $output, $exit_code); echo("Last line: " . $arp . "\n"); echo("Output: " . $output . "\n"); echo("Exit Code: " . $exit_code . "\n"); /*returns: Last line: Output: Exit Code: 127 */ I also tried just plain old: $arp = exec("makeArpFile.sh", $output, $exit_code); echo("Last line: " . $arp . "\n"); echo("Output: " . $output . "\n"); echo("Exit Code: " . $exit_code . "\n"); /*returns: Last line: Output: Exit Code: 127 */ I can run plain old arp>arp.txt but I really need it formatted in BSD style (arp -a>arp.txt) in order to be able to parse it properly later. Any thoughts? EDIT: for fun I made a useBash.sh script that executed "bash makeArpFile.sh" still no luck. Hi all.
I tried to execute command below Hey guys i am trying to create a small script using exec() to convert PDF files into images ... The script worked well in the past and for some reasons it staped working. exec('"C:\\Program Files\\ImageMagick-6.7.1-Q16\\convert.exe" -verbose -density 150 D:\\Inetpub\\www.goulet.ca\\Pub\\Web\\new\\media\\other\\'.$value.' -quality 100 -sharpen 0x1.0 D:\\Inetpub\\www.goulet.ca\\Pub\\Web\\new\\media\\pdf_flipbook\\'.$value.'\\img.png', $out); the $out var returns an empty array have a executable binary to which i pass some dynamic values as hostname,host id,server name,server id and a text field value. Now i call this binary using exec or shell_exec functions in PHP to stimulate Command executions as a admin. But i am able to invoke the binary and not able to use psexec service of windows. I get logs and DB entries successfully but i also have a xml push operation in psexec call that is required. the format is like :: exec($url,$output,$return_var); url is the command path with parameters . output is an out param and return is the code on execution this is executed in PHP and i want this binary to generate the same output as done from CLI . Currently i guess it's a permission issue with shell that disallows psexec call. How do i invoke the binary with psexec access outside PHP on command shell I have set access privilege of Powershell to "unrestricted" so that any script can be executed. Still it hangs up somewhere in th script causing problems in copying XML file. Powershell psexec is required in the process and i need to track down the root cause so that php side scripting of binary is successfull. Please let me know about your ideas in fixing this. I am using google and trying examples ,but i havent got any feasible solution. Hope some expert advice can guide me out of this. Hello i am trying to execute a linux program for every line of a textarea Code: [Select] $text = $_POST['links']; $text = htmlspecialchars($_POST['links']); $text = nl2br($text); foreach(explode("\n",$text) as $row) { $result = NULL; $command = 'the command'; exec($command,&$result); echo $result[0]."<br>"; } but this always print the result for last line of text area for example if there are 3 lines it print 2 blanks and 1 result... whats wrong?? Folks, I am running Linux Commands in PHP. I am looping through the Domain list and using the below line in my Script: exec('cp -r '.$source.' '.$destination); I am using this in a Foreach Statment, so only the last Even in the loop getting executed, because, the loop is running too fast so the Linux command does not even get initiated, only the last even in loop goes through. What i have done is, i have added a line after exec(); sleep(30); This gives enough time for Linux command to get executed, but is it efficient way to handle timing liek this? Do i need to use time_limit() or something like that? Cheers Natasha Hy i have a GIT repo on a specific location and i need to exec it. so i tooth it was like exec git reset --hard but it executes the command as it was on the base root location. I need before i execute the command to go to my GIT repo location. Can someone help me out? I read about it here http://www.linuxjournal.com/content/bash-redirections-using-exec and if i get it i need a named pipe... but i don't get how i can do it ~.~ i am a exec newbie. |