PHP - Stop Executing Required Script
Is there a way or function that stops the execution of a required script but continues to execute the parent script, for example:
if this is a.php <?php echo "<br>Good morning"; // function to stop execution of only this script to appear here echo "<br>Good Afternoon"; ?> and then this is b.php <?php require("a.php'); echo "<br>Good Evening"; ?> So if the file b.php is called it is supposed to display: Good morning Good evening So it has to skip "Good afternoon" because of the anonymous function which I need Similar TutorialsI'm tired and want to sleep so my mistakes are getting lots now. Anybody awake that can explain my problem with the code below. <? function directoryToArray($directory, $recursive) { $array_items = array(); $i = "0"; if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle)) && $i < "3") { if ($file != "." && $file != "..") { if (is_dir($directory. "/" . $file)) { if($recursive) { $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive)); } } else { $file = $directory . "/" . $file; $array_items[] = preg_replace("/\/\//si", "/", $file); $i++; } } } closedir($handle); } natsort($array_items); return array_reverse($array_items); } $data = directoryToArray('images/screenshot/', TRUE); print_r($data); ?> What I want is for the while loop to stop after 4 hits and exit and give me the return results. But now it continue until readdir end. Hello, PowerShell script stored locally can never be executed after I click on button: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Testing PowerShell</title> </head> <body> <?php // If there was no submit variable passed to the script (i.e. user has visited the page without clicking submit), display the form: if(!isset($_POST["submit"])) { ?> <form name="testForm" id="testForm" action="get-process.php" method="post" /> Your name: <input type="text" name="username" id="username" maxlength="20" /><br /> <input type="submit" name="submit" id="submit" value="Do stuff NowNew" /> </form> <?php } // Else if submit was pressed, check if all of the required variables have a value: elseif((isset($_POST["submit"])) && (!empty($_POST["username"]))) { // Display the alert box echo '<script>alert("Welcome to Geeks for Geeks")</script>'; // Get the variables submitted by POST in order to pass them to the PowerShell script: $username = $_POST["username"]; // Best practice tip: We run out POST data through a custom regex function to clean any unwanted characters, e.g.: // $username = cleanData($_POST["username"]); $psPath = "C:\\Windows\\SysWOW64\WindowsPowerShell\\v1.0\\powershell.exe"; $psDIR = "C:\\TestNew\\"; $psScript = "pscripta.ps1"; $runScript = $psDIR. $psScript; $runCMD = $psPath." ".$runScript." 2>&1"; echo "\$psPath $psPath <br>"; echo "\$psDIR $psDIR <br>"; echo "\$psScript $psScript <br>"; echo "\$runScript $runScript <br>"; echo "\$runCMD $runCMD <br>"; exec( $runCMD,$out,$ret); echo "<pre>"; print_r($out); print_r($ret); echo "</pre>"; } // Else the user hit submit without all required fields being filled out: else { echo "Sorry, you did not complete all required fields. Please go back and try again."; } ?> </body> </html>
Thank you for your help! Hey there, I recently started working on a PHP calculator, I tryed testing it out and the script is not executing... *NOTE* I found the error, I forgot to assign values to the options, all is good now Code: [Select] <?php /* Script Created by: Far Cry Started: August 20th, 2010 10:51 PM PST Completed */ $title = "Calculator"; $form = "<form action='calculator.php' method='POST'> <table> <tr> <td><input name='firstnumber' type='text'></td> </tr> <tr> <td><input name='secondnumber' type='text'></td> </tr> <tr> <td><select name='operation'> <option name='multiply'>*</option> </select></td> </tr> <tr> <td><input name='submitbtn' type='submit' value='Calculate!'></td> </tr> </table> </form>"; if ($_POST['submitbtn']){ $first = ($_POST['firstnumber']); $last = ($_POST['secondnumber']); $operation = ($_POST['operation']); } if ($operation == 'multiply'){ echo"The answer is " . $first * $last . $form; } echo $form; ?> Thanks in advance. In my php web program I'm trying to execute a bash shell script on the web server passing to it some parameters gathered within the program. Ideally I wouldl ike to run this script as another user. However, I get only a return code of "1" and no other error messages that I can see. I tried using system and passthru as well and I'm sure the script is executable by anyone. I've also tried the sticky bit on the target shell script. Can someone/anyone please provide some gotcha pointers about doing this? As can be expected, after playing with this for a week now I'm extremely frustrated and nearly exhausted my resources (except for this forum). Ideas/suggestions please? Thanks I am a bit desperate about this problem that I have been trying to solve for several days now. I'm trying to run a Python script from the exec() function in php. The script is called but the print job is never executed. This process has been running for several years and for no clear reason it suddenly stopped working. On my home computer, it works without any problem. In my virtual machine, nothing happens. The print() functions present in the script are well displayed by the return value received by php but the printing is not executed. The virtual machine is a test environment, in production it is also an physical machine. PHP <?php exec("py C:\xampp\htdocs\test\test.py", $out, $res); echo "<pre>"; print_r($out); echo "</pre>"; echo "<pre>"; print_r($res); echo "</pre>"; ?>
if __name__ == "__main__": try: filename = "C:/xampp/htdocs/test/test.pdf" win32api.ShellExecute(0, "print", filename, None, ".", 0) except Exception as e: print(f "An error occured during print_pdf : {e}")
The two environments are approximately the same: I'd like to point out that running the script directly from the CLI works on both machines. On the problematic machine, exec() only returns the result of print(..) I already opened a thread a few months ago about this problem but received no response.
Thank you in advance. Hey Friends,
I am new to this forum, and does not know anything about programming. And I require very small help from the experts of forum. I have downloaded free image hosting script from web & it is not working fine, it gets stuck at basic.php (one of the file in script). I am sharing the script here also sharing the website. My website : bsm1313.5gbfree.com
Note : I have uploaded a rar file. Kindly change extension to .rar from .php. as it was not allowing me to upload the rar file.
Any kind of help is highly highly appreciated. Thanks a ton in advance.
Attached Files
easyimagehoster_1.32.php 35.46KB
5 downloads Hello, Im trying to create a simple voting script for my site, i been trying different things but cannot get it too function properly. The idea is you click the 'thumbs up' image to add 1 to the 'likes' value and thumbs down to add '1' to the dislikes. Sound simple but its giving me headaches. Would really appreciate it if someone could take a quick look at my script. The table is called 'youtube_rating' (because thats the look i was going for) and in the table is 4 columns, id (aut0_increment), liked (counts liked votes), disliked (counts dislikes) and item_num which is the id for teh product the rating is for. Code: [Select] <? if ( $row['rating'] == 'YES' ) { require ("../rating/voting/dbcon.php"); $result1 = mysql_query("select * from youtube_rating WHERE item_num='".$page_id."'"); $row = mysql_fetch_array($result1); $dislike = $row['dislike']; $like = $row['liked']; if (isset($_POST['submitted'])) { require_once ("../database/functions.php"); $userip = $_SERVER['REMOTE_ADDR']; $id = safe($_POST['id']); $vote = '1'; // check if user already voted $result = mysql_query("SELECT * FROM youtube_ip WHERE userip='$userip' AND item_num ='".$id."'"); $num = mysql_num_rows($result); // if already voted show error if (isset($_POST['submitted']) && ($num > 0)) { echo '<div class="alreadyvoted">You have already voted!</div>'; } // add like if (isset($_POST['submitted']) && ($_POST['submitted'] == 'like') && ($num == 0)) { // add 1 to value $liked_value = mysql_query("SELECT liked FROM youtube_ip WHERE item_num ='".$id."'"); $liked_total = $liked_value + $vote; $query = "update youtube_rating set liked = '".$liked_total."' where item_num ='".$id."'"; echo '<div class="ilikethis">You like this!</div>'; } // add dislike if (isset($_POST['submitted']) && ($_POST['submitted'] == 'dislike') && ($num == 0)) { // add 1 to value $dislike_value = mysql_query("SELECT dislike FROM youtube_ip WHERE item_num ='".$id."'"); $dislike_total = $dislike_value + $vote; $query = "update youtube_rating set dislike = '".$dislike_total."' where item_num ='".$id."'"; echo '<div class="idislikethis">You Dislike this!</div>'; } // log ip // if (isset($_POST['submitted']) && ($num == 0)) // { // mysql_query ("insert into youtube_ip (userip, item_num) values ('".$userip."', '".$id."')"); // } } ?> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="48%" align="center"> <form action="" method="post"> <input name="id" type="hidden" value="<? echo $page_id ?>" /> <input name="submitted" type="hidden" value="like" /> <button type="submit" class="like_button" name="like" id="like" > <img src="../rating/voting/pixel-vfl73.gif" alt=""> <span><?php echo $like?></span> </button> </form> </td> <td width="52%"> <form action="" method="post"> <input name="id" type="hidden" value="<? echo $page_id ?>" /> <input name="submitted" type="hidden" value="dislike" /> <button type="submit" class="dislike_button" name="dislike" id="dislike" > <img src="../rating/voting/pixel-vfl73.gif" alt=""> <span><? echo $dislike?></span> </button> </form> </td> </tr> </table> <? } ?> The problem is the vote does not add up or update the database, also it doesn't seem to be checking if the user has voted or not, it just attempts (but fails) to add a vote no matter what Thanks for any help. i want a script which should be easily integrated with the website and should fully customizable like cutephp.. the problem with cutephp is that it can't handle large data since it stores all the news articles in one .txt file on the server.. as the number of articles grow.. the size of .txt file increases and it becomes impossible for the server to handle the script.. i want a script which should be easily integrated into the website and should have the following features. - article categories - admin panel to add news - should use mySQL to store articles or it should create .htm files for articles.. i hope you get the point.. by the way if i want to write my own script.. what is the easiest way to write a script which should have categories, show news on webpages, have admin password protected add news area.. should create seperate files on the server or use mysql..nothing complicated.. simple news posting script.. Hello everyone. I recently coded a Minecraft Voting for Diamonds script. Basically, you enter your username, you vote on the sites, then click "Get Reward". The reward then goes through a RCON script, and rewards the user with their diamonds in-game. the full script works fine, and I am happy with it, but there is one small problem; and that is users being able to abuse the system. If they wanted to, they could just refresh the page, and click Get Rewarded again, and again. I want to make something like this: It has a countdown on the link, which is started upon click, and then the link re-activates when the timer is done. My script already has "disabled=..." tags, so you have to click all links, this way would make sure a user cannot click the link until the timer is done. I'm pretty new to PHP, and please forgive me if it is not 100% PHP, but this place seemed extremely helpful. I am also pretty new to PHP, so make it for dummies xD Thanks everyone! After spending 3 days on internet and struggling with so many different forums , i have found this forum where i believe i will get the solution for my problem. Friends, I am zero in PHP, but still i have managed to do something to fulfill my requirement. I am stuck with one thing now..So i need help on.... I am using one html+php form to submit database into mysql. I created a display of that table through php script on a webpage. Now i want a datepicker option on that displayed page by which i should able to select the date range and display the data of that date range from my mysql table. And then take a export of data displayed of selected date range in excel. This displayed page is login protected, so i want after login the next thing comes in should show a sate selection option which should be fromdate to to date , and then records should displayed from the database and i can take export of those displayed results in excel file. The code i am using on this page is below which do not have any thing included for excel export and datepicker script, I am pasting the code here and request you to please include the required code in it as required. Thanks In advance <?php //database connections $db_host = 'localhost'; $db_user = '***********'; $db_pwd = '*************'; $database = 'qserves1_uksurvey'; $table = 'forms'; $file = 'export'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$table} ORDER BY date desc"); if (!$result) { die("Query to show fields from table failed"); } $num_rows = mysql_num_rows($result); $fields_num = mysql_num_fields($result); echo "$num_rows"; echo "<h1></h1>"; echo "<table border='1'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> </body></html> HI,
I was trying do add a function to my script to stop each 10 seconds, using max_execution_time. Apparently is not working and most probably from the php.ini file, that I can t change because I want for the others script to run normally.
How can I write a function inside a php file to stop everything after 10 seconds. Or how can I make a script to stop after 100 processed items and start again after 30 seconds. I need to stop this file somehow. $processedItems++; I have a script that is mostly written in PHP with a little JS Ajax for updating. It won't stop. There are some cookies and a couple of simple sessions. I've created a 'destroy' page which destroys the session and deletes the cookies but the program still won't stop. I've deleted the files from the server - the script doesn't exist - and yet if I upload the script after several minutes it updates where it left off. I simply can't figure out how to stop of otherwise 'destroy' this script. What I've tried: A redirect page that includes the following: unset($_SESSION['FOR-EACH-SESSION']); setcookie("FOR-EACH-COOKIE", "", time() - 42000); session_unset(); session_destroy(); die; exit; Deleting the script from the server does not stop the script. Yes, if I go to the script after the files have been deleted I receive a 404 error naturally. Yet, when I upload the files again the script still starts off where it left off, it has sessions from the server that still exist. I don't get. Is there anything else I can do? i have a script that wrote which updates fields in a mysql database with millions of rows. it just uses a while loop for each row. now the problem is that i forgot to add something to the script, but i already visited the .php file in my browser. i closed the browser and when i refresh the database it still seems to be running even though i closed the browser the script was running on.... is this because the script is still cached in the memory or what? how can i stop it? I have the following query where $userid is about 100,000 userids separated by commas. Code: [Select] <? $getpostid=mysql_query("SELECT DISTINCT post.username,post.threadid,thread.threadid,thread.forumid from post,thread WHERE post.username='$username' AND post.threadid=thread.threadid AND post.userid IN ($userid) AND thread.forumid IN ($forumids)") or die (mysql_error()); ?>can i just print all the usernames from above result separated by ';' without looping it multiple times? Could someone help me out how to do above in an efficient manner? I am trying to use some php code inside of an html document and it does not work. I have a script.php file that executes perfectly when I try and use it. Here is the code I am currently using: Code: [Select] <?php echo "<title>"; echo "the Homepage!"; echo "</title>"; ?> Any suggestions would be great. I am playing around with php but the script doesnt execute to the last point and with no error...
What i am trying to do is checking the input of the user and comparing it what is in db and then applying conditions. So i have 2 files. update.php and home.php. home.php is my html form page and i included 'update.php' in it In my update.php, i have these codes
<?php error_reporting(E_ALL); include_once('database.php'); if(isset($_POST['submit'])) { $q = $_GET['q']; $next = $q + 1; if($q == 26) { echo '<h2>You have Completed the Exam.Congrats!!</h2>'; } elseif($q <= 25){ $sql = "SELECT * FROM Students WHERE Email=?"; $stmt = $conn->prepare($sql); $stmt->bind_param('s', $_SESSION['login']); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $Mark = $row['Mark']; $Correct = $Mark + 1; $Fail = $Mark + 0; $sqlb = "SELECT * FROM Answers WHERE qid = ?"; $stmtb = $conn->prepare($sqlb); $stmtb->bind_param('s', $q); $stmtb->execute(); $resultb = $stmtb->get_result(); $rowb = $resultb->fetch_assoc(); $Answer = $rowb['Answer']; $Pick = $_POST['ans']; if($Pick == $Answer) { $sqld = "UPDATE Students SET Mark=? WHERE Email = ?"; $stmtd = $conn->prepare($sqld); $stmtd->bind_param('ss', $Correct,$_SESSION['login']); $stmtd->execute(); $resultd = $stmtd->get_result(); echo "correct" ; } } else { echo 'Ate'; echo "<script type='text/javascript'>document.location.href='home.php?q='.$next.';</script>"; } }//post submit ?> The else statement doesnt run. so it keeps reloading the same page. Also i want to ask why i keep getting the value of 2 for my $Correct variable stored on the database into column Mark for a single correct question instead of 1. What could be wrong? Lastly, i dont want the script to run if the browser is edited by the user by changing the value of $q from the browser, because i am using get method, is there a way to do that. Please be nice with your comments. Thanks in advance.!!! OK, so I have the following file that has database functions: <?php function dbDelete($param){ $conDelete = mysql_connect($url,'username','password',true); mysql_select_db('my_db',$conDelete); mysql_query($param,$conDelete); mysql_close(); if(isset($conDelete)){ mysql_close($conDelete); } } ?> I include the above file in a session handling file. But for some reason the new file can't call the above function as follows: <?php include_once 'the above stated file'; function timeOut(){ dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'"); $_SESSION = array(); setcookie(session_name(),'',time()-4200); session_destroy(); } //CHECK FOR TIMEOUT REQUEST switch($_GET['xyz']){ case 'timeout': timeOut(); header("Location: /?xyz=timedout"); break; case 'logout': timeOut(); header("Location: /?xyz=loggedout"); break; case 'refresh': dbUpdate("UPDATE acctussessi SET acctussessi_time = ".time()." WHERE acctussessi_unid ='".$token."'"); break; } ?> dbDelete isn't being called inside of the TimeOut() function. The only way it works is by doing the following: <?php function timeOut(){ $_SESSION = array(); setcookie(session_name(),'',time()-4200); session_destroy(); } //CHECK FOR TIMEOUT REQUEST switch($_GET['xyz']){ case 'timeout': dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'"); timeOut(); header("Location: /?xyz=timedout"); break; case 'logout': dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'"); timeOut(); header("Location: /?xyz=loggedout"); break; case 'refresh': dbUpdate("UPDATE acctussessi SET acctussessi_time = ".time()." WHERE acctussessi_unid ='".$token."'"); break; } ?> But this is annoying and repetitive. What is going on? Thanks in advance. Hey guys! My current employer contracted someone to create a script for him. (The script itself is to create a serial number for a piece of software) It's just a PHP script that executes a file and retrieves its output. Now I've never worked with exec() in PHP, and I don't have a reliable environment to test it in. I compiled apache2 and php 5.0.4 and set them to run on a Macintosh (10.3.9) in the office, but I'm sure I've missed some crucial setup stage (mainly, I'm missing php.ini. I did a php -i | grep php.ini to find it, and it says it is in /etc/, but when I look in my PHP/etc folder, only pear.conf is there!). PHP and apache both appear to be working fine, though. When I try and run the PHP script that executes the .ELF file, I get a blank page. Is this because I'm running it in OS X? should I be running it in Linux? Also, I don't know how to Enable exec() on my server, or to see if it's enabled. Basically, I just need someone to walk me through the basics of this. The script and executable SHOULD work fine because the contractor got it working fine. Below is the script, and attached is the executable. Thanks! :3 <?php /* inUID = 456890 inSerialNumUID = 123456 inMachineID_s = &6dA-8P@K-Xsq */ $p1 = "456890"; $p2 = "123456"; $p3 = "\&6dA-8P@K-Xsq"; exec("./create_activation_code.elf $p1 $p2 $p3", $output); foreach ($output as $output_str) { echo $output_str."<br>"; } ?> Looking to INSERT a row in a data table and keeping the User on the current page. Will it work like what I have below, or do I need to send it to its own page then return the User back to where he started? What I have below isn't inserting a row. No errors showing. function bookmark_add () { if (isset($_POST['submit'])) { include("/home2/csi/public_html/resources/con.php"); $query = "INSERT INTO a_player_bookmark (bookmark) VALUES ('1')"; $results = mysqli_query($con,$query); echo mysqli_error($con); } $output = '<form name="bookmark_add" method="post" action="" class="bookmark-plus">'; $output .= '<span><input type="submit" name="Bookmark"></span>'; $output .= '</form>'; return $output; }
Hi, In some cases I need to execute a default query , so I am storing the SELECT statement in a variable like this and executing it: Code: [Select] $default_query="SELECT * from user where userid='$userid'"; $user_query=mysql_query($default_query); The above code returns an empty results. But if I execute it without the variable it works fine. Code: [Select] $user_query=mysql_query("SELECT * from user where userid='$userid'"); Am I syntatically wrong somewhere? |