Discover & Rate New Music Check out ChartVote. Promote the music you like.


Create a “back” button with PHP

Deziner Folio posted this PHP snippet for creating a simple back link that will take you to the previous page you were on.

Code:

PHP:
  1. <?php session_start(); ?> <!– Starting a session before the DOCTYPE –>
  2.  
  3. <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
  4. “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
  5.  
  6. <a href=”<?php echo $_SESSION[’back’]; ?>“>back</a> <!–The anchor tag that links to the previous page –>
  7.  
  8. <?php $_SESSION[’back’] = $_SERVER[’REQUEST_URI’]; ?> <!– Assigning the current URL to a session variable –>

Please note that first we assign the previous session variable to the anchor tag and only then re-assign the current URL to the session variable which will be read when you move on to the next page.

This being a simple PHP snippet can be used in almost every CMS (PHP based) and sure is a good addon to the accessibility of your site.

You can view the original article here


Leave a Reply

RSS Feed



Recommended Sites