PHP - Exec Function Won't Work For Me Unless I Use Phped
hi guys. i'm new to php and Apache and i have a problem.
i'm trying to execute an exe file that i have in my folder, and the code i use is Code: [Select] echo exec('test.exe');i have tried using this with and without the ".exe." and still no luck. i have also tried using a different path Code: [Select] echo exec('C:\Windows\System32\mspaint');now these codes work when i run them from my php editor(PhpED), bun when i try running it on Apache it gets stuck. (just shows the web page as loading with no end. please help me out. i'm guessing it something with security. also if there is any other code i can use please let me know (i have also tried using system) Similar TutorialsHi all.
I tried to execute command below This code works outside of the while, but not inside while ($row = mysql_fetch_assoc($res)) { $host = $row['host']; $cmd = exec("mysql -h$host -e \"show status like 'wsrep_cluster_size'\""); echo $cmd; } I have found nothing on google, stackoverflow or the php manual that explains why this does not appear to work inside a loop? Hi all, I am a newbie to PHP. I'm trying to execute a program from my PHP script by calling the exec() function of PHP. It works fine when i try it from command line, or execute the script in command line. But when i call it from a php script in my apache, it does nothing. No errors are thrown. What i get in return is only an empty array. i'm using Ubuntu 11.10 and Apache 2.2 with PHP 5.3.3 thanks for helping me. Hmm, hello everyone, i'm running my php in an ubuntu server and I'm trying to run a command using exec (i.e. 'echo 1 > /var/www/test.txt') but I always get a permission denied issue, although i've already changed the permissions to 777 (read-write-execute) Any solution? 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 .......... Hi I'm trying to resize pictures for thumbnails I can do this correctly at linux command line with the following command convert ideologies.jpeg -resize 300x200 ./Thumbnails/testphp.jpg However trying to wrap this in PHP doesn't seem to work // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; exec("convert {['fileName']} -resize 300x200 wankertestphp.jpg"); } If you look above I do successfully hit the "The File has been uploaded successfully" line so it is entering that If statement. I've also checked the Threads table with a Select * from Threads and I can see the $fileName variable is entering there. I've tried numerous different ways around the $fileName variable (removing the brackets...removing the brackets and the apostrophes")
Any help is appreciated. Hi, I'm trying to build a 'simple' page to improve a process where I work.
I'm wanting to do this.
Read either the last line, the last 10 lines, or something I decide on from a log and display the output in table rows and columns.
I've done this before with loops and db query's, but don't know how to approach it using php only as this is the first time I'm using it.
So right now I have this in a table but it will only display one row.
<tr><td colspan="5"> how do i enable exec() in php.ini? where is php.ini? cant find it in the directories in my site. I have a PHP script containing the function exec which works fine in PHP 4 in IIS 7 on Windows 7. However this function does not work in PHP 4 in IIS 5 on windows server 2003. But I have to make it work there because that is what we have on our web server. Can someone provide a solution? Hey guys I usually code in C and I started looking into PHP which I think is pretty good. I'm wondering if there's a function that can be used to execute a command from a remote server on my local machine??? As example if I'd like to have a PHP page/script running on my server which when logged onto would display me a page with buttons like "PING, NETSTAT, IPCONFIG, TRACERT" and when clicked on it would exec those commands but not on the server but from my machine??? So that I would get the PING from my local machine to google.com instead of from the server to google.com ??? making any sense ??? thanks This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=322069.0 When I put this chunk of code into it's own function: function fetch_all ($dbc, $query) { include ('knuffix_list_func.php'); pagination_start ($dbc, $query); $offset = $pag_array[0]; $rows_per_page = $pag_array[1]; $query = $query . " LIMIT $offset, $rows_per_page"; echo "test query: " . $query; knuffix_list ($query, $dbc); pagination_end ($pag_array); } And when I echo out the query as you can see in the example, then I notice that the variables $offset and $rows_per_page never get appended. I set the variable $pag_array to a global inside the function pagination_start(). It usually works when I DON'T wrap a function around this chunk of code, but if I do wrap a function around everything then the global suddenly won't work anymore. Btw, this also won't work if I wrap a function around the function DECLARATIONS. Any ideas, how I could make it work? Hi everyone, It's been awhile since I've coded in PHP and I can't figure out whats wrong with my code... I have a simple function to grab a field from my database and return it. I can make it work without the function, but when I implement it as a function, it breaks - no error, just a blank page. This works fine: $page = "page_about"; $sql = "SELECT body FROM " . $page . " WHERE id=1"; $result = @mysql_query($sql,$connection) or die(mysql_error()); $row = mysql_fetch_array($result); $display = $row[0]; But this does not: function grabBody($page) { $sql = "SELECT body FROM " . $page . " WHERE id=1"; $result = @mysql_query($sql,$connection) or die(mysql_error()); $row = mysql_fetch_array($result); return $row[0]; } $display = grabBody("page_about"); If anyone has any idea whats wrong, please let me know!! Thank you, - Jeff Miller HI...I hope u r all fine. I am using nested function ih php. this is not working.Here is the code. Code: [Select] <?php $array = array('a','b','c'); big_func($array); function big_func($arr) { function func1($arr) { foreach($arr as $list1){ echo $list1.'<br />'; } function func2($arr) { foreach($arr as $list2){ echo '<b>'.$list2.'</b><br />'; } } function func3(){ $arra = array('d','e','f'); func1($arra); } } } ?> This is not working.What is the problem with this code? please help me .....thanks........ Hello Everyone, I am writing a simple CMS system for someone. I am having trouble getting the delete function to work. I pick the user that I want to remove from the system. I verify that this is the right person to remove. Then the record is deleted from the database. The part that picks the person and verifies that it is the right person to remove from the database work fine. It is the part that actually deletes the record. It takes me back to the pick_user.php. If someone could help me with this I would appreciate it This is the code from the show_user_del.php <?php if (!$_POST[id]) { header ("LOCATION: pick_user.php"); exit; } if ($_COOKIE[auth] != "ok") { header("Location: ../login.php"); } require('../includes/auth_user.php'); //build and issue query $sql = "SELECT * FROM $table WHERE id = '$_POST[id]'"; $result = mysql_query($sql, $connection) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $f_name = $row['f_name']; $l_name = $row['l_name']; $username = $row['username']; $password = $row['password']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add Classified Ad</title> </head> <body> <h2><em>Delete user from Database</em></h2> <h3>User being deleted <?php echo "$f_name $l_name"; ?></h3> <form method="POST" action="do_delete_user.php"> <input type="hidden" name="id" value="<?php echo "$_POST[id]"; ?>" /> <input type="hidden" name="f_name" value="<?php echo "$f_name"; ?>" /> <input type="hidden" name="l_name" value="<?php echo "$l_name"; ?>" /> <p> <strong>Name:</strong> <?php echo "$f_name $l_name"; ?> </p> <p> <strong>Username:</strong> <?php echo "$username"; ?> </p> <p> <strong>Password:</strong> <?php echo "$password"; ?> </p> <p> <input type="submit" name="submit" id="name" value="Delete User" /> </p> </form> <p><a href="../admin_menu.php">Return to Administration Menu</a></p> </body> </html> When the submit button is clicked in the above code. It is supposed to bring you to the page below saying that the record was deleted. When the submit button is clicked it sends you back to the pick user page. <?php if ((!$_POST[f_name]) || (!$_POST[l_name])) { header ("LOCATION: show_user_del.php"); exit; } if ($_COOKIE[auth] != "ok") { header("Location: ../login.php"); } require('../includes/auth_user.php'); $sql = "DELETE FROM $table WHERE id = '$_POST[id]'"; $result = mysql_query($sql, $connection) or die(mysql_error()); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <h1>User has been removed</h1> <h2><em>User <?php echo "$_POST[f_name] $_POST[l_name]"; ?> has been deleted from the <?php echo "$table"; ?> table</em></h2> <p><a href="pick_user.php">Delete another person</a></p> <p><a href="../admin_menu.php">Administration Menu</a></p> </body> </html> All the tables are correct and it's making the connect to the database fine it's just not working, did I write it wrong? Code: [Select] function newPm($to, $from, $title, $text){ $q = $db->query("SELECT * FROM ibf_message_topics ORDER BY mt_id DESC"); $lastMsg = $db->fetch_assoc($q); $mid = $lastMsg['mt_id'] + 1; $msgId = $lastMsg['mt_msg_id'] + 1; $db->query("INSERT INTO ibf_message_topics SET mt_id=$mid, mt_msg_id=$msgId, mt_date=". time(). ", mt_title='$title', mt_from_id=$from, mt_to_id=". $to. ", mt_vid_folder='in', mt_read=0, mt_owner_id=$to, mt_user_read=0") or die(mysql_error()); $db->query("INSERT INTO ibf_message_text SET msg_id=$msgId, msg_date=". time() .", msg_post='$text', msg_sent_to_count=1, msg_author_id=$from") or die(mysql_error()); $userq = $db->query("SELECT new_msg FROM ibf_members WHERE id = $to"); $userData = $db->fetch_assoc($userq); $msgCount = $userData['new_msg'] + 1; $db->query("UPDATE ibf_members SET new_msg=$msgCount, show_popup=1 WHERE id = $to") or die(mysql_error()); } Here's how that function is being called in the beginning of the page: Code: [Select] if($action =="banUser"){ $expire = time() + (3600000 * 24 * $_GET['duration']); $q = $db->query("SELECT * FROM ibf_message_topics ORDER BY mt_id DESC"); $lastMsg = $db->fetch_assoc($q); $mid = $lastMsg['mt_id'] + 1; $msgId = $lastMsg['mt_msg_id'] + 1; $title = "Notification"; $duration = $_GET['duration'] ." days"; if($_GET['duration'] == "1"){ $duration = "1 day"; } if($_GET['duration'] == "Forever"){ $duration = "forever"; } $temp = 0; if($expire > time()){ $temp = 1; } $body = "This automated message has been sent to notify you that your account has been banned $duration. To appeal this ban, click on Irc from the menu on the homepage and ask to speak to a moderator. If this ban is temporary, your account will be reinstated automatically at the appropriate time"; newPm($id, 3017, $title, $body); $msgCount = $_GET['msg'] + 1; $db->query("UPDATE ibf_members SET ban_level = $level, tempbanned = $temp, banned = 1, ban_expire='$expire', ban_reason='". $_GET['reason']."', ban_by='". $name."' WHERE id=$id") or die(mysql_error()); ?> <center><b>User banned!</b> (<a href="index.php?code=plyrmgmt">Back to Player Management</a>)</center> I am having an issue with a support ticket program. I have added a feature to this program that allows my staff members to add multiple users to a ticket. The problem I am having because I am new to PHP is how do I email the users when they have been added to the ticket. Below is the code I am using for add user. If someone could look at it and help me figure out how to get this to email the user when they are added to the support ticket that would be great. I have been struggling with this for alot of nights and just cant figure it out. Code: [Select] <?php require "../conf/conn.php"; require "../conf/conf.php"; require "session.php"; ?> <html> <head> <title><?php echo "$c_title - Add User"; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <STYLE type="text/css"> <?php include('../style.php'); ?> </STYLE> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function dele(assigned_user,username,ticket_id,id) { var assigned = document.getElementById('assigned_user').value; if(assigned_user==assigned) { alert("You Can't Delete the user '"+username+"'\nUsername assigned for the ticket '"+ticket_id+"'"); } else { if(confirm('Are you sure to delete?')) window.location.href = "adduser.php?action=delete&user_id="+assigned_user+"&ticket_id="+ticket_id+"&ticid="+id; } } // End --> </script> </head> <body> <?php $ticket_id = $_GET['ticket_id']; if(isset($_GET['action'])) { if($_GET['action']=='delete'){ if(isset($_GET['ticid'])) { $tid = $_GET['ticid']; $query_user ="DELETE FROM support_users WHERE id='$tid'"; $result=mysql_query($query_user); echo $_SESSION['successMsg'] = "<b>User Deleted From the ticket '$ticket_id'</b>"; } } } if(!empty($_POST)) { $date = date('Y-m-d H:i:s'); $puid = $_POST['username']; if($puid!='') { mysql_query("INSERT INTO support_users (id,user_id,ticket_id,assign_date) VALUES ('','$puid','$ticket_id','$date')") or die("<B>Error ".mysql_errno()." :</B> ".mysql_error().""); $_SESSION['successMsg'] = "User Added !"; } } $query_user ="SELECT SU.id,SU.user_id,SU.ticket_id,SU.assign_date,U.user,U.name,U.email FROM support_users AS SU LEFT JOIN users AS U ON SU.user_id=U.id WHERE ticket_id='$ticket_id';"; $result1=mysql_query($query_user); $user_arr = array(); while($userrow1 = mysql_fetch_array($result1)) { $user_arr[] = $userrow1['user_id']; } $result=mysql_query($query_user); $query_user ="SELECT * FROM support WHERE Ticket='$ticket_id';"; $support_result=mysql_query($query_user); $support = mysql_fetch_array($support_result); /* $query_user ="SELECT * FROM users WHERE Ticket='$ticket_id';"; $support_result=mysql_query($query_user); $support = mysql_fetch_array($support_result);*/ if(isset($_SESSION['successMsg'])) { if($_SESSION['successMsg']=="") { echo $_SESSION['successMsg']; $_SESSION['successMsg'] = ""; } } ?> <form method="post" action=""> <table width="400" border="0" align="center" cellspacing="1"> <tr> <td colspan="4" class="submenu"> Ticket ID <?=$ticket_id?> </td> </tr> <tr align="center"> <td colspan="4" class="submenu"> Add Users </td> </tr> <tr align="center"> <td class=""> Select User </td> <td> <select name="username"> <option value="">[--Select User--]</option> <?php $query_user1 ="SELECT * FROM users WHERE level = '3' AND active <> '0' AND validated ='1' order by name"; $result1=mysql_query($query_user1); while($userrow1 = mysql_fetch_array($result1)) { if(!in_array($userrow1["id"],$user_arr)) { $tempuser=$userrow1["user"]; ?> <option value="<?php echo $userrow1["id"];?>"<?php if($row_user[user]==$tempuser){echo " selected ";}?>><?php echo "$userrow1[user] ($userrow1[name] )"; ?></option> <?php } } ?> </select> <input type='submit' value='Add'> </td> </tr> </table> </form> <table width="400" border="0" cellspacing="0" cellpadding="0" align="center" class="border"> <tr> <td> <table width="400" border="0" align="center" cellspacing="1"> <tr align="center"> <td colspan="4" class="submenu"> Assigned Users <input type='hidden' id='assigned_user' name='assigned_user' value="<?=$support['user_id']?>"> </td> </tr> <tr> <td class="descrip">User</td> <td class="descrip">Name</td> <td class="descrip">Email</td> <td class="descrip">Actions</td> </tr> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td class="dat"><a href="#" onClick="sendValue(<?php echo "'".$row[user]."'"; ?>);"><?php echo $row[user]; ?></a><?php if ($row["active"] == 2) echo "<font size=1 color=#FF0000> (Suspended)</font>"; ?></td> <td class="dat"><?php echo $row["name"]; ?></td> <td class="dat"><?php echo $row["email"]; ?></td> <td class="dat"><img src="../images/delete3.gif" /> <a href="javascript:dele('<?=$row["user_id"]?>','<?=$row["user"]?>','<?=$row["ticket_id"]?>','<?=$row["id"]?>');">Delete </a></td> </tr> <?php } ?> <tr align="center"> <td colspan="4" class="submenu"> <?php if ($numpage>1) { pagenav(); } else { echo " "; } ?> </td> </tr> </table> </td> </tr> </table> <br><table align="center"><tr><td><a href="javascript:window.close();">Close Window</a></td></tr></table> </body> </html> Thanks in advance for any help... Hi, Im learning php, but Im a bit confused on this basic problem. I have the following code: <?php include "tax.php"; $price = 95; echo "Price before tax: $price <br>"; echo "Price after tax: "; echo add_tax ($price); ?> Which uses the function below <?php function add_tax ($amount) { $total = $amount * 1.09; return $total; } ?> When I execute the code I can see that it does work, but I do not understand why this part works! echo add_tax ($price); There is no multiplier symbol here, so is the function performed on the ($price) variable simply because of where it is located on this line of code? Thanks I am using PHP 5.5 on windows 8 and I am trying to localize my website to multiple languages while everything is OK on remote host , the gettext function does not work correctly in my localhost. I have implemented the whole tutorial of http://www.sitepoint...applications-1/ step by step but it seems setlocale(LC_ALL, "en_US") fails and I don't know how to correct or install "en_US" in my system. when I use "en-US" instead of "en_US" the sellocale function does not return FALSE but again the gettext function return the original string.
I am attempting to build an online shopping cart, however I have a problem with the Delete /Remove Item function. Add New and Update Item work perfectly fine, just the Remove Item doesn't. It seems to be mirroring the same functionality as Update Item. http://www.tottonc.co.nz to see my problem in action. Any help or solutions would be much appreciated... |