Created
August 2, 2018 17:12
-
-
Save quisido/7bff853bf1cb077cecb5332aa2b65e94 to your computer and use it in GitHub Desktop.
Creating a Dynamic Vertical Gradient in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// provide a generic 404 error if... | |
if ( | |
// FROM/START color does not exist | |
!array_key_exists('from', $_GET) || | |
// FROM/START color is not valid hex | |
!preg_match('/^[a-fA-F\d]{6}$/', $_GET['from']) || | |
// TO/END color does not exist | |
!array_key_exists('to', $_GET) || | |
// TO/END color is not valid hex | |
!preg_match('/^[a-fA-F\d]{6}$/', $_GET['to']) || | |
// HEIGHT does not exist | |
!array_key_exists('height', $_GET) || | |
// HEIGHT is not numeric | |
!is_numeric($_GET['height']) || | |
// Be sure to set your minimum and maximum heights that you'll be | |
// using here. If you need a 300px gradient, you'll need to up the | |
// value to 300. But be sure to use a limit! A user who inputs | |
// 9,999,999 will destroy your server's memory and bandwidth. | |
// HEIGHT is too small | |
$_GET['height'] < 4 || | |
// HEIGHT is too large | |
$_GET['height'] > 64 | |
) { | |
// 404 header | |
header('HTTP/1.1 404 Not Found'); | |
// text document | |
header('Content-Type: text/plain; charset=utf-8'); | |
// generic 404 error message | |
exit('Move along. Nothing to see here.'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment