PHP - Running Scripts At An Interval
I am coding a browser game in php/mysql. the economy code needs to run at a regular interval. How can I get my code to run say, every 6/12/24 minutes? I heard of something called a cron job, but im not sure if it is going to be what I need.
Similar TutorialsSo I have a php script in public_html on my apache server, and it runs a global economy code for my browser game. If I open firefox and go to: http://localhost/Economy.php it runs the code, and it changes all the values in the database properly. How do I get that to run automatically, say every 6 minutes? I have windows so no cron jobs. I went to task scheduler and created a task which I thought would work, and it lists the task as running. But it gives me an error. Event Views: Code: [Select] Log Name: Microsoft-Windows-TaskScheduler/Operational Source: Microsoft-Windows-TaskScheduler Date: 9/28/2011 5:02:37 PM Event ID: 101 Task Category: Task Start Failed Level: Error Keywords: (1) User: SYSTEM Computer: Matt-PC Description: Task Scheduler failed to start "\Economy" task for user "Matt-PC\Matt". Additional Data: Error Value: 2147750687.Event Xml: Code: [Select] <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" /> <EventID>101</EventID> <Version>0</Version> <Level>2</Level> <Task>101</Task> <Opcode>101</Opcode> <Keywords>0x8000000000000001</Keywords> <TimeCreated SystemTime="2011-09-28T22:02:37.967669800Z" /> <EventRecordID>18</EventRecordID> <Correlation /> <Execution ProcessID="1012" ThreadID="1484" /> <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel> <Computer>Matt-PC</Computer> <Security UserID="S-1-5-18" /> </System> <EventData Name="TaskStartFailedEvent"> <Data Name="TaskName">\Economy</Data> <Data Name="UserContext">Matt-PC\Matt</Data> <Data Name="ResultCode">2147750687</Data> </EventData> </Event> EDITed for code tags This may be a stupid question so forgive me if it sounds like a dumb question. I have my own server set up and I was wondering if it was at all possible to have a script running that is hosted on my server, while my PC is off or possibly just without having to load it within my web browser. I have a few scripts I wish to run forever without lagging my old PC. Is there a way to do this? Thanks. P.S All the scripts will be using the file_get_contents function to open HTTP streams, and a few explode functions here and there. Hi Guys, I'm having some trouble running PHP scripts. I have two forms, each of which redirects to a PHP script (each PHP script is different, but essentially both have the same problem) as an action. The code is below. I'm hosted at Bluehost, which runs PHP on their servers so I know the tech is compatible. Thanks! Cheers! <html> <script type="text/php">include('newform.php');</script> <head> <title>TradeSquared></title> <p align="center">Trade Squared</p> </head> <body> <br> <br> <div align="center"> Create a new Listing: <form action="newform.php" method="get" name="newform"> Type:<select name="type"> <option value="book">Book</option> <option value="apt">Apartment</option> <option value="item">Class Items</option> </select> <input type="submit" value="Submit"/> </form> <br> Search current Listings: <form action="searchform.php" method="get" name="searchform"> Type:<select name="type"> <option value="book">Book</option> <option value="apt">Apartment</option> <option value="item">Class Items</option> </select> <input type="submit" value="Submit"/> </form> </div> </body> </html> This is the PHP code on which action redirects to <?php $type = $_GET=["type"]; if($type=="book") header("location:addbooklisting.html"); else if($type == "apt") header("location:aptform"); else header("location:itemform"); ?> Second page <html> <head> <title>Create New Book Listing</title> <p align="center"> <b>Create a New Book Listing</b> </p> </head> <body> <div align="center"> <br><br> <form name="addlisting" method="get" action="bookvalidation.php"> <table width="100" border="0" align="center"> <tr> <td align="center">Title </td> </tr> <tr> <td align="center"><input type="text" name="title"/> </td> </tr> <tr><td><p/></td></tr> <tr> <td align="center">Price </td> </tr> <tr> <td align="center">$<input type="text" name="dollars" size="3"/>.<input type="text" name="cents" size="2"/> </td> </tr> <tr><td><br></td></tr> <tr> <td align="center">ISBN</td> </tr> <tr> <td align="center"><input type="text" name="isbn"/></td> </tr> <tr><td><br></td></tr> <tr> <td align="center">Condition </td> </tr> <tr> <td align="center"><select name="cond"> <option name="used">Used</option> <option name="new">New</option> </select> </td> </tr> <tr><td><br></td></tr> <tr> <td align="center">Commentaries </td> </tr> <tr> <td align="center"><textarea rows="5" cols="30" name="comm"></textarea></td> </tr> <tr><td><br></td></tr> <tr> <td align="center"><input type="submit" value="Add Listing"/></td> </tr> </table> </form> </div> </body> </html> PHP code for second page <html> <head>Results</head> <body> The Following Occurred: <?php $title = $_GET["title"]; $dollar = $_GET["dollars"]; $cents = $_GET["cents"]; $price = $dollar.".".$cents $isbn = $_GET["isbn"]; $cond = $_GET["cond"]; $decide; $comments = $_GET["comm"]; for($i=0; $i<=12; i++) { if(ctype_digit($isbn)) $decide = true; else $decide = false; } if( !(($dollar && $cents)==int) ) echo "Price must be in numbers."; else if($decide == false || strlen($isbn)!=13) echo "ISBN contains 13 characters and must be numbers only" else { $db=mysql_connect("localhost","username","pass!"); mysql_select_db("db_dataabse",$db); $dbsucces=mysql_query("INSERT INTO BookListings (Title, ISBN, Price, Condition, Comments) VALUES ('$title', '$isbn', '$price', '$cond', '$comments')"); if($dbsuccess==true) echo "Posting was succesful"; else echo"Unsuccesful log."; } ?> </body> </html> Hi all. In my database, i have a column recurring which is derived from a multiple option form field with values: Weekly, Bi-Monthly, Monthly, Quarterly, Half Yearly and Yearly. I want to have as next due the current date plus the recurring value. eg current date = 2014-11-24 recurring = monthly next due = current date + recurring (in the next due will be 2014-12-24) so i did: $stmt = $pdo->query("SELECT recurring, due_date FROM $table"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $recur = $row['recurring']; $date_due = $row['due_date']; } $weekly = "Weekly"; $bi_monthly = "Bi-Monthly"; $monthly = "Monthly"; $quarterly = "Quarterly"; $half_yearly = "Half Yearly"; $yearly = "Yearly"; if(strcmp($recur, $weekly) == 0){ $recurs = "7 DAY"; }elseif(strcmp($recur, $bi_monthly) == 0){ $recurs = "14 DAY"; }elseif(strcmp($recur, $monthly) == 0){ $recurs = "1 MONTH"; }elseif(strcmp($recur, $quarterly) == 0){ $recurs = "3 MONTH"; }elseif(strcmp($recur, $half_yearly) == 0){ $recurs = "6 MONTH"; }elseif(strcmp($recur, $yearly) == 0){ $recurs = "1 YEAR"; } $stmt = $pdo->query("SELECT ADDDATE('$date_due', INTERVAL $recurs) as nex_due FROM $table"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $nex_due = $row['nex_due']; $stmt = $pdo->prepare("SELECT * FROM $table ORDER BY trans_id DESC"); $stmt->execute(); $num_rows = $stmt->rowCount(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['trans_ref']; echo "</td><td>"; echo $row['acct_num']; echo "</td><td>"; echo ucwords($row['payee']); echo "</td><td>"; echo ucwords($row['company']); echo "</td><td>"; echo $row['acct_no']; echo "</td><td>"; echo number_format($row['amt'],2); echo "</td><td>"; echo $row['purpose']; echo "</td><td>"; echo $row['recurring']; echo "</td><td>"; echo $row['due_date']; echo "</td><td>"; echo $nex_due; echo "</td><td>"; echo "<strong>".$row['status']."</strong>"; echo "</td><td>"; echo "<strong>".$row['pay_status']."</strong>"; echo "</td><td>"; } The problem is that it's giving me as next due the value of the first row even when the recurring is different! Hey, I'm not that familiar with PHP so maybe what I'm asking for is not even possible. I plan to establish a webserver that is connected to a RS232 device. I don't have any problems accessing the RS232 interface with a PHP-script, it's all working fine. Now I want the incoming data from the device being display on the servers webpage almost in realtime. When I say almost I mean that the client who is logged on to the website should be able to define the update rate of the incoming data. So here comes the problem, I need something like the java script setinterval() function that is working on the server-side and repeats the data request to the device in an infinite loop with the given time interval. I don't want to refresh the whole page as I will have to update about 20 sets of data within seconds! I found this code: http://phpclasses.chimit.nl/package/5544-PHP-Call-a-function-after-a-period-of-time.html it looks pretty promissing but I just can't make it working... As I said I'm a PHP-noob so I just put the code below on the start of my own code and provided the Timer.class.php file in my project folder. Could anyone explain how I could make the test function repeating endlessly on a 1sec basis using this code so I would get a screen full of "called"? So far I only get two "called" :-) Thanks! declare(ticks=100); function test () { print "<br>called"; } require_once 'Timers.class.php'; setTimeout('test', 110000000); setInterval('test', 10000000); Does any one know how to run PHP script automatically at specific time interval in my local machine. I am using Windows 7. What about using the Task scheduler ? Please write to me in details how to give the path of the php page in Task Scheduler. 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++; This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331688.0 guys, please help i have table with datas like speed of vehicle, position e.t.c from morning 8 a.m. to 8 p.m. I need to get these details, but after every 15 minutes i.e. after selecting datas at 8 a.m. it shd select datas @ 8.15 a.m. then 8.30 a.m. hw can i write a mysql query for this ? or a PHP approach is appreciated I've been researching online resources and seen a lot of code and functions for calculating an interval or difference between two date/time figures. What I'm trying to do is somewhat in reverse... I want to establish an interval to determine a past date/time to be used in a MySQL Query but just can't figure the critical part.
// STEP #1 = DEFINE THE DESIRED DATE/TIME DIFFERENCE INTERVAL DESIRED FOR QUERIES $timeinterval = '60'; // Interval is in MINUTES and can be changed as desired // STEP #2 = GET THE CURRENT LOCAL SERVER DATE/TIME // as YYYY-MM-DD HH:MN:SE $serverdatetime = date('Y-m-d H:i:s'); // My local Server Date & time // STEP #3 = CALCULATE THE ***PAST** (OLDER) DATE/TIME LIMIT BASED ON $timeinterval (Minutes) // as YYY-MM-DD HH:MN:SE $pastdatetime = [stuckinarut here] <- 60 MINUTES prior to current Server Date/Time // STEP #4 = MySQL QUERY (`submitted` column is auto-timestampped on record insertions) $sql="[columnsblahblah] FROM mydb WHERE `submitted` >= $pastdatetime";In a Perfect World, the MySQL Query would yield ONLY records with a `submitted` DATE/TIME equal to 60 Minutes (or less) PRIOR TO from the Current Server Time. Any assistance is appreciated! Thanks. -FreakingOUT I know this involves MySQL, but it's mostly PHP, so I figured it should go here, forgive me if I posted in the wrong section, though. Anyway! Let's get down to it. I'd like to combine these two scripts (below). I want the questionnaire script to be a signup requirement in the signup script, and I want it to log the questionnaire into my MySQL database as usual, then prompt the user with a successful sign up. I'm still really new to PHP and I'm just testing to see if this'll work. How would I go about doing this? Thanks a LOT guys. Questionnai <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Questionnaire'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; exit(); } // Show the navigation menu require_once('navmenu.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // If this user has never answered the questionnaire, insert empty responses into the database $query = "SELECT * FROM mismatch_response WHERE user_id = '" . $_SESSION['user_id'] . "'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 0) { // First grab the list of topic IDs from the topic table $query = "SELECT topic_id FROM mismatch_topic ORDER BY category_id, topic_id"; $data = mysqli_query($dbc, $query); $topicIDs = array(); while ($row = mysqli_fetch_array($data)) { array_push($topicIDs, $row['topic_id']); } // Insert empty response rows into the response table, one per topic foreach ($topicIDs as $topic_id) { $query = "INSERT INTO mismatch_response (user_id, topic_id) VALUES ('" . $_SESSION['user_id']. "', '$topic_id')"; mysqli_query($dbc, $query); } } // If the questionnaire form has been submitted, write the form responses to the database if (isset($_POST['submit'])) { // Write the questionnaire response rows to the response table foreach ($_POST as $response_id => $response) { $query = "UPDATE mismatch_response SET response = '$response' WHERE response_id = '$response_id'"; mysqli_query($dbc, $query); } echo '<p>Your responses have been saved.</p>'; } // Grab the response data from the database to generate the form $query = "SELECT mr.response_id, mr.topic_id, mr.response, " . "mt.name AS topic_name, mc.name AS category_name " . "FROM mismatch_response AS mr " . "INNER JOIN mismatch_topic AS mt USING (topic_id) " . "INNER JOIN mismatch_category AS mc USING (category_id) " . "WHERE mr.user_id = '". $_SESSION['user_id'] . "'"; $data = mysqli_query ($dbc, $query); $responses = array(); while ($row = mysqli_fetch_array($data)) { array_push($responses, $row); } mysqli_close($dbc); // Generate the questionnaire form by looping through the response array echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">'; echo '<p>How do you feel about each topic?</p>'; $category = $responses[0]['category_name']; echo '<fieldset><legend>' . $responses[0]['category_name'] . '</legend>'; foreach ($responses as $response) { // Only start a new fieldset if the category has changed if ($category != $response['category_name']) { $category = $response['category_name']; echo '</fieldset><fieldset><legend>' . $response['category_name'] . '</legend>'; } // Display the topic form field echo '<label ' . ($response['response'] == NULL ? 'class="error"' : '') . ' for="' . $response['response_id'] . '">' . $response['topic_name'] . ':</label>'; echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="1" ' . ($response['response'] == 1 ? 'checked="checked"' : '') . ' />Love '; echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="2" ' . ($response['response'] == 2 ? 'checked="checked"' : '') . ' />Hate<br />'; } echo '</fieldset>'; echo '<input type="submit" value="Save Questionnaire" name="submit" />'; echo '</form>'; // Insert the page footer require_once('footer.php'); ?> Signup: <?php // Insert the page header $page_title = 'Sign Up'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { // Grab the profile data from the POST $username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1'])); $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2'])); if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) { // Make sure someone isn't already registered using this username $query = "SELECT * FROM mismatch_user WHERE username = '$username'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 0) { // The username is unique, so insert the data into the database $query = "INSERT INTO mismatch_user (username, password, join_date) VALUES ('$username', SHA('$password1'), NOW())"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>'; mysqli_close($dbc); exit(); } else { // An account already exists for this username, so display an error message echo '<p class="error">An account already exists for this username. Please use a different address.</p>'; $username = ""; } } else { echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>'; } } mysqli_close($dbc); ?> <p>Please enter your username and desired password to sign up to Mismatch.</p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Registration Info</legend> <label for="username">Username:</label> <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br /> <label for="password1">Password:</label> <input type="password" id="password1" name="password1" /><br /> <label for="password2">Password (retype):</label> <input type="password" id="password2" name="password2" /><br /> </fieldset> <input type="submit" value="Sign Up" name="submit" /> </form> <?php // Insert the page footer require_once('footer.php'); ?> And here are the pastebins in case you prefer those: http://pastebin.com/pTXGSMT9 - Questionnaire http://pastebin.com/28jZhYyY - Signup Thanks! why is it that when i try to submit it tells me add a picture but i did added Code: [Select] <?php //decarling some variables $msg = ""; //begin if if($_POST['submitbtn']){ $author = mysql_real_escape_string($_POST['author']); $date = mysql_real_escape_string($_POST['date']); $picture = $_FILES['picture']['name']; $ext = strtolower(substr($name,strpos($name,'.')+1)); $size = $_FILES['picture']['size']; $maxsize = 200000; $type = $_FILES['picture']['type']; $tmp = $_FILES['picture']['tmp_name']; $review = mysql_real_escape_string($_POST['review']); $move = "uploads/"; if(isset($author) && !empty($author)){ if(isset($date) && !empty($date)){ if(isset($picture) && !empty($picture)){ if($size <= $maxsize){ if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){ if(move_uploaded_file($tmp,$move.$name)){ if(isset($review) && !empty($review)){ $query = mysql_query(" INSERT INTO reviews ('',author,date,picture,review) VALUES ('',$author,$date,$picture,$review)"); }else $msg = "Please write a review"; }else $msg = "Error has happen try again later"; }else $msg = "Image must be a jpg, jpeg, or png"; }else $msg = "You must select a smaller image size"; }else $msg = "Select a picture"; }else $msg = "Please enter a date"; }else $msg = "Please fill in the Authors name"; } //ending the if here ?> Hello. This is sort of an embarrassing question, but I guess it is something I've never done before. In the past, whenever I had a command button on a webpage, I used a form and when the user clicked on the button I also just reloaded the same PHP script to process the $_POST request. (I realize that a lot of people have the form on the 1st page/script, and the have a 2nd page/script to handle the form request, but that always seemed like overkill to me.)
With my new problem, I have one web page that has a subscription offer on it, with just some bullet points of why the user should be interested, and then a "Get this offer" button. When the user chooses this button, what should happen behind the scenes is that I add the ProductID to the shopping cart - which is a database record - and then I redirect to my checkout page.
While typing up this thread, maybe I don't have an issue after all? 😕 I guess what i could do on trial-offer.php is have a form surrounding my "Get this offer" button, and when the user submits the form, my trial-offer.php script could add a shopping_cart record in the database and then I could use a re-direct to go to my checkout.php script, right?
But to my original question, if I did want to pass the ProductID to my "Checkout.php script, what would be the best way to do that? Could I still use a $_POST and but just send the form to my other script (i.e. checkout.php)? (This is the part I was unsure of above!) Or would I be forced to use a $_GET which i don't really like or trust?
well I was wanting to make scripts to put on my site and then only let a few people use the site by the ip address, what would be the best way to allow only certain people to use the script on the site, based on the ip? Thanks Hi, I'm trying to make my game navigation that involves switching div images to navigate in the game world. It is browser based. The first script, the user clicks on the world map to go to "Teardrop Ocean". The second script lets the user press the "further" button or "back" button to navigate within "Teardrop Ocean". My problem is I'm trying to combine the image map navigation with the "further" and "back" navigation. The problem is, I don't know if it's possible since the first world map script involves javascript. Here is the code, any help greatly appreciated Thanks. Derek This is the code that uses javascript to process a hidden form to use php to output. This is our "world map" link, that should load the "teardrop ocean" image inside the div, which it doesn't do yet here. Code: [Select] <?php $zone=''; if(isset($_POST['checker']) && $_POST['checker'] == 'checked') { echo "it worked !"; $zone="<img src='teardrop.jpg'/>"; } if(isset($_POST['back'])) { $zone=''; } ?> <!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> <form action="aradia.php" method="post" name="mapform" id="mapform"> <input type="hidden" name="checker" value="checked" /> <div align="left"> <img src="aradia.jpg" width="256" height="328" border="0" usemap="#Map" /></div> </form> <map name="Map" id="Map"> <area shape="rect" coords="5,176,81,249" href="javascript: void(0);" onclick="javascript: document.getElementById('mapform').submit();" /> </map> <div align="center"><?php echo $zone;?></div> <form action="aradia.php" method="post" > <input type = "submit" name="back" value="back" /></form> </body> </html> and here is the "Teardrop ocean" navigation, which uses php to navigate forward and backwards in the zone, but can't go back to the world map, or there is no way to yet. Code: [Select] /////////////////////////////GAME NAVIGATION AND MONSTER SEARCH CODE NOT FINISHED////////////////////////////////// if(( !isset($_SESSION['current_background']) && !isset($_SESSION['currentMonster'])) OR (! $_POST)) { $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if (!isset($_SESSION['background']) && !isset($_SESSION['monster'])) { $_SESSION['background'] = array ( "<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME2.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME3.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME4.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME5.jpg'/>" ); $_SESSION['monster'] = array ( "<img src='sundragon_monsters_source/water/goldfish/goldfish.png'/>", "<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png '/>", "<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/teardrop_ocean_protector/teardrop_ocean_protector.png'/>" ); } if(!isset($_SESSION['current_background']) && !isset($_SESSION['current_monster'])) { $_SESSION['current_monster']=0; $_SESSION['current_background'] = 0; } if(isset($_POST['further'])) { $_SESSION['current_monster'] = isset($_SESSION['monster'][$_SESSION['current_monster'] + 1]) ? ($_SESSION['current_monster'] + 1) : 0; $_SESSION['current_background'] = isset($_SESSION['background'][$_SESSION['current_background'] + 1]) ? ($_SESSION['current_background'] + 1) : 0; } elseif(isset($_POST['back'])) { $_SESSION['current_monster'] = isset($_SESSION['monster'][$_SESSION['current_monster'] - 1]) ? ($_SESSION['current_monster'] - 1) : count($_SESSION['monster'])-1; $_SESSION['current_background'] = isset($_SESSION['background'][$_SESSION['current_background'] - 1]) ? ($_SESSION['current_background'] - 1) : count($_SESSION['background'])-1; } $currentBackground=$_SESSION['background'][$_SESSION['current_background']]; $currentMonster=$_SESSION['monster'][$_SESSION['current_monster']]; and I echo out $currentBackground and $currentMonster in the main game div. Hi Everyone, I am trying to add on to this mobile detection script that I have been using (quite nicely I might add) from http://detectmobilebrowsers.com/ Code: [Select] <?php // check for mobile browser $useragent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) // redirect if mobile browser header('Location: http://www.example.com/mobile/'); ?> I would like to use/combine some sort of redirect link for users who are redirected to the mobile site to be ridirected back to the full site and vice versa. I wrote a quick $_GET example below, but would rather use $_SESSIONS if possible to make it more transparent/invisible. My question is how best to combine the code above with the code below and get it to work? Code: [Select] <a href="http://www.example.com/?mobile">View Mobile Site</a> <a href="http://www.example.com/?full">View Full Site</a> <?php if ($_GET['mobile']) { $variable = true; } if ($_GET['full']) { $variable = false; } ?> Any help, suggestions, or examples would be appreciated. Thanks in advance, kaiman Hello all, I have a simple form which ends in header( "Location: thankyou.php" ); What I have done on the site so far is to use Ajax to load content into a specific Div which uses the following code <a href="javascript:ajaxpage('home.php', 'content-index');"></a> Is there a way to effectively combine the two together to load the thankyou page (upon pressing submit) into the content-index div? Thank you in advance First of all, im a newb when it comes to scripting other then html/xhtml/css. I need a php script that will run through a list of other php scripts and run them. These are stored on a sever inside a folder. Now the tricky thing is, i would like it to go in some kind of order. Meaning it will not repeat the same php script twice until it runs through all of the scripts. Once it has hit the last script, it starts over. The main php script will be ran by a cron so it will be automated. I tried to set up a cron on each script but it is limited funtcion wise (cant state when to start running the first instance of the cron). Make sense? All help is appreciated! Thanks! Is there a way/function to not only remove <script>, <embed> tags etc but also remove the content within the tags so this: " some text <script> functionhere(); </script> some more text " to this: " some text some more text " In effect remove the whole tag and content within the tags? Havent been able to find anything online that works Many thanks in advance. Simon |