Redirect to previous page

I was wondering if anyone on here can help me. I’m building a basic management system for the submissions on my website. I have two sections, new and old submissions. What i’d like to know, is there an easy way to redirect a user to their previous page. At the moment my delete.php file just redirects to the new_submissions.php page, this is ok but it seems a bit odd for it to do this when you’re deleting an old submission and vice versa.

Would somebody be able to give me some tips or pointers on how to solve this small issue. I don’t know if this would be way ott but how about some sort of code that sets a global variable for the last page you visited so that when the delete.php file is run, the header will redirect to the page name in the $variable? Or am i being way stupid here?


Is http_referer something i could use to do this?

Right, i’ve set up variables that tell the delete.php file which page the user was previously on. I’ve done this using

$redirect_subs = $_SESSION['which_subs'];

This is working as it should because i’ve done echo and the delete page shows the page you were previously on. It’s just how do i use this data in the redirect header?


Try working with something like the following.

header("Location: " . $mylocation);

That’s working. Thanks very much for your help.

Is this the best way to do this by the way? Are there any other methods i can use that don’t require me manually adding the following to every page?

$which_subs = "submissions.php";
	$_SESSION['which_subs'] = $which_subs;

The only other option of the top of my head is to play around with $_SERVER[‘HTTP_REFERER’]

I was thinking that would be easier but don’t certain browsers restrict the sending of referrer information?

I guess if it’s only going to be used by a limited number of people (like my page) then it should be alright but if you don’t know what browsers or plugins your visitors are going to be running then getting each page to tell the other pages where you were is probably the best way to go?

yes, there are some issues using it, but like you said since it is administration thing then you should have a pretty good idea of who is using it, but something like the following could maybe tinkered with to get the desired result.


<?php $past = $_SESSION['past']; if(empty($past)){ $past = "";} $_SESSION['past'] = $_SERVER['HTTP_URI']; ?>[/php]

I am not exactly how this will work or if at all, just something I typed up quick. But should be able to tinker around and get something useable.

Logic: Set the variable with the session variable which should contain the previous pages name. Then reset the session variable with the current page to be used on other pages. If statement is there in case page is accessed directly.

Sponsor our Newsletter | Privacy Policy | Terms of Service