Jump to content
Larry Ullman's Book Forums

Max

Members
  • Posts

    112
  • Joined

  • Last visited

Everything posted by Max

  1. Hi Larry, Regarding your spam blocker, of course, I have been using it. However, I was still getting emails from automated spam producers, bots or whatever, so I thought I would share this little routine with you. It simply checks to see if there is a human at the other end (who can add!!) and I now receive NO spam at all. All I do is ask the customer to add two numbers. I put these as numerics, but one could create an array with 1 = One, 2 = two etc etc. I'll leave out all of the extraneous code. Header etc etc <?php $check = $_POST['check']; //Getting answer from customer of the addition. $result2 = $_POST['checking']; //Getting answer from the addition by the server. //if then loops etc, with all of the questions etc.... //...after spam scrubber: if($check == $result2) { //Send the email to me and thank customer } else { echo '<h2 style = "font-family: Arial, Verdana; font-size: 20px; font-weight: bold; background-color: #ffff99;">It seems that your arithmetic is erroneous. Please try again.'; //Make the customer do the sum again. } ?> //Start form action..... Check:<br /> //Or you could write more informative text for the customer. <?php $random1 = RAND(1, 9); //Invent an integer between 1 and 9. $random2 = RAND(1, 9); //Ditto. $result1 = $random1 + $random2; //Do the math!! echo 'What is ' . $random1 . ' plus ' . $random2 . '? <input type="text" name="check" size="3"/><input type = "hidden" name = "checking" value = "' . $result1 . '" /><br /><br />' ; //Ask the customer the question - the answer to the addition. Also send the server's answer ($result1). ?> <input type="submit" value="Send" ><input type="hidden" name ="Secure" value = "ejeewq8"> <input type="reset" value="Clear"> <input type = "hidden" name = "submitted" value = "submitted"> //Send it. <br /><br /> I hope that you find it interesting. Regards Max
  2. One more comment, Larry - I don't seem to be getting any messages via email regarding replies to topic. I have checked settings, email address etc. Not going into Spam. Thought I'd let you know. Max
  3. Hi Larry, That's what I would normally do, but I was copying and pasting a lot of data from my Garmin GPS text dump and didn't think about it at the time. Forewarned is forearmed...or whatever! Sadly, this is what passes for fun for me 🤪.
  4. Larry, you're a star! Firstly, it didn't cross my mind about 'Date' being a keyword in SQL!! I have now resolved the issue - code below. The results can be seen here: http://www.zrm.es/blog.php Yes, I know that my CSS is shocking, but I am just a hobbyist, not a professional and just hate it!! Interestingly, experimenting I can't get date_format() in php to work at all. No matter. I won't use it again. Thanks again, Larry. --------------------------------------------------------------------------------------------------- <?php $_title = "blog."; $_description = "blog"; $keyword = "blog"; include ('header.php'); require_once('../users.php'); //This is the $dbc routine. ?><br /><br /> <div style = "width: 80%; margin: auto; "> <p style = "margin: auto; border: 6px solid rgb(62,60,100); width: 15%; height: 30px; padding: 1.8% 0 0 0; text-align: center; font-family: sans-serif; color: rgb(62,60,100); background-color: rgb(255, 204, 0); font-weight: bold; ">BLOG</p> <br /><br /><br /><table style = "border: 3px solid rgb(62,60,100); width: 99%; "> <?php date_default_timezone_set('Europe/Madrid'); //actually in header.php as well - put this in out of dessperation. $blog1 = "SELECT * , DATE_FORMAT(Date1, '%W, %e %M %Y') AS 'FD' FROM ZRM ORDER BY Date1 DESC"; //SQL request including the formatted date $blog2 = @mysqli_query($dbc, $blog1); //Do the query while ($blog3 = @mysqli_fetch_array($blog2)) //while loop to extract the data from the array { $ref = $blog3['Ref']; //Dont really need this but hey $date1 = $blog3['FD']; //Formatted date $comments = $blog3['Comments']; //Text $image = $blog3['Image']; //image name echo '<tr><td><a href = "images/raw/' . $image . '.jpg" target = "_blank"><img src = "images/reduced/' . $image . 'jpg" alt = "Sorry, image missing." title = "Click to enlarge." style = "border: 2px solid black; margin: 5px; margin-top: 5px; margin-bottom: 5px; margin: auto; " /></a></td><td style = "padding: 5%; vertical-align: top; "><p style = "vertical-align: top; text-align: right; "><b>' . $date1 . '</b></p><br /><br /><p>' . $comments . '</p></td></tr>'; } echo '</table></div>'; include('footer.php'); die(); ?> ---------------------------------------------------------------------------------------------------
  5. Hi Larry, Thanks for your reply to my problem with splitting numbers and alphas. I have a new problem now and am baffled. I am putting together a little blog for which I am using MySQL and php. The database is populated fine and I can pùll the date as $date from the MySQL, The problem is when I try to format it as, for example, Monday 27 July 2021. The code is: Previous code includes calling $dbc, etc etc. <?php date_default_timezone_set('Europe/Madrid'); $blog1 = "SELECT * FROM ZRM ORDER BY Date DESC"; $blog2 = @mysqli_query($dbc, $blog1); while ($blog3 = @mysqli_fetch_array($blog2)) { $ref = $blog3['Ref']; $date = $blog3['Date']; It all works up to here: $date2 = date_format($date, 'd/F/Y'); echo date_format($date, 'j n y') . $date2; As you can see, I have tried a number of formats. Nothing at all prints and no error messages. Using double apostrophes neither. $date prints as: 2021-09-13 13:33:06 . The strange thing is that I can copy/paste the code into W3Schools and it works perfectly (by adding a line at the top: $date=date_create("2013-03-15"); See https://www.w3schools.com/php/phptryit.asp?filename=tryphp_func_date_format For example, W3Schools gives me: 13 Sep 2021 when I run: <?php $date=date_create("2021-09-13 13:33:06"); echo date_format($date,"d M Y"); ?> If I have to I can use some string functions to pull the date apart and re-organize it, but date_format should work, no? As always, your assistance is greatly appreciated. Max You can see $date as it comes out here: http://www.zrm.es/blog.php
  6. Finally got it: $map1 = 12345,98765 //Imagined co-ordinate $map2 = substr_replace($map1, '', strrpos($map1, ',', 0)); // Gives the left hand number $map3 = substr_replace($map1, '', 0 , strrpos($map1, ',', 0) + 1); //Gives the right hand number RESULT: Map1 = 12345 Map2 = 98765 Regards Max
  7. Hi Larry, I hope all is well with you. I have what I thought was a simple problem with a simple solution. 😄🤣 I have in a mysql database a table with data so: 12345/98765 (they are co-ordinates). I need to subtract a number from the left number and a different number from the right number, and then put them back. Thus I need to assign the left hand number to a variable, and the right hand number to another variable. Then I can do the subtraction and replace the co-ordinates. The two numbers aren't necessarily always the same number of digits. I have thought about str_replace, ltrim, rtrim, strpos etc. but none of them cut the mustard. I'd rather do it in php that use LEFT() and RIGHT() in MySql. Any ideas? I have now wasted a whole afternoon on this. 🙄 Max
  8. ...and I am killing off any emails in the first category as I don't want to receive them anyway.... $very_bad = array('to:' , 'cc:', 'bcc:', 'content-type:', 'mime-version', 'multipart-mixed', 'content-transfer-encoding:', 'sex', 'bitcoin', 'resource', '$', 'city', 'money', 'traffic', 'GetaBusinessLoan', 'bitcoin', 'ProFunding', 'BusinessLoan', 'einfac'); foreach ($very_bad as $v) { if (stripos($value, $v) !== false) { die(); } } I don't know it that is bad programming practice to kill a program in mid-flow (like the dreaded BASIC GOTO command), but it does work!
  9. I have also changed the criteria so: $very_bad = array('to:' , 'cc:', 'bcc:', 'content-type:', 'mime-version', 'multipart-mixed', 'content-transfer-encoding:', 'sex', 'bitcoin', 'resource', '$', 'city', 'money', 'traffic', 'GetaBusinessLoan', 'bitcoin', 'ProFunding', 'BusinessLoan', 'einfac'); which has cut downthe deluge of spam that I used to get.
  10. Hi there I hope you are well, Larry. I decided to re-visit my 'Contact us' page and review the spamscrubber. I was having trouble getting the spamscrubber to fish out the '\n's and '\r's to the extent that I changed the blank spaces to letters: function spam_scrubber($value) { //Create spam scrubber array.............. $very_bad = array('to:' , 'cc:' , 'bcc:' , 'content-type:' , 'mime-version' , 'multipart-mixed' , 'content-transfer-encoding:'); //For loop comparing email text to bad words....... foreach ($very_bad as $v) { //Look for bad word using stripos to ID the characters in the string. It will return a blank if found...... if (stripos($value, $v) !== false) { return 'AA'; } } $value = str_replace(array( "\r" , "\n" , "%0a" , "%0d"), 'BB' , $value); echo $value; return trim($value); } which made it easier to see what was going on. Thus my enquiry that included some '\n's and '\r's went through the email system WITH the '\n's and '\r's. So I then changed the code to (in red): function spam_scrubber($value) { //Create spam scrubber array.............. $very_bad = array('to:' , 'cc:' , 'bcc:' , 'content-type:' , 'mime-version' , 'multipart-mixed' , 'content-transfer-encoding:'); //For loop comparing email text to bad words....... foreach ($very_bad as $v) { //Look for bad word using stripos to ID the characters in the string. It will return a blank if found...... if (stripos($value, $v) !== false) { return 'AA'; } } $value = str_replace(array( "\\r" , "\\n" , "%0a" , "%0d"), 'BB' , $value); return trim($value); } and it works just fine. Thought I should let you know. Regards Max
  11. OK, have just got it. There is no need to use YEAR() function as the Date column will accept SELECT * FROM Timeline WHERE Date LIKE '%$i%' SORT BY Date ASC All working now. www.gssr.es/timeline.php Adios!
  12. Hi Larry and everyone, I have really painted myself into a corner with this one. Above is the database that I created for a timeline. The issue is that not all of the dates at my disposition have days and months. Some are just years. Hence, I had to make a separate column for years only. What I want to do is create a timeline using tables so that any year that has either a YYYY date and/or a YYYY-MM-DD date appears in chronological order. I tried it with a for loop starting at $i = 1700 - 2000 which works for the first year but the while ($enquiry3 = @mysqli_fetch_array($enquiry2)) { will only iterate once and then stops. The alternative is to use MySQL such as: for($i = 1700; $i <= 2000; i++) { $enquiry = "SELECT * from Timeline WHERE Year = $i ORDER BY Year ASC" } which works OK for getting the year only files. Then we need to get the full date files so we try: for($i = 1700; $i <= 2000; i++) { $enquiry = " SELECT * from Timeline WHERE Date = YEAR($i, %Y) ORDER BY Date ASC" } ....but the date function doesn't seem to work. Any ideas??? Regards Max
  13. Hi all, Well, finally solved it. What really complicated matters was that my browser was converting the (correct) answer from php back to html entities! This led me to believe that php wasn't actually doing anything. So, it has all come down to two lines of code:.... $search = trim($_POST['Search']); $search = htmlentities($search); Now, php can do the MySQL search and now finds matches. To get round the problem on the test script I added as the first line: header('Content-Type: text/plain'); .....so now my test script works as well. Best regards and thank you, Larry. Max
  14. Hi Larry, html : <meta charset="utf-8"> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> MySQL: Collation on all relevant columns and tables are utf-8_unicode_ci When I use phpMyAdmin the accented characters show as ASCII entities (i.e. á = &aacute;), which is what I want. It all works fine: Inauguraci&oacute;n. Bendici&oacute;n de las locomotoras - &Aacute;guilas. Marzo 1890. - from phpMyAdmin becomes..... Inauguración. Bendición de las locomotoras - Águilas. Marzo 1890. The entities in MySQL have been converted to accented text as wanted. The problem seems to be that php isn't recognising the accented characters and thus not converting them to ASCII entities for the search engine that I am trying to create. Thanks as always for your time and help.
  15. I have come across htmlentities and htmlspecialchars but neither seems to work. Here is a Q&D test: <?php if(isset($_POST['char'])) { $char = $_POST['char']; $char2 = htmlentities($char); echo 'Answer: ' . $char . '<br /><br />'; echo $char2; } echo '<form action = "char_test.php" method = "post"> <input type = "text" name = "char" size = "6"> <input type = "submit" name = "submit" value = "Search!" /> </form>'; if I entered á then I would expect the answer to be: Answer: á &aacute; but I get: Answer: á á This goes for all of the characters that I have tried. Surely php wouldn't put something in their manual that doesn't work?
  16. Hi Larry and everyone, I'm still using your book as php is still reducing me to tears. Here is the problem: I have created a large database in English and Spanish. In spite of setting the MySQL db to UTF-8 it still returns nonsense characters with eg accented 'a', so I have been entering all of the text with accents as for example á = &aacute;, Ú = &Uacute;, ñ = &ntilde; as the only way to guarantee that they print correctly when called. The problem is that when a Spaniosh speaker does a search, then they will search for eg 'Estación' not 'Estaci&oacute;n. The php if conditional doesn't recognise accented characters so I need to parse each word letter by letter and convert any accented character to its ASCII decimal to then convert it to the ASCII entity i.e. 'á' => &225; => &aacute; to present to MySQL. I can't find a converter in the turgid php manual so am stuck. I have re-read your chapter 'Making Universal Sites' but have now resorted to coming home to daddy. Thanks Max
  17. The words are fact. I will look at including regular exressions in the glob(). Regards Max
  18. Further to the above comment, I have stumbled across something called 'imagick' which is part of the PHP domain. The PHP manual says something like this: bool Imagick::resizeImage ( int $columns , int $rows , int $filter , float $blur [, bool $bestfit = false ] ) ..and gives examples like this: <?php function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom) { //The blur factor where > 1 is blurry, < 1 is sharp. $imagick = new \Imagick(realpath($imagePath)); $imagick->resizeImage($width, $height, $filterType, $blur, $bestFit); $cropWidth = $imagick->getImageWidth(); $cropHeight = $imagick->getImageHeight(); if ($cropZoom) { $newWidth = $cropWidth / 2; $newHeight = $cropHeight / 2; $imagick->cropimage( $newWidth, $newHeight, ($cropWidth - $newWidth) / 2, ($cropHeight - $newHeight) / 2 ); $imagick->scaleimage( $imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4 ); } header("Content-Type: image/jpg"); echo $imagick->getImageBlob(); } ?> ...which I can't get to work. Larry - perhaps this could be a subject for your next book? Last time I suggested a book, you brought out the excellent (but headache inducing ) Javascript - Develop and Design, which I was pleased to buy but had to read about 5 times for it to start to sink in. Old dogs and new tricks??? I'm sure it would be a good seller. You certainly have a way of explaining very complex subjects.
  19. Another question for Larry. I would like to offer a library of all of the thousands of images that I have in my raw data directory by displaying thumbnails. I know I can use: <a href = "images/raw/yadayada.jpg" target = "_blank"><img style = "width: 100px;" src = "images/raw/yadayada.jpg" .... /> </a> but this will involve huge overheads as it will mean downloading approx 1Mb images and then resizing them in the browser, so I would prefer to resize the images in PHP before downloading them, but I can't find any reference to this in the PHP manual, or the PHP GD manual. Any advice would be much appreciated. Max
  20. Just spotted a problem with the script - it is only checking files with the extension .jpg, not .JPG. Have changed: //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; to: //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.*'; - can't really see any neat way around it. I suppose I could run it twice, once with .jpg and then with .JPG, then run the .JPGs through strtolower and then combine them in the $getlisting array to then be compared with the raw files. Any comments please.
  21. Hi Larry I thought that I'd post this as it might help other php-ers. I have a website which has many images. To facilitate the download of images, I save a reduced image under a directory name e.g. images/activities/P3451098.jpg for thumbnails and slideshows as well as the full size in e.g. images/raw/P3451098.jpg. Then I can offer an enlarged image using <a href = ***><img src...... target = "_blank"> etc. The problem is that as I send the images up using FTP (Filezilla) I can't be sure if all of the reduced images have the corresponding full sized images thanks to advanced dementia. Therefore, I have written a short routine to compare the two directories.... COMMENTS: 1) I was confused at first as to why it didn't work properly until I discovered that glob() is case sensitive, so that it wasn't finding .JPGs so had to run it twice (there is a variety of both depending on which camera they came from). 2) The search routine is not very elegant as it runs through all of the raw files even though it may have found a match in the first file. 3) I know that I could use glob(images/raw/*.*) instead of glob(images/raw/*.*) and in this case it wouldn't make any difference as all files in these directories are .jpgs - it just seems more precise to use *.jpg. I would appreciate any comments from anybody..... <?php //Declare variable $found to avoid undefined variable errors $found = "No"; //Call header which handles security and error messages include ('adminheader.php'); //Create an array $images which lists all of the relevant image directories on the server.. $images = array('4X4', 'activities', 'almonds', 'alojamiento', 'altiplano', 'archery', 'area', 'artifacts', 'baza', 'castillejar', 'castril', 'caving', 'fiestas', 'flowers', 'history', 'huescar', 'kayaking', 'index', 'markets', 'mountaineering', 'mountains', 'museums', 'photography', 'puebla', 'rafting', 'village', 'wildlife', 'activities/activities', 'activities/caving', 'activities/kayaking', 'activities/mountaineering', 'activities/outdoors', 'activities/rafting'); //Create array $raw which will be a listing of all of the large image files on the server $raw = glob('images/raw/*.jpg'); $raw2 = glob('images/raw/*.JPG'); //Work through the $images array so as to compare whether there is a large matching file in the 'raw' directory... foreach($images as $key => $category) { //Start with a header to ID each category.... echo 'CATEGORY:... ' . $category . '<br /><br />'; //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; //create an array of the files in this category.. $listing = glob($getlisting); //Run through the $raw array to see if it contains a file that matches the file in the category... foreach($listing as $key => $value) { //Create variable to use in str_replace.. $directory = 'images/' . $category . '/'; // Remove the unwanted directory details.... $value = str_replace($directory, "", $value); //Reduce any JPGs to jpgs... $value = strtolower($value); //Run through the $raw array to find a match.. foreach($raw as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //Run through the $raw array to find a match.. foreach($raw2 as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //If small and large files don't match, then print out the filename .. if ($found != "Found") { echo $value . "<br /><br />"; } //reset $found to "Not found".. $found = "No"; } //Close individual Category foreach echo "<br /><br />"; } //Close all category foreach echo "ALL DONE!"; include ('footer.php'); ?>
  22. STOP PRESS!! Darn it! I have just found a much easier way, thanks to your book (Chapter 2):.... Create array of all jpg files on server in the images/activities/activities directory: $listing = glob("images/activities/activities/*.jpg"); Use 'shuffle() to change the order of the jpg files in the array: shuffle($listing); Use 'foreach()' to trawl through the array to extract the filenames: foreach($listing as $key => $value) { This is a bit of js: echo '<div class="mySlides fade"> <img src = "' . $value . '" style=" display: block; margin: auto; width:80%; border-style: solid; border-width: 2px; border-color: black; vertical-align: top;" alt = "Sorry - image missing." /> </div>'; echo '<div style="text-align:center"> <span class="dot"></span> </div>'; $repeat = 1; } That also solves the issue of repeats. KISS - keep it simple, STOOPID! Regards Max
  23. Hi Larry. I am sure that this has been done elsewhere, but I thought I would share it with you anyway. I have a website that displays a slideshow of images of where I live ( www.beautifulcastril.com ). To make things cleaner and quicker, I just upload the jpgs to the server via Filezilla and then, in the program use glob() to bring their filenames into an array. I then used to pass through the array using foreach() to display the images automatically using js and CSS as per your book Chapter 2. The irritating thing was that they always came out in the same order so I have changed the php to randomize the image order. I have added comments in red specifically for this post:.... <?php include ('header.php'); ?> <table style = "width: 100%; border: 0; table-layout: fixed;"> <tr><td style = "width: 20%"><a href="castril.php"><img src = "images/village/P9040321.jpg" style = "width: 100%;" alt = "Sorry - image missing" title = "Click here" /></a></td><td style = "width: 20%;"><a href="castril.php" id = "area1">Castril town</a></td><td rowspan = "6" style = "vertical-align: top; margin: auto;"> This starts the js/CSS: <div class="slideshow-container" style = "margin: auto;"> <?php Get the images from the server and put them into an array called '$listing' using glob(): $listing = glob("images/area/*.jpg"); Find out how many files there are and subtract 1 as they start with 0: $arrlength = count($listing) - 1; Do a for/next loop to run through the whole array (from 0 to the length of the array - 1: for($x = 0; $x < $arrlength; $x++) { Get a random number between 0 and array length - 1 using mt_rand() which apparently is quicker than rand(): $random_keys = mt_rand(0, $arrlength); $value is the filename related to the random number obtained above: $value = $listing[$random_keys]; Use some js to take the filename and produce the image (see below): echo '<div class="mySlides fade"> <img src="' . $value . '" style="display: block; margin: auto; width:80%; border-style: solid; border-width: 2px; border-color: black; vertical-align: top;" alt = "Sorry - image missing"> </div>'; echo '<div style="text-align:center"> <span class="dot"></span> </div>'; $repeat = 1; //Can't remember what this does!!! } ?> </div> <br> Now for the js: <script> var slideIndex = 0; showSlides(); function showSlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i < slides.length; i++) { slides.style.display = "none"; } slideIndex++; if (slideIndex> slides.length) {slideIndex = 1} for (i = 0; i < dots.length; i++) { dots.className = dots.className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; setTimeout(showSlides, 3000); // Change image every 3 seconds } </script> etc. etc....... COMMENTS: 1) I know that my CSS is clumsy and I should use id = "..." linked to a CSS file to make it cleaner and not be passing the same CSS code to the browser. Will sort it. 2) The mt_rand() function doesn't check that it hasn't supplied that number before and perhaps I should add a routine that looks at images that have been displayed and to inhibit the repeat(s) but it would make the code a bit clunky, I think. Something like: - Create an array In the 'for' loop: Second loop to: - Pass through array to see if $random_keys == $myarray() - If 'yes' then delete $random_keys - If 'No' then add $random_keys to array Return to loop...... In reality, if there are more than a few images, it doesn't really notice. I hope this has been of help. Regards Max
  24. That's a great question, Larry. Actually, every other website that I have looked at just terminates the text irrespective of where there is a space. e.g. Lovely property, not overpriced at all, new ro..........more... I have a bad habit of over-thinking these things. All sorted now.
×
×
  • Create New...