Jump to content

JesseElser

Members
  • Posts

    12
  • Joined

  • Last visited

JesseElser's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm not going to write it for you but i will give guidance. First off all of your inputs need a name="". For example your email input should have something like name="email". Looking over this page this seems to be a pretty decent tutorial. http://tangledindesign.com/how-to-create-a-contact-form-using-html5-css3-and-php/
  2. I have this one setup to where the year is irrelevent For example Thanksgiving is not on a set date but I use this simple line to calculate the date in day of the year format: $thanksgivingDay = date('z', strtotime('fourth thursday of november')); // Thanksgiving Day And I have a seperate system for notifications such as business closures and such.
  3. I actually haven't figured out two holidays in the same range yet. It's a starter script. I was trying to avoid databases mostly for practical use of copying and pasting to other sites if i wanted to implement the same feature. Good idea though.
  4. So I wrote this near little script that when a holiday is a week away it displays a custom message on my site counting down to that holiday and then the day of the holiday it changes the message. Works like a charm and I absolutely love how it works, but I realized I made a couple of mistakes and I cannot figure out how to get them fixed. First I'll provide the actual code and then the two issues. <?php date_default_timezone_set("America/New_York"); // Set to ensure todays date is accurate $today = date('z',time()); // Get todays date $nextYear = date("Y" + 1); // Get current year and add one for calculating New Years //$today = date('z', strtotime('fourth thursday of november')); // date for testing - set to holiday date // Calculate dates for holidays with varying days $newYearsDay = date('z', strtotime("December 31, " + $nextYear )); // New Years $valentinesDay = date('z', strtotime("February 14")); // Valentines Day $memorialDay = date('z', strtotime('last monday of may')); // Memorial Day $independenceDay = date("z", strtotime("July 4")); // Independence Day $halloweenDay = date('z', strtotime('October 31')); // Halloween Day $thanksgivingDay = date('z', strtotime('fourth thursday of november')); // Thanksgiving Day $christmasDay = date("z", strtotime("December 25")); // Christmas Day // New Years if($today == $newYearsDay) { $holidayActive = 1; $holidayName = "New Years"; $holidaySlogan = "Happy New Year!"; $holidayClass = "independence"; } else if($newYearsDay - $today <= 7 & $newYearsDay - $today >= 1) { $holidayActive = 2; $holidayDate= $newYearsDay; $holidayName = "New Years"; $holidaySlogan = "Happy New Year!"; $holidayClass = "independence"; } // Valentines Day if($today == $valentinesDay) { $holidayActive = 1; $holidayName = "Valentines Day"; $holidaySlogan = "Will you be our valentine? ;)"; $holidayClass = "valentines"; } else if($valentinesDay - $today <= 7 & $valentinesDay - $today >=1) { $holidayActive = 2; $holidayDate= $valentinesDay; $holidayName = "Valentines Day"; $holidaySlogan = "Will you be our valentine? ;)"; $holidayClass = "valentines"; } // Memorial Day if($today == $memorialDay) { $holidayActive = 1; $holidayName = "Memorial Day"; $holidaySlogan = "You are not forgotten!"; $holidayClass = "memorial"; } else if($memorialDay - $today <= 7 & $memorialDay - $today >= 1) { $holidayActive = 2; $holidayDate= $memorialDay; $holidayName = "Memorial Day"; $holidaySlogan = "You are not forgotten!"; $holidayClass = "memorial"; } // Independence Day - Fourth of July if($today == $independenceDay) { $holidayActive = 1; $holidayName = "Independence Day"; $holidaySlogan = "Happy fourth of July!"; $holidayClass = "independence"; } else if($independenceDay - $today <= 7 & $independenceDay - $today >= 1) { $holidayActive = 2; $holidayDate= $independenceDay; $holidayName = "Independence Day"; $holidaySlogan = "Happy Fourth of July!"; $holidayClass = "independence"; } // Halloween if($today == $halloweenDay) { $holidayActive = 1; $holidayName = "Halloween"; $holidaySlogan = "Trick or Treat!"; $holidayClass = "halloween"; } else if($halloweenDay- $today <= 7 & $halloweenDay - $today >= 1) { $holidayActive = 2; $holidayDate= $halloweenDay; $holidayName = "Halloween"; $holidaySlogan = "Trick or Treat"; $holidayClass = "halloween"; } // Thanksgiving if($today == $thanksgivingDay) { $holidayActive = 1; $holidayName = "Thanksgiving"; $holidaySlogan = "Let's eat some turkey!"; $holidayClass = "thanksgiving"; } else if($thanksgivingDay - $today <= 7 & $thanksgivingDay - $today >= 1) { $holidayActive = 2; $holidayDate= $thanksgivingDay; $holidayName = "Thanksgiving"; $holidaySlogan = "Let's eat some turkey!"; $holidayClass = "thanksgiving"; } // Christmas Day if($today == $christmasDay) { $holidayActive = 1; $holidayName = "Christmas Day"; $holidaySlogan = "Merry Christmas!"; $holidayClass = "christmas"; } else if($christmasDay - $today <= 7 & $christmasDay - $today >= 1) { $holidayActive = 2; $holidayDate= $christmasDay; $holidayName = "Christmas Day"; $holidaySlogan = "Merry Christmas."; $holidayClass = "christmas"; } if(isset($holidayActive)) { echo '<div class="notification '. $holidayClass .'">'; if($holidayActive == 1) { echo 'Today is ' . $holidayName; echo ' - ' . $holidaySlogan; } if($holidayActive == 2) { $daysRemaining = $holidayDate - $today; echo "There "; if($daysRemaining == 1) { echo "is "; } else { echo "are "; } echo $daysRemaining; if($daysRemaining == 1) { echo " day ";} else { echo " days "; } echo "remaining until " . $holidayName . "."; } echo '</div>'; } ?> As you can see it is fairely simple. All I'm doing is taking todays date in day of the year format and comparing it to todays day of the year. Works excellent. But heres the issues. For the script to notify that New Years was a week away I had to add one year to the current year. Works fine for the countdown but then I realized that on the day of new years its still going to add that one year to it and not say that "Today is New Years". Here's what I tried. This is the new years section: // New Years if($today == $newYearsDay) { $holidayActive = 1; $holidayName = "New Years"; $holidaySlogan = "Happy New Year!"; $holidayClass = "independence"; } else if($newYearsDay - $today <= 7 & $newYearsDay - $today >= 1) { $holidayActive = 2; $holidayDate= $newYearsDay; $holidayName = "New Years"; $holidaySlogan = "Happy New Year!"; $holidayClass = "independence"; } I figured I could change this line if($today == $newYearsDay) to if($today == 1) and it would work. When I tested it the message did not appear so somewhere I think it is still adding the extra year. What would be the easiest way for calculating the next new years? The second issue is when two holidays are within a week of each other. Halloween is on October 31. Labor Day is November 1st. How could I work around that? I removed Labor Day temporarily until I found a solution. I haven't tried anything new for that issue yet, but thought I would ask anyways. Thanks guys. If you can think of any other possible improvements to this I welcome suggestions. EDIT: If you would like to see it in action I have it live on my site at http://jollyrogerpcs.com if this link is not allowed I will remove it.
  5. Got them all removed and now there are no errors. Oddly enough it's a blank page now and not making thumbnails still but it's progress lol.
  6. Removed all of the extra characters that show as blank spaces. Error code is now changing lines which i assume is more special characters. Do you have any suggestions on how to easily find any of these special chars?
  7. I'm getting an error and no matter how many people look at the code no one can figure out why. The error I'm getting is: Parse error: syntax error, unexpected '$ratio_orig' (T_VARIABLE) in /home/jollyrogerpcs/public_html/img/gallery/thumbnail.php on line 23 The code is: // thumb width $square = 150; $large = 200; $small = 100; ////////////////////////////////////////////////////////////////////////////////// square if( isset($_GET["img"]) && ( $_GET["type"] == "square" || $_GET["type"] == "" ) ){ // thumb size $thumb_width = $square; $thumb_height = $square; // align $align = $_GET["align"]; // image source $imgSrc = $_GET["img"]; $imgExt = substr($imgSrc,-3); // image extension if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); } if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); } if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); } // getting the image dimensions list($width_orig, $height_orig) = getimagesize($imgSrc); // ratio $ratio_orig = $width_orig/$height_orig; // landscape or portrait? if ($thumb_width/$thumb_height > $ratio_orig) { $new_height = $thumb_width/$ratio_orig; $new_width = $thumb_width; } else { $new_width = $thumb_height*$ratio_orig; $new_height = $thumb_height; } // middle $x_mid = $new_width/2; $y_mid = $new_height/2; // create new image $process = imagecreatetruecolor(round($new_width), round($new_height)); imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // alignment if($align == ""){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "top"){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), 0, $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "bottom"){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($new_height-$thumb_height), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "left"){ imagecopyresampled($thumb, $process, 0, 0, 0, ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "right"){ imagecopyresampled($thumb, $process, 0, 0, ($new_width-$thumb_width), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } imagedestroy($process); imagedestroy($myImage); if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); } if($imgExt == "gif"){ imagegif($thumb); } if($imgExt == "png"){ imagepng($thumb, null, 9); } } // normal if(isset($_GET["img"]) && ($_GET["type"] == "large" || $_GET["type"] == "small" ) ){ if( $_GET["type"] == "large" ){ $thumb_width = $large; } if( $_GET["type"] == "small" ){ $thumb_width = $small; } // image source $imgSrc = $_GET["img"]; $imgExt = substr($imgSrc,-3); // image extension if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); } if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); } if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); } //getting the image dimensions list($width_orig, $height_orig) = getimagesize($imgSrc); // ratio $ratio_orig = $width_orig/$height_orig; $thumb_height = $thumb_width/$ratio_orig; // new dimensions $new_width = $thumb_width; $new_height = $thumb_height; // middle $x_mid = $new_width/2; $y_mid = $new_height/2; // create new image $process = imagecreatetruecolor(round($new_width), round($new_height)); imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); } if($imgExt == "gif"){ imagegif($thumb); } if($imgExt == "png"){ imagepng($thumb, null, 9); } } Every line has the required semicolons. All brackets are properly closed. I have zero clue why that error even exists and I had this posted on another site and no one could figure it out. If it helps the script is from http://1stwebmagazine.com/generate-thumbnail-on-the-fly-with-php
  8. I found a solution but I appreciate the replies. First: CroNiX test.php was added to the url to trigger the 404 error since that file does not exist. It turns out that in the .htaccess file I had the urls wrong since I did not realize that it was looking at the root folder. This was solved by simply changing the paths from ErrorDocument 404 /error.php to ErrorDocument 404 /143/error.php Marked as "Best Answer" for anyone else that made a similar mistake.
  9. So while editing my .HTACCESS file I added the proper lines to redirect users that encounter errors like 404 and 500. It works like a charm if I tell it to display a specific message. However if I tell the file to redirect users to a custom error page it fails. When testing out my 404 redirect I get this: Not Found The requested URL /143/test.php was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80 As you can see it is stating that my ErrorDocument is not found BUT if I type my ErrorDocument URL in I can go to it myself. My .HTACCESS file looks like this: ErrorDocument 400 /error.php ErrorDocument 401 /error.php ErrorDocument 403 /error.php ErrorDocument 404 /error.php ErrorDocument 500 /error.php ErrorDocument 502 /error.php ErrorDocument 504 /error.php # supress php errors php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off # enable PHP error logging php_flag log_errors on php_value error_log PHP_errors.log NOTE: I am using localhost (WAMP). Thanks.
×
×
  • 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.