PHP - How To Clean Css Data Coming From Fck Editor
if any body copy and paste anything from word to editor some unwanted css also coming with that pasting. when we request the data same css also coming with that. so how to clean data when we request
$desc =$_request['contents']; how to solve this issue. please help me. Similar TutorialsI'm new to OOP and trying to write tiny classes to get practice. The next class I want to create will be used to clean HTTP data from when a form gets submitted. I'm embarrassed to say, but I'm scratching my head trying to figure out what types of things I should do as far as "sterilizing" POST and GET data?! Can someone get me started here? Thanks, TomTees 0
What is the best way to store this data coming from the api into a csv file to later put into the db. Output: rank, level, xp, rank, level, xp, etc. This api produces about 60 rows of data per name ran and x that by about roughly 300 names that equals a lot of data. Pretty much with my current code I am pretty much creating a endless loop almost that would take a long time to execute so updating said data would be a nightmare i would think. Is there a way to accomplish the same thing without the loop or I am not sure how to go about this. My current code is a mess that much I know I am gonna be told. This code works, just not efficiently. I am thinking there may be a better way to do this. $query = $conn->prepare("SELECT name FROM users LIMIT 1"); $query->execute(); while($row = $query->fetch(PDO::FETCH_ASSOC)){ $name = $row['name']; $url = 'https://secure.runescape.com/m=hiscore/index_lite.ws?player='. $name . '';//api that the csv data is coming from $highscores = file_get_contents($url); $fields = array("Name", "Rank", "Level", "Xp");//this is to add the headers // for the csv files $implode1 = implode($fields, ",");//turn into csv format, not sure this is //even needed $implode1 .= "\n";/*this is to add a line break so that the explode below will properly put it into its own element*/ //otherwise data starts joining togather $extra_data = array("$name");/*This is to add the name that the data pertains too*/ $implode2 = implode($extra_data, ",");//turn into csv format $highscores = $implode1 . $implode2 . $highscores;//join as one array $highscores = explode("\n", $highscores);//turn each csv into an element of //its own element a bunch of unsets to remove unwanted data. Omitted them to condense the code $i = 1; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="name.csv"'); $data = $highscores; $fp = fopen('highscores/' . $name . '.csv', 'wb'); foreach ( $data as $line ) { $val = explode(",", $line); fputcsv($fp, $val); } fclose($fp); The pdo part I was gonna include but the way I have it setup now wouldn't work. I was thinking that I would use mysql's LOAD DATA INFILE to insert the csv data to database. The end goal here is to be able to search for player stats and to use said data to keep track of xp earned during a xp competition. I PRAY that i have included enough info... I would really appreciate any feedback if possible. Hello friends if i've this $text = "i love adult sites" then i wanna clean it by elminate words like adult - bad - kill - die so it be $clean = "i love sites" as you can see it eliminated the word adult how it could be which code can i use ? thanks in advance Hey guys I have a lot of inputs from my form. Is there a way I can do like a for each or something instead of of having to write $myusername = stripslashes($_POST['name'); $mypassword = stripslashes($_POST['pass']); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); .... for all 16 fields? thanks Hi, Here is a tiny bit of my code $r = mysql_query ($query); while ($row = mysql_fetch_array ($r, MYSQL_ASSOC)) { echo "<tr> <td align=\"center\">"; echo date("M-d-Y", mktime(0, 0, 0, $row['month'], $row['day'], $row['year'])); echo "</td> "; if ($row['presenter1status'] == '0') { echo "<td align=\"center\"><font color=\"#FF9900\">{$row['presenter1']}</font></td>"; } elseif ($row['presenter1status'] == '1') { echo "<td align=\"center\"><font color=\"green\">{$row['presenter1']}</font></td>"; } elseif ($row['presenter1status'] == '2') { echo "<td align=\"center\"><font color=\"red\">{$row['presenter1']}</font></td>"; } if ($row['presenter2status'] == '0') { echo "<td align=\"center\"><font color=\"#FF9900\">{$row['presenter2']}</font></td>"; } elseif ($row['presenter2status'] == '1') { echo "<td align=\"center\"><font color=\"green\">{$row['presenter2']}</font></td>"; } elseif ($row['presenter2status'] == '2') { echo "<td align=\"center\"><font color=\"red\">{$row['presenter2']}</font></td>"; } if ($row['engineerstatus'] == '0') { echo "<td align=\"center\"><font color=\"#FF9900\">{$row['engineer']}</font></td>"; } elseif ($row['engineerstatus'] == '1') { echo "<td align=\"center\"><font color=\"green\">{$row['engineer']}</font></td>"; } elseif ($row['engineerstatus'] == '2') { echo "<td align=\"center\"><font color=\"red\">{$row['engineer']}</font></td>"; } echo "</tr> I was wondering if there is a better way of doing this as I think including this many ifesle statements in a while loop that could go round about 40 times might be very heavy on the resources. Thanks What is the cleanest way to write this if? Code: [Select] <div <?php if (!empty($otherfans)) {echo "class=\"newstext\"";} else {echo "class=\"newstext pts\""; } ?>> My code here Code: [Select] setcookie('hide_div', $_COOKIE['hide_div'].','.$_GET['hide'],time()+32000000); When I set it, it works wonderful, but then when I see view it in my cookie it shows this code between my $_GET['hide'] values Code: [Select] %2C how do I clean it up and just make it show my " , "? Thank you Hi Im trying to write a script to clean up my image directory which has quite a lot of unused images that have built up over time. In order to do this I am doing the following. First Create a database table called 'image_clean' Then I'm searching through 3 tables and collecting all the image file names and dumping the names in the table 'image_clean' Can do that no problem. So now I have all the images I need in this one table 'image_clean' I now want to go through my directory 'image_uploads' and delete anything thats not in the 'image_clean' table. I know how to delete the files using unlink Im just unsure how to search through the directory file by file and check the file against the database. Im asumming I need to put them in an array. Could anyone give be a clue or two to get me started. I have no problem checking a database against a directory but when its the other way round 'checking a directory against a database I'm lost. What I might do is pop the files to delete in a new database called 'image_delete' so that I can then check the images to delete before I write the unlink script. But I'm just not sure how to pick up each file and compare it to the table. Thanks in advance. Hey all, I would like to some how clean up an if statement to be a little cleaner. Code: [Select] if(condition && condition && (condition && condition) || (condition && condition) || (condition && condition)) How can I do that? I've been messing around with clean urls in php and I've been having some trouble. I'm working on a private messaging system and when I go to "sitename.com/mail/view.php?page=inbox" it correctly displays the users inbox messages but when I put "sitename.com/mail/view/inbox/" it just displays the page like the GET value isn't set. Why is that? this is the HTACCESS file for clean url RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^view/([a-z]) view.php?page=$1 [NC,L]
Hi, I am creating a website but am having trouble with the following: I have an include file(db.inc) which contains the following: function clean($input, $maxlength) { $input = substr($input, 0, $maxlength); $input = EscapeShellCmd($input); return ($input); } The file I am having the problem with is my view.php file. I get the following error: Notice: Undefined variable: file in C:\wamp\www\fermpix\view.php on line 4 Line 4 contains the following: $file = clean($file, 4); My view.php does have the line: include 'db.inc'; Does anybody have any idea what the issue might be? Cheers Paul I created a new homepage for my network of sites I run. I tried to go for a simple and clean look. The pages themselves function how I'd like, but I'm unsure if the menu system is easy to understand or not.
I even added a time limited message on the front page of the site indicating that the logo was clickable, but purposely left it off of other sub-pages to try and keep the design as clean as possible.
Check it out, let me know what you think.
http://ctenetwork.com
I currently use the following function to clean form inputs to prevent MySql injection, Does this function do enough to prevent MySql injection? is there anything i have missed? <?php //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } ?> I've been using clean URLs and it's been giving my PHP sessions for my user system some trouble. I display the logged in users username on every page via a header.php file that I require on every page. Sometimes when I click a link to navigate to a page with a clean URL, the session information "disappears" and asks the user to login but if I navigate to another page from the clean url that the session "disappeared" on, the logged in users username is displayed at the top of the page like normal. Any idea certain pages cause the session to "disappear"
Header.php where the user info is displayed. $_SESSION['username'] is set on the login page <? session_start(); if (isset($_SESSION['username'])) { echo "Welcome back, " . $_SESSION['username']; } ?> Edited June 13, 2020 by Nematode128 i have my form with 5 fields that are not required to be filled out. Code: [Select] <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> On my process page I want to remove all of the empty index's that did not have data entered. I am new to sending array data via POST do I need to do anything else other then what is below? Code: [Select] foreach($MAC as $key => $value) { if($value == "") { unset($MAC[$key]); } } $mac_addresses = array_values($MAC); if(empty($mac_addresses)){ $error = "You did not enter any MAC adresses."; $valid = "false"; } I am currently using my own error handler so i can log all mysql errors into a mysql table: mysql_query('select data from table')or trigger_error(mysql_error(),256); If there's an error i need to know the line number where the mysql_query function was called. Is it possible to instead use this code: mysql_query('select data from table'); but somehow transparently log a mysql error and the line number if there is an error in the query? thanks My error: Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key FROM applications WHERE key = '0188f'' at line 1 Code: function randomNum() { $random = substr(md5(rand(5000,300000)), -5); $query = mysql_query("SELECT key FROM applications WHERE key = $random") or die(mysql_error()); //make sure it doesn't already exist if(mysql_num_rows($query) > 0) { randomNum(); } else { return $random; } } I simply cannot seem to figure out what is happening...I've tried many solutions, but all seem to fail. Okay, so, I'm trying to pull the info from my `shop` table where the `users` table matches at x, y, z, and plane. Instead, I'm getting this: Resource id #22 Where is this coming from? I only have 1 row in my shop table, and it has: id = 7 name = admin shop x = 1 y = 0 z = admin plane = batai I'm standing in the shop right now (as my character, so my users table has the exact same x, y, z, plane)... Any help would be appreciated! $q1 = mysql_query("SELECT * FROM `shop` WHERE `x`='".$x["x"]."' AND `y`='".$x["y"]."' AND `z`='".$x["z"]."' AND `plane`='".$x["plane"]."'") or die("qry failed: ".mysql_error()); Variables: $x = $x = $player->username; (so it's pulling my username, which it is doing correctly ==> i echoed out $x and it came up with my username) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <?php // Connect to database================================================== include("connect_db.php"); // sending query =========================================================== $result = mysql_query("SELECT * FROM members Order By last") or die(mysql_error()); if (!$result) { die("Query to show fields from table failed"); } echo "<br />"; echo "<p>MEMBERS LIST</p>"; echo "<table border='10' cellpadding='3' cellspacing='2'>"; echo "<tr><th>First Name</th><th>Last Name</th>><th>Phone</th><th>Email</th></tr>"; // keeps getting the next row until there are no more to get ================ while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table ========================== echo "<tr><td>"; echo $row['first']; echo "</td><td>"; echo $row['last']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?> </body> </html> This is the output. MEMBERS LIST > First Last Phone Email data data data data ect............................................................... I cannot find where the > (greater than) sign is coming from. There is a space after MEMBERS LIST but I could not get it to work in this display. Hi, I just started learning PHP... Below is my first programme infact.. Out put is not coming when i type some thing in input boxes... Can somebody suggest where is the error... Index.php <html> <head> <title>Welcome to our site</title> </head> <body> <form method="POST" action="submit.php"> <label for ="business_name">Business name</label> <input type="text" id="business_name" \><br/> <label for ="contact_person">Contact person</label> <input type="text" id="contact_person" \><br/> <label for ="Telephone">Telephone</label> <input type="text" id="Telephone" \><br/> <label for ="FAX">FAX</label> <input type="text" id="FAX" \><br/> <label for ="Mobile">Mobile</label> <input type="text" id="Mobile" \><br/> <label for ="Addres_line_1">Addres_line_1</label> <input type="text" id="Addres_line_1" \><br/> <label for ="Addres_line_2">Addres_line_2</label> <input type="text" id="Addres_line_2" \><br/> <label for ="Addres_line_3">Addres_line_3</label> <input type="text" id="Addres_line_3" \><br/> <label for ="Addres_line_4">Addres_line_4</label> <input type="text" id="Addres_line_4" \><br/> <label for ="City">City</label> <input type="text" id="City" \><br/> <label for ="Pin_code">Pin_code</label> <input type="text" id="Pin_code" \><br/> <label for ="State">State</label> <input type="text" id="State" \><br/> <label for ="email">email</label> <input type="text" id="email" \><br/> <input type="submit" value="Please submit the details" name="submit"/> </form> </body> </html> submit.php <head><title>Your submission details</title></head> <body> <H3>YOU HAVE SUBMITTED THE FOLLOWING DETAILS</H3> <?php $business_name= $_POST["business_name"]; $contact_person = $_POST["contact_person"]; $Telephone = $_POST["Telephone"]; $fax = $_POST["FAX"]; $mobile = $_POST["Mobile"]; $address1 = $_POST["Addres_line_1"]; $address2 = $_POST["Addres_line_2"]; $address3 = $_POST["Addres_line_3"]; $address4 = $_POST["Addres_line_4"]; $city = $_POST["City"]; $pincode = $_POST["Pin_code"]; $state = $_POST["State"]; $email = $_POST["email"]; echo "Your business name".$business_name.'<br/>'; echo "Contact person".$contact_person.'<br/>'; echo "Telephone no.".$Telephone.'<br/>'; echo "Fax No.".$fax.'<br/>'; echo "Mobile No.".$mobile.'<br/>'; echo "Address line one".$address1.'<br/>'; echo "Address line two".$address2.'<br/>'; echo "Address line three".$address3.'<br/>'; echo "Address line four".$address4.'<br/>'; echo "Your City".$city.'<br/>'; echo "Your Pincode".$pincode.'<br/>'; echo "Your State".$state.'<br/>'; echo "Your email".$email.'<br/>'; ?> <a href=index.php>Home</a> </body> </html> |