PHP Switch
Posted on June 24th, 2014 by webninjataylor
Switch is an abbreviated version of if, else if, etc… <?php switch($_POST[‘color’]) { case ‘white’: case ‘black’: $clean[‘color’] = $_POST[‘color’]; break; } ?>
Posted on June 24th, 2014 by webninjataylor
Switch is an abbreviated version of if, else if, etc… <?php switch($_POST[‘color’]) { case ‘white’: case ‘black’: $clean[‘color’] = $_POST[‘color’]; break; } ?>
Posted on June 24th, 2014 by webninjataylor
<?php //Initialize an empty array for storing filtered, escaped input $clean = array(); //Wash Basic Input Fields function washnormal(){ //Use the global $clean array global $clean; //Loop through the fields passed to the function for ($i = 0; $i < func_num_args(); $i++){ $item = func_get_arg($i); //Regular expression matching for lowercase letters, uppercase letters, digits, periods, […]
Posted on June 24th, 2014 by webninjataylor
You should store include files outside of the document root for security.
Posted on June 24th, 2014 by webninjataylor
Clear a variable’s value(s) <?php unset($variable); ?> Clear a long record set to free memory. Only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script’s execution. <?php mysql_free_result($rsXYZ); ?>
Posted on June 24th, 2014 by webninjataylor
<?php //Associative multidimensional array with named keys, called in reverse order to avoid returning NULL $menuTests = array( ‘ALMA’ => ‘/index.php/about/facilities/alma’, ‘EVLA’ => ‘/index.php/about/facilities/vlaevla’, ‘SKA’ => ‘/index.php/about/facilities/ska’, ); $menu = array( ‘Home’ => ‘/index.php’, ‘Tests’ => array(‘/cosmicradio/test.php’,$menuTests), ‘Cosmic Radio’ => ‘/cosmicradio/index.php’ ); echo “<pre>”; var_dump($menu); echo “</pre>”; echo $menu[‘Tests’][1]; foreach($menu as $itemPrimary => $urlPrimary){ echo […]
Posted on June 24th, 2014 by webninjataylor
Create database with tables (at least 2 with 1 being for users) Create a user with limited privledges to the database Create a connection file using the new user Use the following on the main public page to ensure no sessions are currently active //CALL SESSION AND DESTROY session_start(); unset($_SESSION); session_destroy(); Create a loginfailed page […]
Posted on May 30th, 2013 by webninjataylor
Add this to your PHP file to allow the page to reload when the user clicks their browser’s back button; it’s very handy when navigating back-and-forth from a search results page… header(“Cache-Control: private, must-revalidate, max-age=0”); header(“Pragma: no-cache”); header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // A date in the past
Posted on April 9th, 2013 by webninjataylor
PHP will download in your localhost, instead of rendering, if your .htaccess file in the htdocs root doesn’t have this line commented out… # Use PHP5 Single php.ini as default # AddHandler application/x-httpd-php5s .php # (WNT) Removed above line which actually caused PHP to download instead of render.