Our Scripts Vault contains many game scripts that you can use to create your own game!
<?phpsession_start();require "../config.php";$name = $_GET['game'];$imgOutput = imagecreatetruecolor(48, 64);imagefill($imgOutput, 255, 255, 255);$imgBody = imagecreatefrompng("$game_data$name/items/body_" . str_replace("_", '',$_SESSION['body']) . ".png");imagecolortransparent($imgBody, imagecolorat($imgBody, 0, 0));if(isset($_SESSION['top'])){ $imgBeard = imagecreatefrompng("$game_data$name/items/head_" . str_replace('_', '',$_SESSION['head'] . ".png")); imagecolortransparent($imgBeard, imagecolorat($imgBeard, 0, 0));}imagecopymerge($imgOutput, $imgBody, 0, 0, 0, 0, 48, 64, 100);if(isset($_SESSION['top'])){ imagecopymerge($imgOutput, $imgBeard, 0, 0, 0, 0, 48, 64, 100);}imagepng($imgOutput);?>
over-validating
Quote from: DV8 on March 11, 2011, 08:47:07 AMover-validatingYou, sir, speak of the impossible!
$intExample = ( isset( $_GET["example"] ) && ereg( "^[0-9]*$", $_GET["example"] ) && $_GET["example"] != "" ) ? $_GET["example"] : 0;
$intExample = (isset ($_GET['example']) && is_numeric($_GET['example'])) ? intval($_GET['example']) : 0;
Mainly because you really shouldn't use those anyways. $_REQUEST has long been considered evil. Sure there are situations where it could be useful (say you don't care if the variable comes from $_GET or $_POST) but as a "best practice" you should explicitly check the super-globals you care about rather than leaving the decision over which should take precedent to whomever has control over the php.ini (not always the developer).As for $_COOKIE... why use $_COOKIE when you have $_SESSION? The less data you actually give to the client, the less you need to worry about validating for XSS / cheating / etc..
I've found $_REQUEST extremely useful especially when creating summary / detail type drill downs where the summary is used as a $_GET and the detail is processed as a hidden variable in the detail. Each to his / her own I use it regularly and sanitize the input which is what I was trying to relay in my post.
if (isset ($_POST['var']) && !empty ($_POST['var'])) { $var = $_POST['var'];}elseif (isset ($_GET['var']) && !empty ($_GET['var'])) { $var = $_GET['var'];}
$var = $_REQUEST['var'];
function req($var, $order = 'gpc') { $globals = array( 'c' => $_COOKIE, 'g' => $_GET, 'p' => $_POST, ); $val = NULL; foreach((array) $order as $superGlobal) { if (isset ($globals[$superGlobal][$var]) && !empty ($globals[$superGlobal][$var])) { $val = $globals[$superGlobal][$var]; break; } } return $val;}
As for cookie this comes with the ability for both JavaScript and PHP to share information via cookie data.<off-topic segment removed, don't worry, it's at the bottom>I have not found another way to share data between javascript and PHP without using a cookie. You can pass or push data between the two but to truly 'share' the data in one location, cookie is the only method that I'm aware of.
I don't need to clutter up $_SESSION data with data sorting preferences which I normally use it for.
What makes you think that your $_SESSION data will be available from work (presumabely on a different system) or after a format?
This would only happen if the site developer had altered the session system to work this way...
I set my own cookies with my own session system over using PHP's session system so that I can control things to a better degree. You could of course over ride PHP's default session behaviour but that just seems a messy way to do things.
By default PHP's session system has various problems which I'm not interested in working around when I can control the session/cookies implementation myself.
Basically we're comparing cookies vs a system which utilizes cookies (who uses the query string to pass session identifiers?) to maintain sessions anyway, so this little debate is just plain stupid.
Lets say somebody uses PHP's sessions to just store a user ID once logged in. Ok, great - it works. What's the point in that when by default PHP's session system then has to read from a file system to load that user ID? Instead we can generate our own session identifier, mark this against a user in the database (ensuring the value is unique), store a cookie (for however long you wish), make sure the column is indexed and bob's your uncle.. a much better way of doing things. This doesn't fall victim to the problems PHP's session system has by default, such as having multiple web servers serving requests but session identifiers only being stored locally per web server.
Your own session system > PHP's session system any day. Cookies are going to presumabely be used either way to store the relevant identifier.
For storing client side user preferences which don't really need to be maintained over different systems (for example the size of the chat bar for future reloads, set each time it's resized), I like to use HTML5's localstorage - storing this kind of thing server side is just a waste and storing it in cookies is just extra data being sent with every single request on that domain / path pointlessly. Surprisingly localstorage is even supported in IE8 That's enough for me (and for this type of thing, if the user's browser doesn't support localstorage.. it's no big deal, their chat area width is just not saved for future visits, for example).
Well it's a good job you won't ever be taking over any of my small projects with your "certified engineering", cause I won't ever feel the need to use PHP's session system (completely altered or not) just because it's there