Jump to content

Strider64

Members
  • Posts

    364
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Strider64

  1. Well, when the user first visit a website the token is generated and stored in sessions then when he/she submits his information in a form the token is sent along with the info. That way it has to be her/him that enter the data from that browser and the only way it can theoretically happen to be another user would be that user would have to use the same browser on that computer. For more info check out -> https://owasp.org/www-community/attacks/csrf
  2. You're still trying to paddle upstream without a paddle. My suggestion would to be look at a CURRENT tutorial on adding, updating, and deleting data to a database table. I would also suggest PDO instead of mysqli as I feel it's more robust, but that is a personal preference. I like this PDO tutorial as they do a nice job explaining how PDO works : https://phpdelusions.net/pdo
  3. I probably should had explain better. I would just take a range of dates (for example of week in an array) and loop through the dates. Unless it's important to save the data (which I personally don't there would be) then just store that data in another database table.
  4. If I was tackling the problem I would do something like this: $stmt = static::pdo()->prepare("SELECT count(user_id) FROM users WHERE joined_date = ?"); $stmt->execute(['joined_date']); $result = $stmt->fetchColumn(); return $result; then I would either cycle through the database table with some kind of loop or set up a daily maintenance routine where I store the results. Of course you can do averages or what have you as it's just simple math in either case. The first option is what I would do as I wouldn't have to go about storing and setting up additional stuff.
  5. I find sending NON-HTML emails have a better chance of getting through spam filters than HTML emails. Sure they don't look as flashy, but it's the content that matters. 😉
  6. I personally would make the flow a little easier to follow: here's my example: /* * Database Connection * I would have the PDO database connection in a separate file (Something like inc.pdoConnect.php) * and then call it something like require_once "includes/inc.pdoConnect.php"; */ $db_options = [ /* important! use actual prepared statements (default: emulate prepared statements) */ PDO::ATTR_EMULATE_PREPARES => false /* throw exceptions on errors (default: stay silent) */ , PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION /* fetch associative arrays (default: mixed arrays) */ , PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]; $pdo = new PDO('mysql:host=' . DATABASE_HOST . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD, $db_options); /* End of Connection String */ /* I would personally only be pulling out table column names instead of the wildcard * */ $query = "SELECT * FROM convoy_part WHERE us_convoy=:get_id"; $stmt = $pdo->prepare($query); $stmt->execute([':get_id' => $_GET['id']); // I personally would have something like uniform :convoy_id / $_GET['convoy_id] $result = $stmt->fetchALL(PDO::FETCH_ASSOC); echo "<pre>" . print_r($result, 1) . "</pre>"; // Great way to debug and see what is going on: /* I personally like using the fetch statement over the while statement */ foreach ($result as $results) { $convoy_name = $results['convoy_name']; $convoy_veranstalter = $results['convoy_veranstalter']; $convoy_server = $results['convoy_server']; $convoy_date = $results['convoy_date']; $convoy_adddate = $results['convoy_adddate']; $convoy_language = $results['convoy_language']; $convoy_participants = $results['convoy_participants']; } Make sure you have error reporting turned on ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); It will help you debug your code easier.
  7. Make sure you have error reporting on - ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); If that isn't working then your local server isn't set up right. To test if you local server is working properly create a php info file. <?php // Show all information, defaults to INFO_ALL phpinfo();
  8. I use SwiftMailer, but I don't bother to send the email and going through all the hassle of sending the email until I verify the user with Google's recaptcha. /* 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: }
  9. Personally I would just populate the table and if you want people to edit the comments use a HTML anchor tag: You can then either redirect the edit to another HTML page and/or use some form of Javascript/Ajax on the anchor tag. That's what I did with my small blog that I wrote for my website: <?php foreach ($journal as $cms) { ?> <div class="article"> <h2><?= $cms->heading; ?> <span class="subheading">by <?= $cms->author ?> on <?= $cms->date_added ?></span></h2> <a class="myLightBox" href="<?= $cms->image_path; ?>" title="Picture Gallery" data-picture="<?= $counter ?>" data-exif="<?php if (!is_null($cms->Model)) { echo $cms->Model . " --- " . $cms->FocalLength . " --- " . $cms->Aperture . " --- " . $cms->ISO . " --- " . $cms->ExposureTime; } ?>"><img class="editPic" src="<?= $cms->thumb_path; ?>" alt="Picture for Journal Entry"></a> <hr> <p><?php echo nl2br($cms->content); ?></p> <a class="btn3" href="edit.php?article_id=><?= $cms->id; ?>">Edit</a> <a class="btn3" href="delete_entry.php?id=<?= $cms->id; ?>" data-confirm="Do you really want to delete this item?">Delete</a> <hr> </div> <?php $counter += 1; } ?> I just find it cleaner and easier to understand.
  10. I personally switched back to vanilla javascript as it really isn't all that much harder to write and it doesn't use a library. Nothing wrong in with jQuery, but I was always wondering about the javascript equivalent when it came to certain coding. Now I don't have to wonder. I do say people who are just learning javascript should learn vanilla javascript before tackling jQuery as it will make life much simpler if you ever need just to use vanilla javascript. That was my problem as I really didn't learn vanilla js before I tackled jQuery.
  11. A person a long time ago help me out on the php portion and I am going to repay it back now. <?php /* Makes it so we don't have to decode the json coming from javascript */ header('Content-type: application/json'); /* Grab decoded incomming data from Ajax */ $incomming = $_POST['data']; $data['outgoing'] = 'stop'; if ( $incomming === 'proceed') { $data['outgoing'] = "send"; } if ( $data['outgoing'] === 'send') { output($data); } else { errorOutput('error'); } /* Something went wrong, send error back to Ajax / Javascript */ 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); }
  12. The first place I would go to is this website https://caniuse.com/
  13. 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!
  14. 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: }
  15. Another good 3rd party mailer is Swiftmailer and I found it easy to setup.
  16. 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.
  17. 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";
  18. 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="">
  19. 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.
  20. 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.
  21. 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/
  22. 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.
  23. 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.
  24. 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.
  25. 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.
×
×
  • 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.