By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Detecting cached file

P: n/a
I have the following code on files "a.php" and "b.php"

-----------------------------
FILE a.php
-----------------------------

<form action="a.php" method="post">
<input type="hidden" name="active" value="1">
<input type="submit" name="Submit" value="Send">
</form>
<?php
if (isset($_POST['active']) && $_POST['active'] == 1) {
?>
<script language="JavaScript" type="text/JavaScript">
alert('Thank you.');
</script>
<?php ; } ?>

<a href="b.php">Go to b.php</a>

--------------------------
FILE b.php
--------------------------

<a href="#" onClick="history.back()">Back to a.php</a>

---------------------------
Works like this.

1. The user fills and sends the form in a.php
2. a.php loads and displays a thank you message
3. The user clicks on "Go to b.php"
4. b.php loads and the user clics on "Back to a.php"
5. a.php loads (I assume is loading from the cache") and displays thank
you message again, which should not occur!!!
I tried this on file a.php
<?php
if (isset($_POST['active']) && $_POST['active'] == 1) {
?>
<script language="JavaScript" type="text/JavaScript">
if (!window.IWasHere) {
alert('Thank you.');
var IWasHere = true;
}
</script>
<?php ; } ?>

But did not work. Also tried includding a pragma no-cache and expires
tags:

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">

but did not work either.

Any ideas?

Thanks,

Guillermo Scharffenorth

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
gu*******@gmail.com wrote:
I have the following code on files "a.php" and "b.php"
<snip>

<a href="#" onClick="history.back()">Back to a.php</a>

---------------------------
<snip>
1. The user fills and sends the form in a.php
2. a.php loads and displays a thank you message
3. The user clicks on "Go to b.php"
4. b.php loads and the user clics on "Back to a.php"
5. a.php loads (I assume is loading from the cache") and displays thank
you message again, which should not occur!!!


Change your link from history.back() to something a little simpler:

<a href="A.php?PHPAppendedTime">Back to a.php</a>

And when b.php is sent to the browser, have php append the current
server time, in milliseconds, to the link.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2

P: n/a

Use PHP header() to have the browser no cache the pages, which is cheesy
IMO as you can just instead, use a target="thankyou.html" on the form.
Danny

On Sat, 25 Jun 2005 09:52:23 -0700, <gu*******@gmail.com> wrote:
I have the following code on files "a.php" and "b.php"

-----------------------------
FILE a.php
-----------------------------

<form action="a.php" method="post">
<input type="hidden" name="active" value="1">
<input type="submit" name="Submit" value="Send">
</form>
<?php
if (isset($_POST['active']) && $_POST['active'] == 1) {
?>
<script language="JavaScript" type="text/JavaScript">
alert('Thank you.');
</script>
<?php ; } ?>

<a href="b.php">Go to b.php</a>

--------------------------
FILE b.php
--------------------------

<a href="#" onClick="history.back()">Back to a.php</a>

---------------------------
Works like this.

1. The user fills and sends the form in a.php
2. a.php loads and displays a thank you message
3. The user clicks on "Go to b.php"
4. b.php loads and the user clics on "Back to a.php"
5. a.php loads (I assume is loading from the cache") and displays thank
you message again, which should not occur!!!
I tried this on file a.php
<?php
if (isset($_POST['active']) && $_POST['active'] == 1) {
?>
<script language="JavaScript" type="text/JavaScript">
if (!window.IWasHere) {
alert('Thank you.');
var IWasHere = true;
}
</script>
<?php ; } ?>

But did not work. Also tried includding a pragma no-cache and expires
tags:

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">

but did not work either.

Any ideas?

Thanks,

Guillermo Scharffenorth


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #3

P: n/a
Danny wrote:

Use PHP header() to have the browser no cache the pages,
And if the browser/UA/proxy/etc doesn't honor it? You are right back
where you started. Read my reply, it might enlighten you.
which is cheesy IMO as you can just instead, use a
target="thankyou.html" on the form.


Yes, if that is the intent. But it depends on what the intent of a.php
and b.php use is.

Reading this group's FAQ (via sig below) will do wonders for you.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #4

P: n/a
I must use history back because I want the user to come back not just
to the previous file (a.php), but also to the specific place in the
previous file where the user clicked in order to go to b.php. Besides,
theres is no only b.php, there could be b.php, c.php, ... etc.

Thanks.

GS

Jul 23 '05 #5

P: n/a
> Change your link from history.back() to something a little simpler:
<a href="A.php?PHPAppendedTime">B*ack to a.php</a>


I must use history back because I want the user to come back not just
to the previous file (a.php), but also to the specific place in the
previous file where the user clicked in order to go to b.php. Besides,
theres is no only b.php, there could be b.php, c.php, ... etc.

I wonder if there is a way, using javacript, to detect the name of the
file (or title of the window) from which I am coming. For example:

1 I am in a.php and click a link that opens b.php
2 from b.php I click history.back()
3 back in a.php, using JS, I detect that the previous displayed window
was b.php (or the title of the window)

Thanks.

GS

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.