Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Max's Achievements


Rookie (2/14)

  • First Post Rare
  • Collaborator Rare
  • Conversation Starter Rare
  • Week One Done Rare
  • One Month Later Rare

Recent Badges



  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.
  • Create New...