Jump to content

ohno

Members
  • Posts

    127
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ohno

  1. OK, so I made a test script that creates a file and deletes it for the above htaccess code :- RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/site-error.php -f RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f RewriteCond %{SCRIPT_FILENAME} !site-error.php RewriteRule ^.*$ /site-error.php [R=503,L] ErrorDocument 503 /site-error.php The script that makes/deletes the file works fine, what I need to work out now is how to NOT include my admin directory in the above code, otherwise I can't re-enable the site as the whole site shows the error page! ie, I need to be able to still access /admin and all sub directories in it.
  2. I've sorted this now so if there is an SQL error a nice error page is displayed informing the user the site is experiencing a technical issue and will be online again soon. This got me thinking, is there an easy way to display a site maintenance page? So if a DB entry is set to true all requests get redirected to one page? I found this :-https://rimuhosting.com/knowledgebase/creating-a-maintenance-page-for-your-site But I'm not sure how to make a PHP script create or delete the maintenance.enable file?? Or is there a better way to achieve this? Thanks.
  3. Hmmm, the settings are deffo correct so I guess there is more to look into as I didn't get a 500 error. Good point on the other message.
  4. Ok, I got a white screen which I guess was expected? If I comment out this line : - mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); I get this error : - Failed to connect to MySQL: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known Which seems more helpful? (ie, if we have another SQL server error at least we know what the issue is without checking error logging??).
  5. OK, that's done. Would that now avoid the issue that the SQL server problem caused?
  6. Thanks, currently PHP is set to display errors (E_ALL & ~E_NOTICE), are you saying that should be disabled? I'm not a coder (!) but a pro coder did write the code above.
  7. Our hosts had an SQL server error which required the service to be restarted. However, while the site was down the error message gave the DB name, login & password! Fatal error: Uncaught mysqli_sql_exception: Connection refused in /home/domain/public_html/include/database.php:9 Stack trace: #0 /home/domain/public_html/include/database.php(9): mysqli->__construct('127.0.0.1', 'domain_DB, 'PASSWORD!!!', 'DB_USER_NAME!!!') #1 /home/domain/public_html/include/app_top.php(12): DbManager->__construct() #2 /home/domain/public_html/index.php(4): require_once('/home/domain/...') #3 {main} thrown in /home/domain/public_html/include/database.php on line 9 database.php :- function __construct() { mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); if ($this->db->connect_errno) { die("Failed to connect to MySQL: (" . $this->db->connect_errno . ") " . $this->db->connect_error); } Line 9 is $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); Looking at this guide :- https://www.w3schools.com/php/func_mysqli_error.asp Should the code look like this?? function __construct() { mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); if ($this->db->connect_errno) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); exit(); } Thanks
  8. I'll take another look, none of the examples I seemed to find showed how this could be done though. Thanks
  9. This works but doesn't add any hours outside of the whole days :- $elapsed = $d1->diff(new DateTime())->days * 24 * 60; eg, if the elapsed time is 7 days two hours it gives 10080 minutes instead of 10200.
  10. On a similar note, can the date string be converted to minutes rather than days? (in PHP that is). I did try $elapsed = $d1->diff(new DateTime())->i ;
  11. Works a treat, thanks
  12. Hi, I have this code :- $datestarted = $row['datestarted']; $datestart=date("l d/m/Y @ H:i:s",strtotime($datestarted)); Which is been echo'd like this :- echo ' <tr align="center"'.$rowbackground.'> <td>'.$datestart.'</td> <td align="center"> '; So for example I get this output :-Sunday 18/04/2021 @ 10:45:26 The data in the DB for the above is stored like this :-2021-04-18 10:45:26 What I'd like to do is also echo how many days ago this date was, all of the examples I've tried don't seem to work though?
  13. To add, I tried the latest version of the script : - https://github.com/tuupola/lazyload#changelog & tried modifying this code : - let images = document.querySelectorAll(".example"); lazyload(images); To the span name but still nothing, the rendered HTML of the image is like this :- <span class="thumb" style="background-image: url(https://www.example.com/images/thumbnails/example.jpg);"></span> I wonder if the lack of height & width maybe causing it? (this info is in the CSS file but I'll try adding it inline now)
  14. Hi, I've implemented lazy loading on my website using this guide : - https://web.dev/codelab-use-lazysizes-to-lazyload-images/ However I can't get the last bit of code to work! Basically I have images that are in a span tag loaded as a background image, I have this is the CSS : - .blocks1 .block a span.thumb { width: 120px; height: 90px; background-repeat: no-repeat; background-position: center; background-size: contain; margin: 0 auto } The page uses this tpl file for the images : - {section name=c loop=$cats->mCats} <div class="block"><a class="clearfix" href="{$smarty.const.SITE_ROOT}/{$cats->mCats[c].menulinktext}/"><span class="thumb" style="background-image: url({$smarty.const.SITE_ROOT}{$smarty.const.IMG_DIR}/thumbnails/{$cats->mCats[c].img_category});"></span><span class="info">{$cats->mCats[c].name|escape:'htmlall'|widont}</span></a></div> {/section} I thought this script may have worked : - https://appelsiini.net/2013/lazyload-190/ But I couldn't get that to work either. Any idea's whether this can be done & if so how?! Many thanks for any help on this one
  15. I now get this error (in PHP8) Could not execute MySQL query: SELECT * FROM blog_posts WHERE status<>'Hidden' ORDER BY publish_date DESC LIMIT -1,1 . Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-1,1' at line 4 && [16-Feb-2021 19:49:52 Europe/London] PHP Warning: Undefined variable $search in /home/public_html/blog/meta.php on line 50 Line 50 of meta.php :- WHERE status<>'Hidden' " .$search . " Which is in this block of code :- $sql = "SELECT * FROM ".$TABLE["Posts"]." WHERE status<>'Hidden' " .$search . " ORDER BY publish_date DESC LIMIT " . ($pageNum-1)*$Options["per_page"] . "," . $Options["per_page"]; $sql_result = sql_result($sql);
  16. When I say "nothing" I just get this error on the page :- Fatal error: Uncaught TypeError: Unsupported operand types: string - int in /home/public_html/blog/blog.php:614 Stack trace: #0 {main} thrown in /home/public_html/blog/blog.php on line 614 Line 614 :- $prev = $page - 1; The whole block of code is this :- // pagination query and variables starts $sql = "SELECT count(*) as total FROM ".$TABLE["Posts"]." WHERE status<>'Hidden' " .$search; $sql_result = sql_result($sql); $row = mysqli_fetch_array($sql_result); mysqli_free_result($sql_result); $total_pages = $row["total"]; $adjacents = 2; // the adjacents to the current page digid when some pages are hidden $limit = $Options["per_page"]; //how many items to show per page $page = ''; if(isset($_GET["p"]) and $_GET["p"]!='') { $page = (int) abs(SafetyDB(urldecode($_GET["p"]))); } if(isset($page) and $page!='') { $start = ($page - 1) * $limit; //first item to display on this page } else { $start = 0; //if no page var is given, set start to 0 } /* Setup page vars for display. */ if (isset($page) and $page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 // pagination query and variables ends
  17. Well, I can only dump that variable when running PHP7.4 as if that code is left in place (the code I commented out as above) with PHP8 I get nothing! At the moment PHP8 is looking like a stack of work as a lot of things have broken when testing with 8! Even LiveZilla which we use for online chat (which sadly closed last year) breaks when switching to 8. Beginning to think it's not worth the hassle but 7.4 will only have security updates for another 18 months or so.
  18. I'm getting this error for a blog script that is on my site :- PHP Fatal error: Uncaught TypeError: Unsupported operand types: string - int The line in questions is this :- $prev = $page - 1; If I comment out this block of code the blog appears (with other errors, but I'll move on to those if I can fix this first!). /* Setup page vars for display. */ if (isset($page) and $page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 Any idea's on what's needed to fix this script? I've contacted the original author but they haven't got back to me, I guess PHP8 maybe a little too new for them. Thanks for any help....
  19. To add, some delivery methods have delivery on a Saturday.
  20. Sorry, I don't follow? Probably because I've been staring at this all day!!
  21. Pasted on phone and can't see how to format code on a mobile browser?? Sorry!
  22. I thought I’d sorted this but alas, no <?php class BoDelivery { public function EstimatedDaysWithHoliday($off, $days, $saturday) { require_once FILE_ROOT . '/data_objects/do_settings.php'; $doSettings = new DoSettings(); // Holidays that happen every year in MM-DD format. $holidays_every_year=($doSettings->GetSetting(51)); $date_array= explode(',',$holidays_every_year); $holidays_every_year= array(); foreach ($date_array as $value) { trim($value); if (strtotime($value)=== false ){ //bad date }else{ $holidays_every_year[] = date('m-d',strtotime($value)); } }; // Holidays that happen only ONCE in YYYY-MM-DD format. $holidays_by_year=($doSettings->GetSetting(50)); $date_array= explode(',',$holidays_by_year); $holidays_by_year= array(); foreach ($date_array as $value) { trim($value); if (strtotime($value)=== false ) { //bad date }else{ $holidays_by_year[] = date('Y-m-d',strtotime($value)); } }; $today = date("N"); // Weekday - number 1-7 $now = strtotime("now"); // Unix $off_array = explode(":", str_replace(".", ":", $off)); $off_unix = mktime($off_array[0], $off_array[1], "00", date("n"), date("j"), date("Y")); $sending_days_from_now = 0; if ($now > $off_unix) { $sending_days_from_now++; } $sending_day = $today + $sending_days_from_now; switch ($sending_day) { case 6: $sending_days_from_now++; $sending_days_from_now++; break; case 7: $sending_days_from_now++; break; } $count5WD = 0; $temp = strtotime("now"); // Todays date if($sending_days_from_now > 0) { $temp = strtotime('+'.$sending_days_from_now.' weekday', $temp); } while($count5WD<$days){ $currentDay = date('N', $temp); if($currentDay == 5 && $saturday) { $next1WD = strtotime('+1 day', $temp); } else { $next1WD = strtotime('+1 weekday', $temp); } $MMDD=date("m-d", $next1WD); $YYYYMMDD=date("Y-m-d", $next1WD); if(!(in_array($MMDD, $holidays_every_year)) && !(in_array($YYYYMMDD, $holidays_by_year))) { $count5WD++; } $temp = $next1WD; }; $next5WD = date("D jS F", $temp); return $next5WD; // + working days, extra day if holiday day is in array } } ?> With the above code it tells me standard delivery will be on Wednesday 26th it should be Tuesday 25th. It all looks correct to me, date is N so a Saturday (today) is 6 & Sunday is 7, the code says add 2 days if a Saturday & 1 if a Sunday but it’s not doing that. Any ideas?
  23. Thanks for replying. Of what I can gather, delivery is always 1 day, $off is the cutoff time for delivery that day, eg, after 4pm that delivery will not ship that day, it will ship the next business day. $standard_days is the number of business days for delivery. $saturday is whether delivery can happen on a Saturday (so if a user orders on a Friday & selects Saturday delivery). But Saturdays should NOT count towards delivery progress for other delivery options. $delay adds day(s) as required to the delivery progress. This is how the function is currently being used :- // Est Delivery $today = date("N"); // Weekday - number 1-7 $now = strtotime("now"); // Unix if ($this->mCart['deliveryoption'] == '0') { $standard_days = 1; $saturday_del = 0; $off = $this->mDoSettings->GetSetting(175); $delay = $this->mDoSettings->GetSetting(47); } else { $delivery = $this->mDoCart->GetPremiumDeliveryInfo($this->mCart['deliveryoption']); $standard_days = $delivery['standarddays']; $saturday_del = $delivery['saturdaydel']; switch ($today) { case 1: $off = $delivery['monoff']; break; case 2: $off = $delivery['tueoff']; break; case 3: $off = $delivery['wedoff']; break; case 4: $off = $delivery['thuroff']; break; case 5: $off = $delivery['frioff']; break; case 6: $off = $delivery['satoff']; break; case 7: $off = $delivery['sunoff']; break; } $delay = 0; } $delivery_days = $this->mBoDelivery->EstimatedDays($off, $standard_days, $saturday_del, $delay); $this->mCart['est_delivery'] = date("D jS F", strtotime("+" . $delivery_days . " days")); I found this script which seems to simplify things a lot but I'm not sure how to code in delivery cut off time for the day or Saturday delivery. <?php $holidayDates = array( '2020-08-19', ); $count5WD = 0; $temp = strtotime("now"); // Todays date while($count5WD<5){ $next1WD = strtotime('+1 weekday', $temp); $next1WDDate = date('Y-m-d', $next1WD); if(!in_array($next1WDDate, $holidayDates)){ $count5WD++; } $temp = $next1WD; } $next5WD = date("D jS F", $temp); echo $next5WD; //Displays next 5 working days ?> Basically, am I better off getting someone to re-code the original script or use the one I found as base for a new one?
  24. I have this block of code that was written by someone years ago :- <?php class BoDelivery { public function EstimatedDays($off, $standard_days, $saturday, $delay) { $today = date("N"); // Weekday - number 1-7 $now = strtotime("now"); // Unix $off_array = explode(":", str_replace(".", ":", $off)); $off_unix = mktime($off_array[0], $off_array[1], "00", date("n"), date("j"), date("Y")); $sending_days_from_now = 0; if ($now > $off_unix) { $sending_days_from_now++; } $sending_day = $today + $sending_days_from_now; switch ($sending_day) { case 6: $sending_days_from_now++; $sending_days_from_now++; break; case 7: $sending_days_from_now++; break; } $sending_day = $today + $sending_days_from_now; // Estimated delivery time $delivery_days = $standard_days; $over_weekends = 0; // Add Delay if ($delay) { $delivery_days = $delivery_days + $delay; } if ($sending_day == 5 && !$saturday) { $delivery_days++; $delivery_days++; $over_weekends++; } $delivery_day = $sending_day + $delivery_days; switch ($delivery_day) { case 6: if (!$saturday) { $delivery_days++; $delivery_days++; $over_weekends++; } break; case 7: $delivery_days++; $over_weekends++; break; } if ($over_weekends == 0 && $delivery_days > 5) { $delivery_days++; $delivery_days++; } $delivery_day = $sending_day + $delivery_days; switch ($delivery_day) { case 13: $delivery_days++; $delivery_days++; $over_weekends++; break; case 14: $delivery_days++; $over_weekends++; break; } $delivery_day = $sending_day + $delivery_days; $delivery_days = $delivery_day - $today; return $delivery_days; } } ?> Which is supposed to calculate the number of days for delivery, taking into account weekends & with a delay variable that we can set. It isn't working as expected, may never have worked(??) or maybe down to PHP upgrades. For example, if today (18th)I set the delay to 2 days the delivery estimate is the 21st (which is correct), if I change the delay to 3 OR 4 it becomes the 24th, 5 then becomes the 26th! I can't get my head around the code at all, I wonder if someone could assist in what may be going on or add comments to the code snippets so I can maybe work it out? Thanks for any help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.