Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Strider64 last won the day on April 28 2014

Strider64 had the most liked content!

Community Reputation

13 Neutral

About Strider64

  • Rank
    Advanced Member
  • Birthday 08/28/1964

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    A burb of Detroit, MI
  1. 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.
  2. 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/
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. This link might help you out -> http://phpenthusiast.com/blog/how-to-autoload-with-composer HTH John - I know it did me, for before this I was using my own crazy autoloader and it should make my GitHub repositories more standardized.
  9. Google's reCaptcha is pretty nice and easy to use -> https://www.pepster.com/contact.php I like using it for it save me from coming with my own and I can move onto other PHP scripts.
  10. I like this link https://phpdelusions.net/pdo, but I don't agree with everything they write. However, for the most part it's very informative and won't steer you wrong. (In my opinion)
  11. On points number 1 & 2 .....why not just have security levels for the admins? It would be easier and make people happier than blocking users by country? Heck, you could only have a only member site that way you can control who has access or not to certain pages. Think of it as having a green jacket at Augusta's Country Club (The Masters in case people don't know golf).
  12. I agree with ginerjm. I just wanted to add Radio Buttons can have only one value in the first place, so I don't even know why you are using an array? Unless all of the $id is going to be the same? An if that was the case there would be no need for an array for you are using Radio Buttons. <div class="radioBlock"> <input type="radio" id="radio1" name="reason" value="support" checked> <label class="radioStyle" for="radio1">support</label> <input type="radio" id="radio2" name="reason" value="advertise"> <label class="radioStyle" for="radio2">advertise</label> <input type="radio" id="radio3" name="reason" value="error"> <label class="radioStyle" for="radio3">Report a Bug</label> </div> However, I really don't understand what you are trying to do, so onward..... An to use an array you would in a form you wouldn't use $id, you would do something like: <input id="example" type="radio" name="use_item[id]" value=""> and this is how I retrieve it using php: $data = filter_input(INPUT_POST, 'use_item', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY);
  13. I personally would concentrate on getting PHP with PDO acting right, before moving on to JavaScript/jQuery. It's relatively easy to add client-side script later and at the same time you'll have graceful degradation with the scripts. Myself I find if I have too many layers (I'm talking about coding) going on at the same time I get easily confused, but it could just be my old age creeping up on me. Just my .02 cents. BTW JQuery is easy to implement Ajax but plain vanilla JavaScript isn't that much harder. For example this is a little bit of the coding of a trivia game that I'm developing.. function insertNew() { var addform = document.getElementById('addTrivia'); var action = 'add_trivia.php'; var fdata = new FormData(addform); // for ([key, value] of fdata.entries()) { // console.log(key + ': ' + value); // } var xhr = new XMLHttpRequest(); xhr.open('POST', action, true); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { var result = xhr.responseText; console.log(result); var info = JSON.parse(result); console.log('info', info); if (info.result) { document.getElementById("addTrivia").reset(); function closeit() { document.getElementById("shadow").style.display = "none"; } if (info.result) { document.getElementById('shadow').style.display = 'block'; setTimeout(closeit, 2000); } } } } xhr.send(fdata); } done in vanilla javascript. Though I agree jQuery is easier to use for Ajax.
  14. I personally don't like protecting code to begin with and here my reasoning. I used to work for auto paint manufacturer that bought this really expensive software package from a company that heavily protected their code (though they did have tech support that they paid for), if the people in charge (the IT department) running the software even had to make a simple change to the software package they had to had the company do it. To make a long story short, the company that sold us the software package went bankrupt and left us up a creek without a paddle. Even though they were going out-of-business they still wouldn't unprotect the software claiming they still had held the rights to to software. So here we are with an expensive digital paperweight and having to fork over more $$$ to another company. My memory is a little fuzzy but it was so specialized piece of software that the competitors would have to write it from the ground up thus costing us money for the downtime and/or praying the software that we would currently using would hold up until the replacement could be up and running. Anyway, my point is that you being a small company (while you probably won't go out-of-business) are probably specializing in developing software that for most part isn't going to be freely distributed to other companies unless it's a game or a general application then like someone stated you don't have to give them the php file though that presents a minor problem (that also stated). I know from personal experience being held hostage on a software package is a negative experience. Besides the company went to you to write the software for they didn't want to take the time to develop themselves for they have other priorities. Like in my case we were making paint for the automotive industry and my specific job was matching the color to customer's (auto companies) OEM color standards. The last thing I wanted to do is figure out how that software work.
  15. Well, if you are GETTING then you can just easily SET the data. If you set the data then you can easily save the data. Doing it this way class userModel{ private name; private email; /*lots more properties for user */ public function getName(){ return $this->name; } public function getEmail(){ return $this->email; } } would be more secure in my opinion.
  • 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.