OSdata.com |
Building a game open source code This is the actual source code from a new web game. See the game at thissideofsanity.com and read how this was built starting at example code.
This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.
Copyright 2013 Milo (for software), Distribution and website handled by Strazbick.com
Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This narrative uses anchor links so that you can follow the building of this software in chronological order. Go to software explanation to start reading. Go to thissideofsanity.com to see the working software.
This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.
A few data validation routines.
<?php /* FILE NAME /datavalidation.php */ /******************************/ /* ValidateInputforSQL */ /* validate input for SQL */ /* the type is used to guarantee that theinput is the correct type */ /* the default value is used if the input is otherwise invalid */ /* returns valid SQL input if validated -- with security protections */ /* returns empty string on failure with empty string as default */ /******************************/ function ValidateInputforSQL($inputdata,$inputtype,$defaultvalue) { // change to include better defenses against SQL injection attacks if ( $inputtype == 'string' ) $x = 1; /* placeholder because there is no check here yet because all of the forms actually generate strings as the input */ elseif ( $inputtype == 'integer' ) { if ( !is_numeric($inputdata) ) $inputdata = ''; /* invalid input, set to empty string */ } $inputdata = addslashes($inputdata); return $inputdata; } /* ValidateInputforSQL */ /******************************/ /* ValidateOutputforHTML */ /* validate output for HTML */ /******************************/ function ValidateOutputforHTML($inputdata) { // change to include better defenses against HTML attacks $inputdata = htmlspecialchars($inputdata); return $inputdata; } /* ValidateOutputforHTML */ /******************************/ /* CreateDateForSQL */ /* create date for SQL */ /******************************/ function CreateDateForSQL($inputday,$inputmonth,$inputyear) { // convert parts into correct date if ($inputmonth < 10) $firstpart = $inputyear."-0".$inputmonth; else $firstpart = $inputyear."-".$inputmonth; if ($inputday < 10) $secondpart = "-0".$inputday; else $secondpart = "-".$inputday; $fulldate = $firstpart.$secondpart; return $fulldate; } /* CreateDateForSQL */ /******************************/ /* CreateDateTimeForSQL */ /* create date and time for SQL */ /******************************/ function CreateDateTimeForSQL($inputday,$inputmonth,$inputyear,$inputhour,$inputminute,$inputsecond) { // convert parts into correct date and time for SQL if ($inputmonth < 10) $firstpart = $inputyear."-0".$inputmonth; else $firstpart = $inputyear."-".$inputmonth; if ($inputday < 10) $secondpart = "-0".$inputday; else $secondpart = "-".$inputday; $fulldatetime = $firstpart.$secondpart; if ($inputhour < 10) $firstpart = ' 0'.$inputhour; else $firstpart = ' '.$inputhour; if ($inputminute < 10) $secondpart = ':0'.$inputminute; else $secondpart = ':'.$inputminute; if ($inputsecond < 10) $thirdpart = ':0'.$inputsecond; else $thirdpart = ':'.$inputsecond; return $fulldatetime.$firstpart.$secondpart.$thirdpart; } /* CreateDateTimeForSQL */ /******************************/ /* Subtract13Years */ /* subtract 13 years form a date */ /* called from newregistration.php */ /******************************/ function Subtract13Years($inputdate) { // subtract 13 years from a valid date $tempdate = substr($inputdate,0,4); $newdate = $tempdate - 13; $newdate = $newdate.substr($inputdate,4,6); return $newdate; } /* Subtract13Years */ /******************************/ /* ValidEmail */ /* called from newregistration.php */ /******************************/ function ValidEmail($address) { // check an email address is possibly valid if (preg_match('/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/', $address)) return true; else return false; } /* END ValidEmail */ ?>
OSdata.com is used in more than 300 colleges and universities around the worldFind out how to get similar high web traffic and search engine placement. |
OSdata.com is used in more than 300 colleges and universities around the world |
Tweets by @osdata |
A web site on dozens of operating systems simply cant be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.
Click here for our privacy policy.
previous page | next page |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2013 Milo
Last Updated: September 23, 2013
Created: September 9, 2013
previous page | next page |