Wednesday, April 25, 2012

Ankhet Mobile Problem Solving

Problem: I want to cache images, but not HTML
Solution: Modify headers sent from server for image data to clarify cacheability
Implementation: Not Done

Problem: Zoom works properly on iPhone but not on Kindle Fire
Solution: iPhone auto-creates a viewport from the beginning of the first visual component to the end of the last visual component. Kindle renders more or less like a desktop. Create a viewport for Kindle Fire.
Implementation: Viewport with minSize ~= 2.0 and maxSize ~= 3.0 with User-Scaleable = 1

Problem: mysql_real_escape_string requires a live connection to a mySQL database, so it can grab the character encoding. I don't have a mySQL database.
Solution: Use mysql_escape_string (deprecated, possible it'll be removed) or a dummy mySQL database with the same charset at the MSSQL database.
Implementation: Switched to MySQL 5.5 database backed by

Problem: Unable to use any mysql_, mssql_ or sqlsrv_ PHP functions with the default GoDaddy configuration (despite having databases for both mysql and MSSQL).
Solution: Switch somewhere that lets me finish my site.
Implementation: Call Get satisfaction in under 10 minutes.

Problem: doesn't support sqlsrv_ functions (linux based hosting) and mssql_ functions are deprecated.
Solution: Switch to a MySQL database, use the already extant mysql_ functions to interface with the database.
Implementation: see above.

Problem: default.php doesn't display at, instead a directiory of contents comes up.
Solution: Rename default.php to index.php.
Implementation: done (future: redirect index.php to default.php transparently, not done)

Problem: PHP pages are cluttered and contain large portions of if(bool) echo '[HTML CODE]';
Solution: Migrate HTML out of PHP
Implementation: Use include() to bring in HTML as needed, reducing page size, processing time and increasing readability.

Problem: HTML/PHP pages to be included are visible without being inside their including page.
Solution: Enforce inclusion over direct viewing.
Implementation: <?php if($_SERVER['PHP_SELF'] !== "[PAGENAME]") { header("HTTP/1.1 404 Not Found"); echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<TITLE>404 Not Found</TITLE>
<H1>Not Found</H1>
The requested URL '.$_SERVER['PHP_SELF'].' was not found on this server.<P>
<P>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
<ADDRESS>Apache/1.3.41 Server at [SERVER] Port 80</ADDRESS>
</BODY></HTML>'; exit; } ?>

Problem: Sessions dying on every page, requiring new login.
Solution: session_start() must be on every page.
Implementation: Put session_start() just after <?php in most cases, or use ob_start()

Problem: Sessions persist forever.
Solution: Add logout button
Implementation: <?php
header("Location: [FRONTPAGE]");

Problem: Registration and some other abilities need to be restricted to testing only.
Solution: A debug variable, put somewhere it'll always be available.
Implementation: Wrap the abilities in question in if (AnkhDEBUG) {} and define() AnkhDEBUG in ankhetdb.php as it's included on every page.

Problem: Registration dumps you back on the main page with no indication your registration worked
Solution: Auto-login if successful.
Implementation: Change $returnVal to an array() with [0] being success and [1] being message. If [0] start_session, header location: index.php else continue on register.php, displaying [1] as appropriate.

Problem(s): Lots of problems with getting data into the table.
Solution/Implementation: Print the query being sent, debug debug debug, make sure of use ` instead of ' when referring to MySQL tables/databases (MySQL idosyncracy)

Problem: game.php needs to require login
Solution: Check if user is logged in, otherwise redirect
Implementation: Check if a particular session variable exists, if not use the above header location: technique to redirect to index.php for session start.

No comments: