Back to Previous Page (PHP)

Your rating: None Average: 3.8 (55 votes)

While working on one of our projects we came across a requirement which was basically a Link which takes you to the previous page within the same site.

We googled and found a lot of ways which were complex. After giving it a thought, we just figured out that its a very simple logic with a few lines of code.

Well, our requirement was for a Drupal site so got the logic on PHP. Here it goes [sharing is our policy] :

<?php session_start(); ?> <!-- Starting a session before the DOCTYPE -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<a href="<?php echo $_SESSION['back']; ?>">back</a> <!--The anchor tag that links to the previous page -->

<?php $_SESSION[’back’] = htmlentities($_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.

Trackback URL for this post:


Anonymous's picture

Right. if user refresh the page or user redirected to same page again then its not going to work. it will take user to same page again and again. try another way to do this or simply use Go Back

Chirag (not verified)
Mon, 05/06/2013 - 14:47
Anonymous's picture

Thanks to share this.

jayendra kumar (not verified)
Tue, 03/27/2012 - 13:20
Anonymous's picture

Great goods from you, man. I have understand your stuff previous to and you're just extremely great. I actually like what you have acquired here, really like what you're saying and
the way in which you say it. You make it entertaining and you still take care of to keep it wise.
I can't wait to read much more from you. This is actually a great website. (not verified)
Wed, 03/20/2013 - 20:43
Anonymous's picture

Unquestionably imagine that which you stated. Your favourite justification appeared to be at the internet the simplest
thing to have in mind of. I say to you, I certainly get
irked while other folks think about issues that they plainly do not recognize about.
You managed to hit the nail upon the highest as well as outlined out the entire
thing with no need side-effects , people could take a signal.
Will likely be again to get more. Thanks

Tue, 02/26/2013 - 18:54
Anonymous's picture

Thanks for your useful post. In recent times, I have come to be
able to understand that the actual symptoms of mesothelioma are caused by this build up
associated fluid between lining in the lung and the torso
cavity. The ailment may start from the chest region and multiply to other areas of the body.
Other symptoms of pleural mesothelioma include weight loss, severe breathing trouble, a
fever, difficulty eating, and swelling of the face and
neck areas. It ought to be noted some people with the disease will not
experience any kind of serious signs or symptoms at all.

good website (not verified)
Sun, 01/20/2013 - 03:56
Anonymous's picture

Do you have a spam problem on this site; I also am a
blogger, and I was wondering your situation; many of us have developed some
nice procedures and we are looking to exchange techniques with others, be sure to shoot me an email if

recipes book (not verified)
Thu, 11/01/2012 - 02:56
Anonymous's picture

Oferim solutii software pentru industria Horeca.Soft pentru Restaurant,Bar,Fast food,Club.

AB Soft Timsoara, HORECA MANAGER este o solutie software care permite urmarirea, controlul si
reglarea activitatilor din firma dumneavoastra prin
controlarea de la vanzare la materii prime in timp real.

Softul a fost dezvoltat pentru a veni in intampinarea nevoilor aparute in desfasurarea activitatii
intr-o locatie HORECA, astfel prin utilizarea monitorului cu TOUCH SCREEN de catre angajati, dumneavoastra aveti un control
total asupra afacerii prin:

-Scazamantul din stoc dupa retete sau unitar se face in momentul

-Calculul in timp real al stocurilor de marfa (cantitativ si valoric)

- Controlul vanzarilor pe ospatar in timp real (cantitativ
si valoric)

- Controlul vanzarilor totale in timp real (cantitativ si valoric)

- Rapoarte cantitativ – valorice – procentuale pe grupele de produse si pe fiecare produs in parte.

- Listare NIR la pret de achizitie sau de vanzare.

- Fisa Magazie pe produs pe perioada.

- Grafice vanzari pe orele zilei sau pe zilele saptamanii Sistemul software va mai ofera urmatoarele avantaje:

Reducerea erorii umane in calculul notelor de plata si a stocurilor.

Eliberarea automata a bonurilor fiscale (pt DATEX MP55 sau compatibile cu PC)

Siguranta datelor – HORECA MANAGER ofera siguranta
datelor in sistem cu nivele de acces distincte pentru angajat si pt Administrator.

Promptitudine si reactie rapida la comenzile utilizatorilor.

Se pot utiliza un numar nelimitat de produse grupate in categorii.

Interfata foarte prietenoasa, customizabila pt fiecare client.

Reducerea costurilor prin o corecta gestionare a materiilor prime,
avand la dispozitie rapoartele de consum pentru a putea alcatui
o comanda de aprovizionare.

Controlul angajatilor prin informatiile oferite de catre BORDEROUL DE INCASARI OSPATAR: Data
si ora intrarii in tura precum si a iesirii,Numarul de comenzi servite,
Valoare vanzari desfasurata pe categoriile de plata (Numerar,Card,

Softul functioneaza si pe varianta MONOPOST – un singur calculator
sau in varianta de RETEA.

Cel mai importatnt avantaj este controlul de oriunde din lume
cu ajutorul internetului conectandu-va si vizualizand in timp real ce se intampla
la firma dumneavoastra.


Se seteaza mesele dupa designul locatiei incat ele sa fie
usor de identificat pt ospatari.

O masa la care s-a luat comanda este colorata in rosu
si are inscriptionat numele ospatarului care
se ocupa de acea masa.
Interfata de introducere a comenzii este foarte usor de utilizat.

Doar prin apasarea zonei corespunzatoare categoriei, zona de produse se populeaza cu cele din categoria selectata.

Se listeaza bonurile de comanda.
Apoi se elibereaza nota de plata si bonul fiscal.

Raportul de vanzari ne ofera informatii complexe asupra vanzarilor cantitativ –
valoric si procentual odata pe CATEGORII DE PRODUSE cat si amanuntit
pe fiecare produs vandut in parte.

-Calcul CONSUM Materii prime pentru orice perioada selectata.
(se poate defalca pe modalitati de plata!) Toate Rapoartele se exporta in EXCEL Interfata de Introducere Produse Meniu foarte usor de lucrat in ea.
De aici se poate introduce un produs NOU
sau modifica un produs vechi

- Schimbare PRET sau DENUMIRE. Tot de aici se si sterge un produs existent in lista meniu.

Grafice vanzari pe orele zilei si zilele saptamanii va
ofera o imagine a evolutiei in timp a firmei dvs.

Optim pentru gestionarea angajatiilor prin suplimentarea in
perioade de varf daca e necesar. Interfata de INCHIDERE ZI poate fi consultata oricand pentru a afla vanzarile in timp real, imparite pe metode de
plata si fiecare pe gestiuni, precum si valoarea vanzarilor inclus MESELE NEINCASATE INCA.

Soft Restaurant (not verified)
Sun, 09/23/2012 - 00:59
Anonymous's picture

It is in point of fact a nice and useful piece of info.
I am happy that you just shared this useful info
with us. Please keep us informed like this. Thanks for sharing.

Memorizing Tips (not verified)
Tue, 09/18/2012 - 11:40
Anonymous's picture

It helped me very well:)

tomas drozda (not verified)
Tue, 08/09/2011 - 17:51
Anonymous's picture

Thanks's very nice articles....

geetha (not verified)
Sat, 03/12/2011 - 12:11