PHP - Running Php Offline
I am using MAMP on my MacBook and don't understand why MAMP and my code in NetBeans will not run if I am offline?
If I am trying to execute PHP files locally on my laptop, why should MAMP or Apache of NetBEans care if I do not have an Internet connection?! I wanted to show someone something at work where there is no Internet access, but that won't work as it currently stands. TomTees Similar TutorialsI have a self-built blog website, done with PHP and MySQL.
How to write the posts offline? How is it done? Which tools are used?
Any suggestions?
Hey Guys/Girls, Thanks for offering to help! I'm currently setting up a small social network for school and I just basically want to know whether the way I'm dealing with in-active users is appropriate and not going to SLOW down my code A LOT, My method is : 3 Functions: Code: [Select] function update_active_user(){ global $connection; global $id; $time = time(); $result3 = mysql_query("UPDATE users5 SET last_update = '$time' WHERE id = '$id'", $connection); } function update_inactive_users(){ global $connection; $time_to_expire = time() - 300; // 300 seconds off the current time $result2 = mysql_query("UPDATE users5 SET online='0' WHERE last_update < $time_to_expire AND online='1'", $connection); } function update_active_users(){ global $connection; $time_to_expire = time() - 300; // 300 seconds off the current time $result2 = mysql_query("UPDATE users5 SET online='1' WHERE last_update > $time_to_expire AND online='0'", $connection); } First function updates the user's field called last_update to the current time (This will only occer when the script loads and the user has done something on my website, it will update their last_update field to current time) Second function sets ALL users that haven't loaded any pages in the last 300 seconds to offline or field online to 0, which obviously means the user is offline Third function sets ALL users that have loaded pages in the last 300 seconds to online if they're offline The reason I'm worried about this is not because it doesn't work, it's working fine at the moment with 2 users, I'm worried when their might be A LOT of users and there are people who are active. My question is : will it make my scripts really slow or be bad for my database in ANY way if I do use these functions for ALL users because each time it searches the table, it is searching ALL users to see if they're active or inactive. I use firebug to detect how javascript work. It same code. the java script :
<script type="text/javascript"> $(function() { $("#cmbNegara").change(function(){ $("img#imgLoad").show(); var kodejeniskayu = $(this).val(); $.ajax({ type: "POST", dataType: "html", url: "getProvinsi.php", data: "kodejeniskayu="+kodejeniskayu, success: function(msg){ if(msg == ''){ $("select#cmbProvinsi").html('<option value="">--Pilih Ukuran--</option>'); $("select#cmbKota").html('<option value="">--Pilih Ukuran--</option>'); }else{ $("select#cmbProvinsi").html(msg); } $("img#imgLoad").hide(); getAjaxAlamat(); } }); }); $("#cmbProvinsi").change(getAjaxAlamat); function getAjaxAlamat(){ $("img#imgLoadMerk").show(); var kodeukuran = $("#cmbProvinsi").val(); $.ajax({ type: "POST", dataType: "html", url: "getKota.php", data: "kodeukuran="+kodeukuran, success: function(msg){ if(msg == ''){ $("select#cmbKota").html('<option value="">--Stok Kosong--</option>'); }else{ $("select#cmbKota").html(msg); } $("img#imgLoadMerk").hide(); } }); }; }); </script>getprovinsi.php <?php require_once('Connections/karyo.php'); ?> <?php ini_set('display_errors',0); //ambil parameter $kodejeniskayu = $_POST['kodejeniskayu']; if($kodejeniskayu == ''){ exit; }else{ $sql ="SELECT kodeukuran,ukuran FROM tukuran WHERE kodejeniskayu='$kodejeniskayu'"; $getNamaProvinsi = mysql_query($sql,$karyo) or die ('Query Gagal'); while($data = mysql_fetch_array($getNamaProvinsi)){ echo '<option value="'.$data['kodeukuran'].'">'.$data['ukuran'].'</option>'; } exit; } ?>getkota.php <?php require_once('Connections/karyo.php'); ?> <?php ini_set('display_errors',0); //ambil parameter $kodeukuran = $_POST['kodeukuran']; if($kodeukuran == ''){ exit; }else{ $sql ="SELECT idstok,harga FROM tstok WHERE kodeukuran = '$kodeukuran'"; $getNamaKota = mysql_query($sql,$karyo) or die ('Query Gagal'); while($data = mysql_fetch_array($getNamaKota)){ echo '<option value="'.$data['idstok'].'">'.$data['harga'].'</option>'; } exit; } ?>the problem at online is, the combobox at getprovinsi not showing up. So I've coded this to run the while loop once for every server within the the table, there is currently two rows within the table and the while loop wont stop running it just keeps on running until I restart Apache, its producing the same effect as what "while(1)" would do, could anybody tell me what the problem could be?, thanks for your time in advance. class bot_restart { function __construct( ) { while($CurrentServers = mysql_fetch_array(mysql_query("SELECT * FROM xhost_boxs"))) { echo $CurrentServers['box_id']; } } } Hi, Im trying to create a really simple password protected page that is fairly secure but when the user doesnt enter a password the wrong error is displayed. Can anyone see a problem? Also could someone please check that im properly compairing the hash password of 2135fa0dd7fb99d167b420b7ff34ec98 with what the user entered when its hashed? login.php <?php session_start(); ?> <?php $submit = $_POST['submit']; $password = md5($_POST['password']); if ($submit) { if ($password) { if ($password == '2135fa0dd7fb99d167b420b7ff34ec98') { $_SESSION['user'] = logged; header('Location: page.php'); } else { header('Location: index.php?id=1'); } } else { header('Location: index.php?id=2'); } } else { header('Location: index.php?id=1'); } ?> index.php <?php $id=$_REQUEST['id']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/xml; charset=utf-8" /> <title>Keys</title> <link rel = "stylesheet" type = "text/css" href = "css/layout.css" /> </head> <body> <div id="header"> <h1>Keys</h1> </div> <div id="secondheader"> </div> <div id="main"> <form method="POST" action="login.php"> Password: <input type="password" name="password" onfocus="selected(this)" onblur="notselected(this)"> <input type="submit" name="submit" value="Login"> </form> <br/> <?php if ($id==1) { echo "Invalid password. Please try again"; } elseif ($id==2) { echo "Please enter a password"; } ?> </div> <div id="footer"> </div> <div id="left"> </div> </body> </html> Thanks in advance. Hi, actually the problem is i have been modifying a website, which has been already built and working. so i have all the code and everything, i need to keep it running to make changes. But i m facing problems like above Warning: require_once(../../global-inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\\Apache2.2\htdocs\login.php on line 2 Fatal error: require_once() [function.require]: Failed opening required '../../global-inc.php' (include_path='.;C:\php5\pear') in C:\\Apache2.2\htdocs\login.php on line 2 please let me know what to do ... and the other thing is i need to execute the entire file of code at a time .....can u please tell me the process of doing it .......... thanks in advance shiva shiva ok. this may make now sense at all, I will try to explain as best as I can. anyways, what I need is for a mysql query to run that will pull all data from table payment between certain days. Then all the rows will show, but I want only one row with each cart_id(there will be multiple) to show. After it does that, in a new column on a table, all the payment types with the amount will show with a slash between each one. I want all of this in a table generated from a php loop. maybe a visual represenation will be better. I hope the picture I attached makes a bit more sense. Hi, I have a PHP script which I want to run from a different IP on my server. Example of what I want to do: My main ip: 4.5.6.7 Have several IP's on server. I want my PHP script (running from CLI) to use cURL with another IP, ay 4.5.6.9 Is this possible to do? Help would be greatly appreciated! I want to run a php file which contains a long process and takes time. If I simply run the file on browsers, the process will be interrupted by any perturbation in the internet connection or closing the browser. How I can force the php process to continue running without connection to my local PC (server side controlling)? I am looking for something like what cron job does (but only one time, not periodically). Hey Guys, I have a DB with two tables, one is field names, the other is the data. So for example, I log in and I am user ID 1..... I need to query the DB to show all fields where user_id = 1 Field1 - Data1 Field2 - Data2 etc etc... This is what I have so far, but I dont get any output... $sql = "SELECT * FROM ".WPSC_TABLE_DATA." WHERE `user_id` == .$cu. ORDER BY id DESC"; $user= $wpdb->get_row($sql); while($user) { echo $user->name .' : '. $user->value .'<br />'; } Can you help please? Hey guys, I dont know if you can do this in PHP due to it only running when the page loads but I would like to make it so at the end of everyday "24:00" some code will run that will reset all users "Mana" and "Health". My guess would be JQuery or somthing like that? If anyone knows would be great for a reply. Cheers guys, Ruddy I'm experimenting with the shell_exec function to gain shell capability on a Linux host that doesn't provide it otherwise. I've found that I can see what is in different directories by entering a command line like: Code: [Select] cd ..; ls but if I enter two consecutive command lines: Code: [Select] cd .. ls The cd command has no effect. Apparently shell_exec is using a new shell every time I call it. Is there a way to start a shell in a PHP script and keep it active while I pass it multiple commands, so that this won't happen? Okay I want to run some code every 24 hours, what would be the best way to do this? Also I don't have root to the server or anything. Hi I've got a qry that selects 100 questions one at a time from tblquestions. When the users have answered q100 I want them to be able to come out of the post-process-post loop that has taken them through the survey. My idea is that I could put an IF requirement in before the qry runs each time it selects the next question i.e. if $nextq <101 $result = mysql_query("SELECT oid,psc9 FROM tblquestions WHERE oid = $nextq"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }; else echo "thanks you've finished now"; Two Questions: Is this the way I should be going about this problem? Have I got the syntax right? Many thanks! Nick I have made a script that allows a user to change their email address. It works BUT if the email address they have chosen is already registered the script does not cut off - it continues to the next if statement and changes the email address anyway. I am trying to put a stop to it using exit() and exit; but it does not work. Any tips? <?php //////////////////// checking new email is not already registered ///////////////// if ($_POST['newemail'] && $_POST['newemail1'] !="") { if ($_POST['newemail'] == $_POST['newemail1']) { $sql2 = "SELECT email FROM Members WHERE email='$_POST[newemail]'"; $result2 = mysqli_query($cxn,$sql) or die ("Couldn't execute query 2"); $num2 = mysqli_num_rows($result2); if ($num2 > 0) { $updateerror = "The email address you have chosen is already registered."; include("my-account.php") exit(); // TRYING TO STOP THE SCRIPT HERE (IF $num2 > 0) exit; } else { echo "You can have this new email address";} } else { echo "Your email addresses do not match. Please try again."; } } else {} // THIS SCRIPT CONTINUES TO CHANGE THE EMAIL ADDRESS DESPITE IT ALREADY BEING REGISTERED. if ($_POST['newemail'] == "") { $newemail = $_POST['currentemail']; } else { $newemail = $_POST['newemail']; } $newemail1 = $_POST['newemail1']; ?> Hey everyone, I have an SQL file called "Cype.sql" and I was wanting to have it run when the install feature is going on. However I can't seem to figure out why exactly the code is not working. is it possible to have it run without getting too in depth the PHP coding? I'm not OOP Literate yet. //Connection is opened //While in installation file $sqlFile = "Cype.sql"; if(!file_exists($sqlFile)){ echo "File not found"; } else{ $openFile = fopen($sqlFile, "r"); $tryQuery = mysql_query($openFile); } Now obviously, I'm not the best coder. I've been out of the works of PHP for quite some time now as well. However, I have researched it and found no answers to my issue. Any help would be greatly appreciate. Thank you. Its the Code: [Select] $query = "INSERT INTO hitlist hit_id = ($addIDs_str), player_id = '$playerID'"; Thats the issue, my codes below i cannot figure out how to insert the results, any help would be appreciated Thanks Code: [Select] if (isset($_POST["submit"]) && $_POST["submit"] == "Recall Selected Informants") { //Force POST values to be INTs $addIDs_ary = array_map('intval', $_POST['chkInv']); //Remove any 'false' value $addIDs_ary = array_filter($addIDs_ary); //Check that there was at least one valid value if(count($addIDs_ary)) { //Create comma separated string of the IDs $addIDs_str = implode(',', $addIDs_ary); //Create and run one query to perform all the adds (of the user) $query = "INSERT INTO hitlist hit_id = ($addIDs_str), player_id = '$playerID'"; $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'"; mysql_query($sql) or die(mysql_error()); if(mysql_query($query)) { $selectedCount = count($addIDs_ary); $adddCount = mysql_affected_rows(); echo "{$adddCount} of {$selectedCount} Investigated player(s) were successfully Removed."; if($adddCount != $selectedCount) { echo " You do not have rights to the others."; } }else{ echo "There was a problem running the query.<br>" . mysql_error(); } }else{ echo "Invalid ID data passed."; } } Hi, I have written some code however when I echo the query it runs it twice... Quote SELECT `description`, `fulldescription` FROM `productdbase` WHERE `keywords` LIKE '%table%'something found.SELECT `description`, `fulldescription` FROM `productdbase` WHERE `keywords` LIKE '%table%'something found. I only have the query once in my code. Any suggesions? Code: [Select] <?php if (isset($_POST['keywords'])){ $keywords = mysql_real_escape_string (htmlentities(trim($_POST['keywords']))); } $errors = array(); if (empty($keywords)) { $errors[] = 'Please enter a search term'; } else if (strlen($keywords)<3) { $errors[] = 'Your search must be three or more characters'; } else if (search_results($keywords) === false) { $errors[] = 'Your search for '.$keywords.' returned no results'; } if (empty($errors)) { search_results ($keywords); } else{ foreach($errors as $error) { echo $error, '</br>'; } } ?> <?php function search_results ($keywords) { $returned_results = array(); $where = ""; $keywords = preg_split('/[\s]+/', $keywords); $total_keywords = count($keywords); foreach($keywords as $key=>$keyword) { $where .= "`keywords` LIKE '%$keyword%'"; if ($key != ($total_keywords - 1)) { $where .= " AND "; } } $query_string = "SELECT `description`, `fulldescription` FROM `productdbase` WHERE $where"; echo $query_string; $query = mysql_query($query_string); if ($results_num === 0) { return false; }else{ echo 'something found.'; } } ?> I am running some php via a cron and I was after the best way to achieve this. Currently I am doing it as follows:- Code: [Select] 0 * * * * lynx -dump http://www.domain.com/script.php This works fine but I don't want anybody being able to run the script by pointing their browser to the file. Any advice on the best method? Cheers. Hello there, I have a problem where the following code is running the query before it should. private function isAccountRegistered($AccountUsername, $AccountEmail) { global $Class; if($Class['MySQL']->currentRows("SELECT * FROM xhost_accounts WHERE account_username = '".$Class['MySQL']->parseClientInput($AccountUsername)."'") == 1) { return USERNAME_REGISTERED; } else if($Class['MySQL']->currentRows("SELECT * FROM xhost_accounts WHERE account_email = '".$Class['MySQL']->parseClientInput($AccountEmail)."'") == 1) { return EMAIL_REGISTERED; } } public function createClientAccount($AccountUsername, $AccountPassword, $AccountEmail, $AccountRealname) { global $Class; if($this->isAccountRegistered($AccountUsername, $AccountEmail) == USERNAME_REGISTERED) { echo("<div class=\"warning\">Unfortunately this username is in use by another member!, please select another!.</div>"); } else if($this->isAccountRegistered($AccountUsername, $AccountEmail) == EMAIL_REGISTERED) { echo("<div class=\"warning\">Unfortunately this email address is in use by another member!, please select another!.</div>"); } else { if($Class['MySQL']->Query("INSERT INTO xhost_accounts (account_username, account_password, account_email, account_realname, account_regdate, account_regtime, account_level, account_balance, account_notifications) VALUES('".$Class['MySQL']->parseClientInput($AccountUsername)."', '".md5($Class['MySQL']->parseClientInput($AccountPassword))."', '".$Class['MySQL']->parseClientInput($AccountEmail)."', '".$Class['MySQL']->parseClientInput($AccountRealname)."', '".date("d/m/y")."', '".time()."', '0', '0.00', 'Enabled')")) { $Class['Core']->refresh('index.php'); } else { echo("<div class=\"warning\">Unfortunately something went wrong there, please try again!.</div>"); } } } For some reason when the code above is run it executes if($Class['MySQL']->Query("INSERT INTO xhost_accounts (account_username, account_password, account_email, account_realname, account_regdate, account_regtime, account_level, account_balance, account_notifications) VALUES('".$Class['MySQL']->parseClientInput($AccountUsername)."', '".md5($Class['MySQL']->parseClientInput($AccountPassword))."', '".$Class['MySQL']->parseClientInput($AccountEmail)."', '".$Class['MySQL']->parseClientInput($AccountRealname)."', '".date("d/m/y")."', '".time()."', '0', '0.00', 'Enabled')")) Before it runs: if($this->isAccountRegistered($AccountUsername, $AccountEmail) == USERNAME_REGISTERED) { echo("<div class=\"warning\">Unfortunately this username is in use by another member!, please select another!.</div>"); } Causing it to say that the username is registered every time yet still inserting the account into the database, its returning that its registered because it inserts it before doing the check, does anybody have any idea why, this really has confused me, thanks for your time. |