0

hey ppl. I have many submit buttons in a form. Each of them does its thing in different php pages. But when, for example, 'add' button goes to 'add.php' it does its work but stays there) how to redirect page back? thanks

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by kracko
1

There are 2 simplistic ways.

The first and most recommended is the header redirect:

header("Location: pagename.php");

That sends the header location to the browser, telling it to redirect itself to whatever you replace pagename with.

The second, less elegant way:

<meta http-equiv="refresh" content="2;url=pagename.php">

Where 2 is the number of seconds to wait before sending a refresh command to the browser and the url obviously being the page you want to redirect to.

The main problem I have with the second is that the page has to load before it even begins the countdown and witin that amount of time, if the user presses ESC or clicks the stop button, the countdown stops and the page does not redirect. The header sent by php is, as far as I've ever been able to manipulate, impossible to stop from redirecting as it's one of the very first things the browser receives.

However, the header refresh can be tricky to use. As it's a header, you cannot echo or display ANY kind of text or anything. If you decide to use it but cannot get it to work, just post it and we'll see what we can do.

1
header("Location: add.php");

I am not sure that is the one you want. Hope this help..!

1

Try using the following code at the point you want to redirect.

<script type="text/javascript">
window.location.href="<? echo $_SERVER ;?>";
</script>

$_SERVER contains the value of the referring page.

Also avoid using header function from PHP. It causes hell of a trouble...

0

thanks a lot. I guess header helped and don't have troubles with it yet:) But thank you all. It's a pleasure to ask something here:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.