Difference between revisions of "Quick Reference for PHP"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
(Read Query String)
(Read Query String)
Line 19: Line 19:
 
       <nowiki>?><i>Viewing some other page</i></a> <?</nowiki>
 
       <nowiki>?><i>Viewing some other page</i></a> <?</nowiki>
 
     }
 
     }
 +
 +
The line with preg_replace protects against known query string exploits.  The null assignment could be done better, however, the example is for syntax purposes.
  
 
&nbsp;
 
&nbsp;

Revision as of 14:26, 18 April 2014

Redirect with PHP

See also: PHP Function Reference

 <?
   header('Location: http://members.robotz.com/');
 ?>

Read Query String

 <?
   $qString = $_SERVER['QUERY_STRING'];
   $qString = preg_replace('#[^a-zA-Z0-9_-]#', '', $qString);
   print "QUERYSTRING= $qString<BR>";
   if ($qString == "") $qString = "home";
   if ($qString == "home") {
     ?><i>Viewing the HOME PAGE</i></a> <?
   } elseif ($qString == "other") {
     ?><i>Viewing some other page</i></a> <?
   }

The line with preg_replace protects against known query string exploits. The null assignment could be done better, however, the example is for syntax purposes.