PHP - Filtering Gps Points
hi,
i am trying to filter my gps history points. i would like to ignore points if they are too close to the previous position. i can do this like so. $old_lat = $old_long = "0"; foreach($history['data'] as $record) { //calculate distance in meters $distance = distance($record['latitude'], $record['longitude'], $old_lat, $old_long, "V"); if($distance >= 300) { echo 'add(jQuery(this), number += 1, "' . date("d-m-Y @ h:i:s",$record['timestamp']) . '", "map_post.php?n=' . $name . 'u=' . $history['user'] . '", "' . $history['user'] . '", "' . $record['latitude'] . '", "' . $record['longitude'] . '");'; $old_lat = $record['latitude']; $old_long = $record['longitude']; } the problem with the above is that if i arrive home at 6pm on friday and stay outside my house for 24hours, it will show the latest position as at 6pm on fri. i would like it to show the 6pm friday position but with a date 'from and to' time like (28/10/11 18:00 - 29/10/11 18:00) rarther than just (28/10/11 18:00) which looks inacurate. Possible? Similar TutorialsOk i have 3 columms right now i have date player and points and what i want is for this script to add up each players points and send it to page as totals decending i have got the page to show them individually but when i do group it only gets one record so i tried to add in the sum points and it gives me a ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in so i am kind of lost as to where adding the sum(points) would cause this below is the code where the problem is any help would be much appreciated
$r = mysql_query("select * from player_points Sum(points) as total where date_entered > '$d' Group by player order by total DESC"); Okay, I'm trying to make it so that when someone levels up in my game, they can use stat bonus points to increase their abilities. However, there doesn't seem to be a break in there to ensure that someone can't spend points that they don't have. For instance, they get 3 per level, but if they spend 6, the system lets them and shows a -3 in their stat_bonus field. Any help would be appreciated! Thanks in advance!! <?php include("fightfunc.php"); include("lib.php"); //include('cookies.php'); //$link = opendb(); define("PAGENAME", "Stat Bonus"); $player = check_user($secret_key, $db); $x = $player->username; if($_SESSION['234asdfas']){$y = $_SESSION['234asdfas'];}else{echo 'Error: You do not have a session variable set'; exit;} $command = 1; $choice = $_POST['choice']; $amount = $_POST['amount']; if (isset($_POST["statbonus"])) { include("tmpconfig.php"); $checkquery = $db->execute("SELECT * FROM `users` WHERE `id`=?", $player->id); //$rec = mysql_fetch_array($checkquery); extract($_POST); $errors = 0; $errorlist = ""; if ($errors == 0) { $query = $db->execute("UPDATE `users` SET `stat_bonus`=? WHERE `id`=?", array($player->stat_bonus - $amount, $player->id)) or die("querya failed: ". mysql_error()); if($query) $qry = $db->execute("select * from `users` where `id`=?", array($player->id)) or die("qry failed: ".mysql_error()); $rw = $qry->fetchrow(); if($qry){ $query2 = $db->execute("UPDATE `users` SET `stat_bonus`=?, $choice=$choice+$amount WHERE `id`=?", array($player->stat_bonus - $amount, $player->id)) or die("query2 failed: ". mysql_error()); if($query2){ echo("<br><br>You have successfully used your stat bonus points.<br>"); } elseif ($amount > $player["stat_bonus"]) { echo "<font color='red'>Enter an amount higher than 0!</font>"; } elseif ($amount == 0) { echo "<font color='red'>Enter an amount higher than 0!</font>"; } elseif (!is_numeric($amount)) { echo "<font color='red'>Enter an amount!</font."; } else { echo "<font color=green><b>You have succesfully spend skill points!</b></font><br /><br />"; }}}} $player = check_user($secret_key, $db); ?> <table width="100%"> <tr> <td colspan="2"><fieldset> <form action="" method="post"> <font size='4'><b>Skill points</b></font><br /> Every time you raise a level, you get 3 skillpoints. You can spend them here. <br /> You currently have <font color=green><b><?=$player->stat_bonus?> Skill Points.</b></font>. Please choose an attribute:<br /> <br /> <INPUT TYPE="radio" NAME="choice" VALUE="strength" CHECKED>Strength<br /> <INPUT TYPE="radio" NAME="choice" VALUE="vitality" >Vitality<br /> <INPUT TYPE="radio" NAME="choice" VALUE="agility">Agility<br /> <INPUT TYPE="radio" NAME="choice" VALUE="wisdom">Wisdom<br /> <br /> How many skill points do you want to spend? (+1 for every skill point): <br /><br /> Amount: <INPUT TYPE="text" NAME="amount" SIZE="8" MAXLENGTH="8"> <INPUT TYPE="submit" NAME="statbonus" VALUE="Submit"> </form></fieldset></td></tr> </table> <?php $totalcreditstd = $row_rsCreditPurchaseMoney['SUM(quantity)']; $totalcreditsdollar = $totalcreditstd * $Mutliplier; echo $totalcreditsdollar; ?> I'm using the above calculation to display a total amount. Problem is that if the calculation total is 7.5 I want it to show up as 7.50 I want to force the second number. How can I do that? Thanks. I have a picture (attached), where I find the coordinates of black points, because I do not remember any point, so you want every point at which I find coordinates with mark a red cross as watermark. At the coordinates using this script: <?php if(isset($_GET["obrazek_x"])) file_put_contents("soubor.txt",$_GET["obrazek_x"].",".$_GET["obrazek_y"]."\n",FILE_APPEND); ?> Coordinates I save to an external file in this format: Code: [Select] 602;744 Could you advise me a solution to mark black points? Hey, I have a minigame on my website and when you bet 1 It says you lost and you lose your point but it doesn't remove it, Same with if you win it says you gain the point but doesn't add it.... Code: [Select] function bet ($bet){ sleep(2); $user1 = mysql_query("SELECT * FROM `users` WHERE `id`='" . $_SESSION['id'] . "'"); $user = mysql_fetch_object($user1); $chance = rand (1, 2); $bet = round ($bet); $betPretty = number_format ($bet); if ($bet == 0) { $echo = "You did not bet anything!"; $chance = 0; } if ($bet < 0) { $echo = "You cannot bet a negative number."; $chance = 0; } if ($bet > $user->minigame_points) { $echo = "This is more minigame points than you have!"; $chance = 0; } if ($user->minigame_points == 0) { $echo = "You do not have any minigame points."; $chance = 0; } if ($chance == 1) { //Win $money = $user->minigame_points+$bet; $times_bet = $user->times_bet+1; mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'"); $money = number_format($money); $echo = "You won $betPretty minigame points!<br /><b>Current Minigame Points:</b> $money"; } if ($chance == 2) { //Lose $money = $user->minigame_points-$bet; $times_bet = $user->times_bet+1; mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'"); $money = number_format($money); $echo = "You lost $bet minigame points.<br /><b>Current Minigame Points:</b> $money"; } return $echo; Hello dear friends, first of all : merry merry Xmas!!! i want to parse with the simple Simple HTML DOM Parser, well i am pretty new to php and to the Simple HTML DOM Parser. My example: http://schulen.bildung-rp.de/gehezu/startseite/einzelanzeige.html?tx_wfqbe_pi1[uid]=60119 I want to collect the data in the block: I have investigated the sourcecode - and found out that the attribute of interest should be this one: class="content"div class="content"><!-- TYPO3SEARCH_begin --> here the code is: - my trails. // inculde the Simple HTML DOM Parser include_once('simple_html_dom.php'); // get the file we want to parse right now,create a DOM $html = file_get_html(''); // simple_html_dom::find() creates a new // simple_html_dom-Objekt, that consists out of // corresponding childelements foreach($html->find('class: content ') as $h3) { // simple_html_dom::get the text in a tag // den Text innerhalb eines Tags if($h3->innertext == 'Text of a H3 Tag') { break; } } // simple_html_dom::next_sibling() gives the // next Element $table = $h3->next_sibling(); but believe me - it gives me not back what is aimed. what have id done wrong...? dbone I have a form and script that is used to collect information from users. There is one field that is url. There is one field that is email. I want to filter out scripts. I also only want to allow url in the url field and email in the email field. Is there an easy way to filter? I have tried several pieces of code to no avail. Code: [Select] <?php $root = $_SERVER['DOCUMENT_ROOT']; include('/home/arts/public_html/shows/includes/config.db.php'); if ($link) { foreach ($_POST as $k => $v) { if (($k == "start_date") || ($k == "end_date") || ($k == "application_dead")) { $varray = explode("/",$v); $v = $varray[2] . "-" . $varray[0] . "-" . $varray[1]; } $v = "'" . addslashes($v) . "'"; if($k != "captcha_code") { $keys[] = $k; $vals[] = $v; } } $fields = implode(",", $keys); $values = implode(",", $vals); //$fields = "id," . $fields; //$values = "null," . $values; $sql = "INSERT into craft_shows ($fields) VALUES ($values)"; $result = mysql_query($sql,$link); if (!$result) { die('There was a problem with your submission. Refresh the page to try again'); } else { echo "Thank you for your submission.<br>"; echo "<a href=\"http://www.artsandcraftsnetwork.com/shows/\">Back to shows</a><br>"; echo "<a href=\"http://www.artsandcraftsnetwork.com/shows/shows_submit.php\">Submit another show</a>"; } } ?> hey guys i was generally wondering...is it good practice to add_slashes and use mysqli_real_escape_string when entering data into the database?
then to strip slashes when extracting rows?
is this the right way to go around things...thanks
I have a SQL statement which is difficult to use PDO on, it might not even be possible to do.
So I'm filtering it like this:
$search = $_GET['search']; $search = preg_replace("/[^A-Za-z0-9]/", " ", $search); $search = $mysqli->real_escape_string($search);Will this result in an acceptable level of security? Edited by anderson_catchme, 16 September 2014 - 12:28 PM. Hello,
Is it possible to allow '@' and '.' while maintaining the rest of this regex?
$email= 'adsfsa@asdf.edu'; $email= preg_replace("/[^A-Za-z0-9]/", " ", $email); echo $email; Hi all, I am working on a tool to pull data remotely and the data is set to xml format. I want to post items that meet a certain criteria only, essentially there are several layers/tags on the data being brought over. The sStatus is the primary item I am looking for, not only that but only if it has or equals to "Waiting". Any thoughts or suggestions greatly appreciated. Below is the basic code I have in place currently and am working on. <code> <?php $soapclient = new SoapClient("https://secure.logmeinrescue.com/api/api.asmx?wsdl"); $sEmail = "dummy@dum.com"; $sPassword = "dum123"; $iNodeID = "123456"; $eNodeRef = "NODE"; $sAuthCode = ""; $loginparams = array ( 'sEmail' => $sEmail, 'sPassword' => $sPassword); $loginResult = $soapclient->login($loginparams); $output = array( 'eOutput' => "XML" ); $outputResponse = $soapclient->setOutput($output); $sessionparams = array( 'iNodeID' => $iNodeID, 'eNodeRef' => $eNodeRef, 'sAuthCode' => $sAuthCode ); //get session(s) $sessionresult = $soapclient->getSession($sessionparams); $session = $sessionresult->aSessions; $sessionnodes = $session->SESSION; $session_status = $sessionnodes[$isessionNodes]->sStatus; print_r($sessionresult); ?> </code> I want to create a feature as you see nn this image, where it says 'filter your results' if a user clicks 'Detached Houses' then only detached houses will be displayed. if a user clicks 'Semi-detached' then only semi detached houses will be shown. Any help is really appreciated, thank you. Code: [Select] <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><div id="filter"><p class="houses" style="font-family:helvetica;color:#0155a1;font-size:14px;background:url(cutouts/forsale/filter.jpg) no-repeat;"><b><u>Houses</u></b> <br /> <span class="dh"><b><u>Detached Houses</u></b></span><?php // Make a MySQL Connection mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM example WHERE name='Sandy Smith'") or die(mysql_error()); // get the first (and hopefully only) entry from the result $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table echo $row['name']." - ".$row['age']; ?> <br /> <span class="dh"><b><u>Semi-detached houses</u></b></span> <br /> <span class="dh"><b><u>Terraced houses</u></b></span> <br /> <br /> <b><u>Flats / Apartments</u></b> </p></div></td> I'm pretty sure the problem is starring me in the face, but I can't seem to locate it. function filter($string) { //swear words pulled from bannedwordlist.com $f = fopen('../badwords.txt', 'r'); $bad_words = fread($f, filesize('../badwords.txt')); $bad_words = explode('\n', $bad_words); $input = strtolower($string); foreach($bad_words as $value) { $string = str_replace($value, '****', $input); } return $string; } UPDATED CODE function filter($string) { //swear words pulled from bannedwordlist.com $f = fopen('../badwords.txt', 'r'); $bad_words = fread($f, filesize('../badwords.txt')); $bad_words = explode('\n', $bad_words); $input = strtolower($string); $string = str_replace($bad_words, '****', $input); return $string; } I've already echoed out $value in the foreeach loop, and it does correctly retrieve the bad words and put them into an array. My only problem is, the returned string is still in strtolower() form, and the words aren't censored. :/ Hi guys I was wondering if anyone could point me in the right direction with this. I am using JSON to return the contents of a directory and then using a foreach loop to print each one to a new row in a table. Is there anyway to filter the results? Basically I just want to show the files that end in a .jar extension? Currently all sub directories and files are shown, however all the files I need to pull will be in the main directory. This is what I am using: Code: [Select] <?php foreach ($installedplugins1['success'] as $v) { echo "<tr><td>".$v."</td>"; echo "<td><a href='index.php?dp=".$v."'>Disable Plugin</a></td>"; } ?> Any hints or reading material? Cheers Hi, I have an issue, I cant filter my data from DB. Whats wrong in my code? <?php /* Include Files *********************/ //include("banners/database.php"); mysql_connect("host", "user", "pwd") or die("Connection Failed"); mysql_select_db("DB")or die("Connection Failed"); ?> <?php $memberIndustries =['memberIndustries']; if (isset($_POST["memberIndustries"])) { $memberIndustries = mysql_real_escape_string ($_POST["memberIndustries"]); $sql="SELECT * FROM Members WHERE Industries_Industry_ID='$memberIndustries'"; $result = mysql_query($sql) or die (mysql_error()); while ($myrowe = mysql_fetch_array($result)) {?> <? // if new member, label it //$todays_date = date("Y-m-d"); //$dateCompare = $myrowe[Creation_Date]+30; //$dateCompare = strtotime(date("Y-m-d", strtotime($myrowe[Creation_Date])) . " +30 days"); //if(strtotime($todays_date)<=$dateCompare){ ?> <table width="100%"> <tr> <td align="right"> <img src="/members/new.gif"> </td> </tr> </table> <? //}?> <? if($myrowe[LOGO_lnk]!='') {?> <img src="<? echo $myrowe[LOGO_lnk]; ?>"> <? } ?> <br /> <br /> <font style="font-family: Arial; font-size: 10.5pt; font-weight:bold;color:#C1121F"> <? echo $myrowe[Company_Title];?> </font> <? if($myrowe[Person_Name_1]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Name_1];?></font> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Title_1];?></font> <? } if($myrowe[Person_Name_2]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Name_2];?></font> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Title_2];?></font> <? } if($myrowe[Person_Name_2]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Name_3];?></font> <font style="font-family: Arial; font-size: 8.5pt; font-weight:bold;color:#000000"><? echo $myrowe[Person_Title_3];?></font> <? } if($myrowe[Address_row1]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Address_row1];?></font> <? } if($myrowe[Address_row_2]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Address_row_2];?></font> <? } if($myrowe[Address_row_3]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Address_row_3];?></font> <? } if($myrowe[Phone]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000">Tel:<? echo $myrowe[Phone];?></font> <? } if($myrowe[Fax]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000">Fax:<? echo $myrowe[Fax];?></font> <? } if($myrowe[email]!='') {?> <br /> <a href="mailto:<? echo $myrowe[email];?>"> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[email];?></font> </a> <? } if($myrowe[web]!='') {?> <br /> <a href="<? echo $myrowe[web];?>"target="_blank"> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[web];?></font> </a> <? } if($myrowe[Industries_Industry_ID]!=0) { $queryInd = "SELECT Industry_Title FROM Industries WHERE Industry_ID=$myrowe[Industries_Industry_ID]"; $resultInd = mysql_query($queryInd) or die (mysql_error()); $myroweIND = mysql_fetch_array($resultInd) ?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myroweIND[Industry_Title];?></font> <? } if($myrowe[Description]!='') {?> <br /> <font style="font-family: Arial; font-size: 8.5pt; color:#000000"><? echo $myrowe[Description];?></font><p></p> <? } ?> <br /><br /> <? } <? }} ?> Hi there I have the following array . Code: [Select] $products = array( array( Code => "CF1", Items => "Sand Tray", Cat => 'Tray', ), array( Code => "CF2", Items => "Mobile Computer Table", Cat => 'Table', ), array( Code => "CF3", Items => "General Service Trolley", Cat => 'Trolley', ), array( Code => "CF4", Items => "TV Trolley", Cat => 'Trolley', ), array( Code => "CF5", Items => "Overhead Projector Trolley", Cat => 'Trolley', ), array( Code => "CF6", Items => "Book Trolley", Cat => 'Tolley', ), array( Code => "CF7", Items => "Stacking Chairs", Cat => 'Chairs', ), ); What I want to do is select each by 'Cat'. For example I simply want to display all the trolleys. I was wondering how I do this? What functions would I use in PHP? Thanks a million This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=334433.0 Hi all, I was wondering if i can filter certain log files like using 2 keywords and get all the info inbetween? The log files are like <1 MB. The other problem i encounter is howto since i looked all over the net but cant seem to find usefull info about it. Can you help me out here? First off, i have made a validation class using array_diff() to check if there are invalid characters submitted by a user. Some extracts: Code: [Select] $this->chr_alpha_lower=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); $this->chr_alpha_upper=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $this->chr_numeric=array('0','1','2','3','4','5','6','7','8','9'); $this->chr_symbol=array(' ','!','@','#','$','%','&','(',')','[',']','.',',',':',';','\'','"','/','=','\\','-','_','?'); ... // lets say only alpha and numeric characters are allowed $allowed_characters=array(); $allowed_characters=array_merge($allowed_characters,$this->chr_alpha_lower,$this->chr_alpha_upper); $allowed_characters=array_merge($allowed_characters,$this->chr_numeric); $input_split=str_split($this->input); $invalid=array_diff($input_split,$allowed_characters); if(empty($invalid)){ return true; } return false; I have two questions. First, for acsii characters is this method 'full proof' or is there a way for someone to get around this validation script? Second, a new site im developing is going to be built with UTF-8 in mind so people can use the site in their own language. How do i validate UTF-8 user input? I know about mb_strings and sanitizing UTF-8 input using this: Code: [Select] preg_match_all('/([\x09\x0a\x0d\x20-\x7e]'. // ASCII characters '|[\xc2-\xdf][\x80-\xbf]'. // 2-byte (except overly longs) '|\xe0[\xa0-\xbf][\x80-\xbf]'. // 3 byte (except overly longs) '|[\xe1-\xec\xee\xef][\x80-\xbf]{2}'. // 3 byte (except overly longs) '|\xed[\x80-\x9f][\x80-\xbf])+/', // 3 byte (except UTF-16 surrogates) $input, $clean_pieces ); $clean_output = join('?', $clean_pieces[0] ); But how do i know what to filter? Example: a field for the user to input first name English: only alpha characters Other language: ????? Help much appreciated. |