Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a Post.php page

Status
Not open for further replies.

denisfinn

Programmer
Jun 7, 2003
49
US
I'm trying to make a page that after a submit button is pressed on say index.php it goes to post.php. from here i want the post.php to go to the previous page, which in this case is index.php. i can easily do this the hardcoded way where i simply tell it to go back to "index.php", but i want this to work from any page. this would mean i'd need a variable that has the URL from the previous page.

i hope you understand.

lets put it in another way.

i want the post.php page to go to the previous page (no matter what page it was) after a set amount of time.

please understand :)

Thanks,

DF
 
I think it could be done with javascript:

history.go(-1)

or something like that...
 
can you write that out all the way....i don't know anything about javascript or how to go into it. but won't that not work if they have their history stuff off?
 
How can you turn "history" off ???

but yes, you are right on that... if turn history off can be done, the history.go(-1) will not work... it is curious anyway, I know nobody with that option off.

you could ask it in the Javascript forum.

 
ok,

how do you put that script into an html page?

<html>
<body>
<whatgoeshere>
history.go(-1);
</whatgoeshere>
</body>
</html>

Thanks

DF
 
All you need to do is

<script><!--
history.go(-1);
//--></script>

However, how about passing the previous page's url in a hidden field in your form? This would unfortunately mean adding a line to all the pages on your site, but it has the advantage that you could do all the redirection stuff server-side.

ie on each page with a form you have something like:

<form method="post" action="post.php">
...
...
<input name="from_url" type="hidden" value="<?=$PHP_SELF?>" />
</form>

Then at the end of post.php you could put something like:

// after doing what you need to do in post.php
header("Location: ".$_POST["from_url"]);

This avoids the use of Javascript altogether.

-Rob
 
JavaScript code may or may not be executed, so it's not a sure bet. You could use $_SERVER['HTTP_REFERER'] to find out the previous page and use that as a check at the same time:
The referer must be on your own site - the redirect to the historically previous page. If there were a link somwhere on the net to one of your scripts the referer would not be on your site, so don't redirect. If it is a direct request by typing on the URL, also don't redirect.
 
Javascript can be turned off, history can be turned off, HTTP_REFERER can be disabled.

Since you're having them fill out a form anyway, I'd go with Broccoli2's suggestion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top