Jump to content
#FlattenTheCurve ×

Strider64

Members
  • Content Count

    255
  • Joined

  • Last visited

  • Days Won

    1

Strider64 last won the day on April 28 2014

Strider64 had the most liked content!

Community Reputation

14 Neutral

About Strider64

  • Rank
    Advanced Member
  • Birthday 08/28/1964

Contact Methods

  • Website URL
    http://www.pepster.com

Profile Information

  • Gender
    Male
  • Location
    A burb of Detroit, MI

Recent Profile Visitors

5,149 profile views
  1. The first place I would go to is this website https://caniuse.com/
  2. Another way of doing is using Javascript and PHP that way it doesn't matter what the user does on the website as the timer will still keep on chiming away. Here's the javascript: const getTimeRemaining = (endtime) => { var t = Date.parse(endtime) - Date.parse(new Date()); var seconds = Math.floor((t / 1000) % 60); var minutes = Math.floor((t / 1000 / 60) % 60); var hours = Math.floor((t / (1000 * 60 * 60)) % 24); var days = Math.floor(t / (1000 * 60 * 60 * 24)); return { 'total': t, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds }; }; const myClock = (id, endtime) => { var clock = document.getElementById('game' + id); var daysSpan = clock.querySelector('.day' + id); var hoursSpan = clock.querySelector('.hour' + id); var minutesSpan = clock.querySelector('.minute' + id); var secondsSpan = clock.querySelector('.second' + id); function updateClock() { var t = getTimeRemaining(endtime); daysSpan.textContent = t.days; hoursSpan.textContent = ('0' + t.hours).slice(-2); minutesSpan.textContent = ('0' + t.minutes).slice(-2); secondsSpan.textContent = ('0' + t.seconds).slice(-2); if (t.total <= 0) { clearInterval(timeinterval); } } updateClock(); var timeinterval = setInterval(updateClock, 1000); }; function ajaxRoutine() { var grabDate = "myDate=endDate"; var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { //console.log('readyState: ' + xhr.readyState, 'xhr.status: ' + xhr.status); if (xhr.readyState === 2) { //console.log(xhr.status); if (xhr.status === 410) { gameover(); } } if (xhr.readyState === 4 && xhr.status === 200) { var data = JSON.parse(xhr.responseText); console.log('data', data); console.log('data.home', data.home); var opening_day_home = new Date(Date.parse(data.home)); var team = data.home_opponent + " -vs- " + data.team; document.getElementById("countdown_team").textContent = team; document.getElementById("opening").textContent = data.home_display; team = data.team + " -vs- " + data.away_opponent; document.getElementById("countdown_team2").textContent = team; document.getElementById("opening2").textContent = data.away_display; myClock(1, opening_day_home); var opening_day_away = new Date(Date.parse(data.away)); myClock(2, opening_day_away); } }; // End of Ready State: xhr.open('POST', 'countdown_date.php', true); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.send(grabDate); } ajaxRoutine(); the php <?php /* Makes it so we don't have to decode the json coming from javascript */ header('Content-type: application/json'); $endDate = filter_input(INPUT_POST, 'myDate'); if ($endDate === 'endDate') { $data['team'] = "Tigers"; $home = new DateTime('2020-03-30 13:10:00', new DateTimeZone("America/Detroit")); $data['home'] = $home->format("Y/m/d H:i:s"); $data['home_display'] = $home->format("l - F j, Y"); $data['home_opponent'] = "Royals"; $away = new DateTime('2020-03-26 13:10:00', new DateTimeZone("America/Detroit")); $data['away'] = $away->format("Y/m/d H:i:s"); $data['away_display'] = $away->format("l - F j, Y"); $data['away_opponent'] = "Indians"; output($data); } function errorOutput($output, $code = 500) { http_response_code($code); echo json_encode($output); } /* * If everything validates OK then send success message to Ajax / JavaScript */ function output($output) { http_response_code(200); echo json_encode($output); } and the HTML <div id="countdownContainer"> <div class="teams"> <h1 id="countdown_team2"></h1> <h2 id="opening2"></h2> </div> <div id="game2"> <figure class="box"> <div class="day2"></div> <figcaption>Days</figcaption> </figure> <figure class="box"> <div class="hour2"></div> <figcaption>Hours</figcaption> </figure> <figure class="box"> <div class="minute2"></div> <figcaption>Minutes</figcaption> </figure> <figure class="box"> <div class="second2"></div> <figcaption>Seconds</figcaption> </figure> </div> <div class="teams"> <h1 id="countdown_team"></h1> <h2 id="opening"></h2> </div> <div id="game1"> <figure class="box"> <div class="day1"></div> <figcaption>Days</figcaption> </figure> <figure class="box"> <div class="hour1"></div> <figcaption>Hours</figcaption> </figure> <figure class="box"> <div class="minute1"></div> <figcaption>Minutes</figcaption> </figure> <figure class="box"> <div class="second1"></div> <figcaption>Seconds</figcaption> </figure> </div> </div> The nice thing about this is it is written in vanilla javascript no jQuery needed. The code isn't the tightest as I just put it up for the current baseball season. Go Tigers!
  3. Google gives a good example on how to setup ReCaptcha V2 and even you gives an option where you can test it on a local server. Here is the link -> https://developers.google.com/recaptcha/docs/display There are even tutorials on how to setup up that might help you the ReCaptcha backup and running -> Here's just one link of many https://www.kaplankomputing.com/blog/tutorials/recaptcha-php-demo-tutorial/ Here's my code that I think is broken done pretty good (I think?) -> /* The Following to get response back from Google recaptcha */ $url = "https://www.google.com/recaptcha/api/siteverify"; $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL); $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer); $recaptcha_data = json_decode($response); /* The actual check of the recaptcha */ if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) { $success = "Mail was sent!"; $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $send = new Email($data); } else { $success = "You're not a human!"; // Not on a production server: }
  4. Another good 3rd party mailer is Swiftmailer and I found it easy to setup.
  5. I usually do a mockup of my HTML/CSS before implementing PHP that way if I run into problems I know the likely culprit is my PHP code. Heres a small CMS that I did for my website: <div id="gallery" class="picture-box" data-total="<?php echo count($journal); ?>" data-current="" > <?php $counter = 1; foreach ($journal as $records) { $cms = (object) $records; echo '<article class="cms" id="page' . $counter . '">' . "\n"; echo '<h2>' . $cms->heading . '<span class="subheading">by ' . $cms->author . ' on ' . $cms->date_added . '</span></h2>' . "\n"; echo '<a class="myLightBox" id="image' . $counter . '" href="' . $cms->image_path . '" title="Picture Gallery" data-picture="' . $counter . '" data-exif="' . (($cms->Model) ? $cms->Model . ' --- ' . $cms->FocalLength . ' ' . $cms->Aperture . ' ' . $cms->ISO . ' ' . $cms->ExposureTime : null) . '">' . '<img class="blogBox" src="' . $cms->thumb_path . '" alt="Picture for Journal Entry">' . "</a>\n"; echo "<hr>\n"; echo '<p>' . nl2br($cms->content) . "</p>\n"; echo '</article>' . "\n"; $counter += 1; } ?> </div> And you can see the results on my website link: I find it it much simpler and less frustrating to do it this way. BTW that is basically what is said in the other responses.
  6. I personally do the following and call it a day: define("APP_ROOT", dirname(dirname(__FILE__))); define("PRIVATE_PATH", APP_ROOT . "/private"); define("PUBLIC_PATH", APP_ROOT . "/public"); require_once PRIVATE_PATH . "/vendor/autoload.php"; require_once PRIVATE_PATH . "/security/security.php"; require_once PRIVATE_PATH . "/config/config.php";
  7. I personally find it easier to store the path and the filename in the database table, for example - assets/large/img-photos-1554932472.jpg. Then I simply do <img src="<?php echo $image ?>" width="478" height="1034" alt="">
  8. Well I would check the captcha first then process the email. Here's my little script that does that -> /* The Following to get response back from Google recaptcha */ $url = "https://www.google.com/recaptcha/api/siteverify"; $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL); $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer); $recaptcha_data = json_decode($response); /* The actual check of the recaptcha */ if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) { $success = "Mail was sent!"; $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $send = new Email($data); } else { $success = "You're not a human!"; // Not of a production server: } The $send = new Email($data) is my email process, if your form was working before then just do something like that.
  9. Wouldn't you be better off using a 'switch' statement? switch ($a) { case "one": $variable = 'poor'; break; case "two": $variable = 'good'; break; case "three": $variable = 'very good'; break; case "four": $variable = 'excellent'; break; default: $variable = 'invalid response'; } To me it would be easier to make sense of the logic and to modify.
  10. Here's might be another way in achieving the same thing? I personally just CSS highlight the day (you could also make the font bolder or what have you) by doing something like the following. protected function currentDays() { //$this->result = $this->checkForEntry($this->current->format("Y-m-d")); if ($this->now->format("F j, Y") === $this->current->format("F j, Y")) { $this->calendar .= "\t\t" . '<td class="background">'; } else { $this->calendar .= "\t\t" . '<td>'; } $this->calendar .= '<a href="' . $this->pageName . '?date=' . $this->current->format('Y-m-d') . '">' . $this->current->format("j") . '</a>'; $this->calendar .= "</td>\n"; } To understand it better think of $this-> as $ Here's the full Class that I have been tinkering with over the last 3 years or so. <?php namespace Library\Calendar; use DateTime; use Library\Database\Database; //use Library\Calendar\Location; class Calendar { protected $date = \NULL; protected $page = 0; public $output = \NULL; protected $username = \NULL; protected $user_id = \NULL; protected $query = \NULL; protected $stmt = \NULL; protected $urlDate = \NULL; protected $sendDate = \NULL; protected $prev = \NULL; public $current = \NULL; protected $next = \NULL; protected $month = \NULL; protected $day = \NULL; protected $year = \NULL; protected $days = \NULL; protected $currentDay = \NULL; protected $highlightToday = \NULL; protected $highlightHoliday = \NULL; protected $isHoliday = \NULL; protected $prevMonth = \NULL; protected $nextMonth = \NULL; public $selectedMonth = \NULL; public $n = \NULL; public $result = \NULL; protected $calendar = \NULL; // The HTML Calender: protected $alphaDay = [0 => "Sun", 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat"]; protected $smallDays = [0 => "S", 1 => "M", 2 => "T", 3 => "W", 4 => "T", 5 => "F", 6 => "S"]; protected $imporantDates = []; protected $myPage = \NULL; protected $now = \NULL; protected $monthlyChange = \NULL; protected $pageName = "index"; /* Constructor to create the calendar */ public function __construct($date = null) { $this->selectedMonth = new \DateTime($date, new \DateTimeZone("America/Detroit")); $this->current = new \DateTime($date, new \DateTimeZone("America/Detroit")); $this->current->modify("first day of this month"); $this->n = $this->current->format("n"); // Current Month as a number (1-12): } public function fileLocation() { return $this->returnLocation(); } public function set_user_id($user_id = -1) { $this->user_id = $user_id; } public function checkIsAValidDate($myDateString) { return (bool) strtotime($myDateString); } public function changeMonth($setDate) { self::__construct($setDate, $size); } public function phpDate() { $setDate = filter_input(INPUT_GET, 'location', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $valid = $this->checkIsAValidDate($setDate); if (isset($setDate) && strlen($setDate) === 10 && $valid) { self::__construct($setDate); } } public function returnDate() { return $this->selectedMonth; } public function getHolidayNames() { return $this->isHoliday->checkForHoliday($this->selectedMonth->format('Y-m-j')); } /* * Not Currently Being Used: */ protected function checkForEntry($calDate) { $blog = "blog.php"; $db = Database::getInstance(); $pdo = $db->getConnection(); $this->username = isset($_SESSION['user']) ? $_SESSION['user']->username : \NULL; $this->query = 'SELECT 1 FROM cms WHERE page_name=:page_name AND DATE_FORMAT(date_added, "%Y-%m-%d")=:date_added AND user_id=:user_id'; $this->stmt = $pdo->prepare($this->query); $this->stmt->execute([':page_name' => $blog, ':date_added' => $calDate, ':user_id' => $this->user_id]); $this->result = $this->stmt->fetch(); /* If result is true there is data in day, otherwise no data */ if ($this->result) { return \TRUE; } else { return \FALSE; } } /* Highlight Today's Date on Calendar */ protected function currentDays() { //$this->result = $this->checkForEntry($this->current->format("Y-m-d")); if ($this->now->format("F j, Y") === $this->current->format("F j, Y")) { $this->calendar .= "\t\t" . '<td class="background">'; } else { $this->calendar .= "\t\t" . '<td>'; } $this->calendar .= '<a href="' . $this->pageName . '?date=' . $this->current->format('Y-m-d') . '">' . $this->current->format("j") . '</a>'; $this->calendar .= "</td>\n"; } /* Draw Days (make Table Cells) on Calendar */ protected function drawDays() { $this->now = new \DateTime("Now", new \DateTimeZone("America/Detroit")); $this->calendar .= "\t<tr>\n"; $x = 1; while ($x <= 7) { if ($this->selectedMonth->format('n') === $this->current->format('n')) { $this->currentDays(); } else { $this->calendar .= "\t\t" . '<td class="fade">' . $this->current->format("j") . '</td>' . "\n"; } $this->current->modify("+1 day"); $x += 1; } $this->calendar .= "\t</tr>\n"; } protected function heading() { $this->monthlyChange = new DateTime($this->current->format("F j, Y")); $this->monthlyChange->modify("-1 month"); $this->prev = $this->monthlyChange->format("Y-m-d"); $this->monthlyChange->modify("+2 month"); $this->next = $this->monthlyChange->format("Y-m-d"); /* Create heading for the calendar */ $this->calendar .= "\t<tr>\n"; $this->calendar .= "\t\t" . '<th class="tableHeading" colspan="7">'; $this->calendar .= '<a data-pos="prev" class="prev-left" href="' . $this->pageName . '-' . $this->prev . '"><</a>'; $this->calendar .= $this->current->format('F Y'); $this->calendar .= '<a data-pos="next" class="next-right" href="' . $this->pageName . '-' . $this->next . '">></a>'; $this->calendar .= "</th>\n"; $this->calendar .= "\t</tr>\n"; } protected function display($pageName) { $this->pageName = $pageName; /* Create the table */ $this->calendar .= '<table class="calendar">' . "\n"; $this->heading($this->pageName); /* Create days of the week heading (columns) */ $this->calendar .= "\t<tr>\n"; for ($x = 0; $x <= 6; $x++) { $this->calendar .= "\t\t<th>" . $this->smallDays[$x] . "</th>\n"; } $this->calendar .= "\t</tr>\n"; /* Generate Actual Days of the Week */ $this->current->modify("last sun of previous month"); /* * Output 7 rows (49 days) guarantees an even calendar. */ $num = 1; while ($num < 7) { $this->drawDays(); $num += 1; } /* Close the HTML tags */ return $this->calendar .= "</table>\n"; } public function generateCalendar(string $pageName = "index") { return $this->display($pageName); } } Except for the top part where I declare my variables (some of them not being even used) the code I think is pretty good and is free to use, modify or just look at. I know it's written in OOP, but it might be of some value? You can see this can in action at https://www.pepster.com/
  11. Not to harp on it, but my IDE (Netbeans) is always flagging me to use === instead of ==, so it is rare that == should be used. I think the only time I had this come into play (==) is when I was developing an online php calendar and even then it was used very minimal. There are a lot of times a person who is typing on a fly that typing = will be very easy to do. I agree you should use == when should it is actually called for and I don't see many cases where that comes in play. Though using a good IDE is better than using an old trick, but in this case I can't see where this particular old trick will lead a person astray until he or she is better knowledgeable in PHP. I know one instance it actually got me to slow down and think when I saw $row = $stmt->fetch(PDO::FETCH_OBJ) in a while loop and realized that was supposed to be like this when I first started learning PHP.
  12. Someone told me an old trick on another forum (He passed away about a year ago) to use === when doing a comparison that way if you accidentally type == it will still work. Very rarely will you have to use == instead of === (or vice versa) and just remember the === operator actually checks to see if the left and right values are equal, and also checks to see if they are of the same variable type (like whether they are both booleans, ints, etc.). The == just cares if both the left and right values are equal.
  13. I'm in the process of redoing my login scripts to add better security and I will eventually post it on my Github account (https://github.com/Strider64) as a repository once I have it working. With that said I would check into password_hash() http://php.net/manual/en/function.password-hash.php and password_verify http://php.net/manual/en/function.password-verify.php this takes care of encryption and salting for you.
  14. I use forums like this to avoid writing obsolete PHP code and there are a lot of obsolete tutorials out on the web. Jacques1 I find will help a noob from wasting his/her time by writing bad PHP code. I find going to the latest edition of a PHP Book is the way to go when learning PHP and PHP OOP. I have found Larry Ullman to be a good author to bridge the gap between procedural and OOP. I also find having a strong grasp of HTML/CSS helps out tremendously before even attempting PHP (procedural or OOP), for if you don't then your will struggle with PHP. It also helps to have basic knowledge of a programming language even if it is basic. I think my very first programming language was Fortran in college in the early 80s. For all programming language have the basic programming structure (if statements, loops, arrays, etc...). I'm finally getting the handle on PHP OOP myself, but I don't even consider myself an expert. I would probably go as far to I'm at advanced level, but even then there are times I have my doubts that I'm even that. My point is the goal of writing OOP in my opinion is to have classes that are very portable from one web project to another without have to change anything in the classes or very minimal changes. I have this one class Calendar that I have develop that I simply move over to the current project and the only thing I have to change is the CSS. The classes will also save you a lot of unnecessary code in your projects and save you time in the development stage. A lot of people just learn the minimal amount of PHP OOP and use a framework to do the heavy lifting. There's nothing wrong with that for you're not reinventing the wheel and there are even times employers demand that you use a framework. I personally like writing my own PHP classes and I work for myself so I have that luxury. I also found after obtaining a Graphics Designer degree in computer technology that people critiquing you or telling you the truth is way better than someone sugar coating it because they are afraid of hurting your feelings. I found asking family members or friends is the worst thing you can do when it comes to this. Just my .02 cents.
  15. I developed a calendar in PHP that uses namespaces here that you could use -> https://github.com/Strider64/Website-Development/tree/master/src/Calendar or you could use Google Calendar (I think) that I hear is pretty good. The rest is just manipulating the calendar with Javascript.
×
×
  • 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.