faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input : Validating Data

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

57 of 64 people (89%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I pass variables to a script in the url like /script/var1/var2?
How can I pass variables in a form that won't scare off search engines?

Apr 8th, 2005 04:52
Philip Olson, Alberto Ferrer, Ben Munoz, Karl Hennig, Nathan Wallace, Onno Benschop,


It's easy but first note that having a QUERY_STRING (stuff after the ?
in the URL) does not scare off search engines.  Now, let's say that
rather then having:
    http://www.example.com/foo/index.php?id=23&this=that
You want something more like one of the following:
    http://www.example.com/foo/index.php/id/23/this/that 
    http://www.example.com/foo/id/23/this/that 
Yet still have access to variables such as $id and $this, in similar 
fashion to how faqts.com does it.  Search engines are more friendly 
towards these versions, a few tutorials and articles exist on the 
subject:
  Search Engine Optimizing PHP Scripts
  ---------------------------------------------------------------:
  http://www.stargeek.com/php-seo.php
  Search Engine Friendly PHP Pages                               :
  ----------------------------------------------------------------
  http://zend.com/zend/spotlight/searchengine.php
  mod_rewrite: A Beginner's Guide to URL Rewriting               :
  ----------------------------------------------------------------
  http://www.sitepoint.com/article/guide-url-rewriting
  Building Dynamic Pages With Search Engines in Mind             :
  ----------------------------------------------------------------  
  http://phpbuilder.com/columns/tim20000526.php3
  A quick example of file.php/var/var                            :
  ----------------------------------------------------------------
  http://www.deltasoft.com.ar/code/test.phps
  How to Succeed With URLs                                       :
  ----------------------------------------------------------------
  http://www.alistapart.com/articles/succeed/
If you want to get rid of the ugly .php in the middle of your url, 
take a look at the Apache ForceType directive (see the phpbuilder 
tutorial too.)
   http://www.apache.org/docs/mod/mod_mime.html#forcetype
Also, if you're feeling brave, consider Apaches mod_rewrite as it'll be 
more efficient (and powerful):
   http://httpd.apache.org/docs/mod/mod_rewrite.html
   http://www.engelschall.com/pw/apache/rewriteguide/
   http://marc.theaimsgroup.com/?l=php-general&s=mod_rewrite
There you have a few options.  The key to the PHP methods are  
understanding predefined variables such as REQUEST_URI and PATH_INFO 
and exploding them with explode().  The above tutorials explain it 
pretty well.  A call to phpinfo() will tell you exactly what is
available to your script.