redirect to previous page and refresh it

I have a cold fusion shopping cart website. When a user places an item in their shopping cart, it posts to a page that displays all the items placed in their cart. I would like this page to display for a brief time and go back to the previously viewed page but without anything selected(refreshed). I was thinking of using  meta http-equiv="refresh" content="5;url= but I'm not sure of the exact syntac that would go back 1 and  also maintain my #session.urltoken variable.
ktjamms2Asked:
Who is Participating?
 
PluckaConnect With a Mentor Commented:
<cfset Session.ReturnTo = CGI.SCRIPT_NAME />

Then in your next page you can do a link or auto refresh with this variable.

Ie:

<a href="#Session.ReturnTo#">Back</a>

or go back after 5 seconds.

<script language=JavaScript>
    setTimeout("#Session.ReturnTo#", 5000);
</script>

PS: You need the above commands within a cfoutput.
0
 
pinaldaveCommented:
Hi ktjamms2,
. Declare the body tag in html window as server control by specifing runat attribute and give an id to that tag.

                                <body runat="server" id= "body">< /P>< /FONT>

2. In the code behind, declare this element as htmlgenericcontrol like this.            

  Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl    

3. Finally add the following code in your page_load event handler, this will add the client side handler for body tag.

 body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='<somepage>.cfm'"",5000);")    


ANOTHER WAY:::


   <META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">



ANOTHERWAY :::::::::::::::


<html>
<head>
<title>A web page that points a browser to a different page after 2 seconds</title>
<meta http-equiv="refresh" content="2; URL=http://www.pa.msu.edu/services/computing/">
<meta name="keywords" content="automatic redirection">
</head>
<body>
If your browser doesn't automatically go there within a few seconds,
you may want to go to
<a href="http://www.pa.msu.edu/services/computing/">the destination</a>
manually.
</body>
</html>


Regards,
---Pinal
0
 
pinaldaveCommented:
Hi ktjamms2,
as long as you are worried about your session. it will be there and will not be affected by this code.
If your user does not accept and you want to be extra carefull..in that case this is what you can do... like for your code... you can add #session.URLTOCKEN#  like www.experts-exchange.com&#session.URLTOCKEN#
let me knwo if you have any more questions.

Regards,
---Pinal
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
pinaldaveCommented:
Hi ktjamms2,
  Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl    this may not work... i was testing it and it is not working on my server... so do not waste trying that of my suggestion...

Regards,
---Pinal
0
 
mrichmonCommented:
That looks like ASP code instead of Cold Fusion code ;o)

Personally I would recommend against doing this as the user will NOT appreciate it, but if you do want to proceed the best method for a timed redirect is in PinalDave's answer of this :

<meta http-equiv="refresh" content="2; URL=http://www.pa.msu.edu/services/computing/">

Here is a link that will generate the redirect code for you and even add a progress bar
http://www.designerwiz.com/ad-framer.htm?http&&&www.designerwiz.com/generator/auto_redirect_generator.htm


Here is a good article on types of clientside redirection
http://tech.irt.org/articles/js021/
0
 
pinaldaveCommented:
Hi mrichmon,
 That looks like ASP code instead of Cold Fusion code --- Mrichmon. that is very true. I realize afterwards. My team mate laughed on me and told me that I am so stupid that I can not find out differance between ASP and JAVAScript. He told me that he had this on server, but that is not working. I felt stupid as I posted that first and tested afterwards. thanks again for correcting me.

Regards,
---Pinal
0
 
ktjamms2Author Commented:
the thing is that I don't know the url they just came from to put a specific url location. I want it to automatically go back to the page they were on and refresh so the same selections aren't still on that page so they can re-select different without confusion or having to erase the previously entered form. And I dont want to loose my session.urltoken variable(maybe url.token won't get lost with back and refresh).
0
 
pinaldaveCommented:
Hi ktjamms2,
 And I dont want to loose my session.urltoken variable(maybe url.token
 won't get lost with back and refresh).
It will not get lost if you are worried you can put them in URL as mentioned on the top.
following is javascript code to go back after 5 second.
<script language=JavaScript>
setTimeout("window.location.history.go(-1)",5000);
</script>


Regards,
---Pinal
0
 
mrichmonCommented:
Just a note that by automaticaly sending them back to where they came from WILL confuse them.


BUT if you insist...

The best way to know where they came from is that when they hit submit to go to the cart save the page URL to a session variable using the CGI.SCRIPT_NAME and CGI.QUERY_STRING variables.

Then you can use them on the cart page to recreate the URL the user came from.

The problem with using back is that the previous page will not be refreshed.

Personally I would just have a "Continue shopping button" and let the user control where they go.  Maybe they don't want to go back?  Maybe they want to check out.  But by you sending them back they can't checkout and so leave your site....

Just some things to cinsider.
0
 
ktjamms2Author Commented:
Even so...I could have the continue shopping button take them back to the place they were. The page they are on that displays a list of items in their cart, already has links to check out or navigate throughout the website. I just didn't want users to have to remember how they navigated to where they were in the previous screen. I tried  <input type = "button" onclick = "history.go(-2)" value = "Continue Shopping"> but it doesn't refresh the page and clear previously selected information. I thought that would confuse some users.
0
 
PluckaCommented:
Hi ktjamms2,

Normally you store the page they were last when you want to return them to it, you can store it in a session variable or pass it in a post or url data, relying on javascript history has issues all of its own.

Regards
Plucka
0
 
ktjamms2Author Commented:
What is the Cold Fusion syntax to store the previous page in a session variable?
0
 
ktjamms2Author Commented:
this works good Plucka,

<cfset Session.ReturnTo = CGI.SCRIPT_NAME />

Then in your next page you can do a link or auto refresh with this variable.

Ie:

<a href="#Session.ReturnTo#">Back</a>

The problem I have now is that when the session times out via:
<cflock TIMEOUT="90">(I increased the time from 30 to 90)
<cftransaction>  etc. An error occurs while evaluating #Session.ReturnTo#

Is there a drawback to not setting a TIMEOUT ?

0
 
PluckaCommented:
If you pass it in the url then it will never expire, otherwise you could just increase the timeout further or change the setting in Administrator.

To pass it in a URL.

<a href="nextpage.cfm?ReturnTo=#CGI.SCRIPT_NAME#">Whatever</a>

As for the TIMEOUT, unless you need to timeout the session then dont.

The <cflock isn't timing out the session I don't believe, this is to do with the session timeout. You either don't have your session variables setup properly or they timeout too quickly.

Here's the code I normally throw in my application.cfm to setup session variables properly and make sure they expire when the browser is closed.

<cflock name="ApplicationName" throwontimeout="no" timeout="20">
      <cfapplication       name="ApplicationName"
                              sessionmanagement="Yes"
                              setclientcookies="Yes"
                              sessiontimeout="#CreateTimeSpan(0,8,0,0)#">
      
      <!--- This code kills all session variables when the browser is closed --->
      <cfif IsDefined("Cookie.CFID") AND IsDefined("Cookie.CFTOKEN")>
            <cfset cfId_local = Cookie.CFID>
            <cfset cftoken_local = Cookie.CFTOKEN>
            <cfcookie name="CFID" value="#cfId_local#">
            <cfcookie name="CFTOKEN" value="#cftoken_local#">
      </cfif>
</cflock>

This sets up session variables for 8 hours.
0
 
PluckaCommented:
One other thought, if the page runs for a really long time and you don't want to worry about sessions expiring quickly do this at the top of your page.

<cfparam name="Request.ReturnTo" Default="#Session.ReturnTo#" />

Then Request.ReturnTo will be available as long as the page is open. So you can use this in your redirects.

Ie:

<a href="#Request.ReturnTo#">Back</a>

or go back after 5 seconds.

<script language=JavaScript>
    setTimeout("#Request.ReturnTo#", 5000);
</script>
0
 
ktjamms2Author Commented:

<a href="nextpage.cfm?ReturnTo=#CGI.SCRIPT_NAME#">Whatever</a>


I already have the session.urltoken varriable being passed

<A HREF="nextpage.cfm?#session.urltoken#">whatever</A>

Can I also pass the ?ReturnTo=#CGI.SCRIPT_NAME# with the same link?
0
 
mrichmonCommented:
Yes like this :

<A HREF="nextpage.cfm?#session.urltoken#&ReturnTo=#CGI.SCRIPT_NAME#">whatever</A>
0
 
ktjamms2Author Commented:
what is the advantage of killing all session variables when the browser is closed?
0
 
mrichmonCommented:
It prevents session hijacking.
0
 
ktjamms2Author Commented:
I don't know what that means.

Anyhow, I still get an error when the page sets idle for a period of time.
I have an order page that posts to a page that enters the items in a data base and redirects to a page where the viewer can see all of their selections. I made a button to continue shopping that utilized the <a href="#Session.ReturnTo#"> and there is another button if selected will post to a page that removes the item from the data base and displays the remaining items for the user to view. When the remove item button is clicked after the page is idle for awhile an error occurs.

 I set the <cfparam name="Request.ReturnTo" Default="#Session.ReturnTo#" /> on the redirect page, the view items, page and to page it posts to (view items 2).
 
on the redirect page I have:
<meta http-equiv="refresh" content="0;URL=http://mydomain.com/page1.cfm?#&ReturnTo=#CGI.SCRIPT_NAME#">


the item view page posts to item view 2:
action="page2.cfm?#session.urltoken#&ReturnTo=#CGI.SCRIPT_NAME#"
method="post"

item view 2 posts to itself  because it processes the removal function and displays an updated view.

Both pages seem to time out if the the remove item button is clicked. Every other link works including the continue shopping that takes them back
0
 
mrichmonCommented:
session hijacking is where Person A logs on and creates a session.

Then they close the browser, but you don't kill the session.

Now person B logs on and starts using Person A's session variables.

They have "hijacked" the session.

In most cases the session will time out, but this can happen even unintentionally.

This is why it is a good practice to clear a session when the browser closes - because people expect that cllosing the browser gets rid of thier information.


Part of the problem with sessions is the timeout you are mentioneing above.

Yes if the page sits idle too long an error will occur.

The only way to prevent this is to test if the session exists on every page and if not then create a new one.
0
 
ktjamms2Author Commented:
I've noticed that the redirect page doesn't  seem to pass the #session.urltoken#
before the redirect page the url is:
http://mydomain/formpage.cfm?CFID=12345&CFTOKEN=12345678
after the redirect the url is:
http://my domain/page1.cfm?#session.urltoken&ReturnTo=CGI.SCRIPT_NAME
0
 
ktjamms2Author Commented:
on the redirect page I have:
<meta http-equiv="refresh" content="0;URL=http://mydomain.com/page1.cfm#session.urltoken#&ReturnTo=#CGI.SCRIPT_NAME#"> but the url token doesn't seem to get passed on
0
 
mrichmonCommented:
Youneed a ? after teh .cfm before teh #session.....
0
 
mrichmonCommented:
Also make sure it is enclosed in a cfoutput
0
 
ktjamms2Author Commented:
ok, thanks that works....I should have seen that one.

but I need the <a href="#Session.ReturnTo#">
to also pass my #session.urltoken#

<a href="#Session.ReturnTo#&#session.urltoken#"> comes up page not found
0
 
mrichmonCommented:
Try this on the page :

<cfoutput>#Session.ReturnTo#&#session.urltoken#</cfoutput>

Note it is not inside a  <a href ... >

and see what prints....
0
 
ktjamms2Author Commented:
likely it wants to go back to the redirect page....which I don't want and haven't set the
<cfset Session.ReturnTo = CGI.SCRIPT_NAME /> on that page.  How can I work around that?
0
 
ktjamms2Author Commented:
<cfoutput>#Session.ReturnTo#&#session.urltoken#</cfoutput>

Note it is not inside a  <a href ... >

DIDN'T WORK MRICHMON ..... just displays the actual values instead of the variable
0
 
mrichmonCommented:
what exactly does it display?
0
 
ktjamms2Author Commented:
/page.cfm&CFID=12345&CFTOKEN=12345678
0
 
ktjamms2Author Commented:
OK I got the cfid to pass by reversing the code to
a href="#Session.ReturnTo#?#session.urltoken#">

but the page still seems to time out or something
0
 
mrichmonCommented:
The problem is that you need a ? after the .cfm as I mentioned several messages back...
0
 
mrichmonCommented:
Well time out is not really something we can address....
0
 
ktjamms2Author Commented:
The problem with using <a href="#Session.ReturnTo#?#session.urltoken#"> appears to come from the fact that one of the pages posts to itself and the first page is a result of a redirect page. When it times out, it causes an error.
<cfparam name="Request.ReturnTo" Default="#Session.ReturnTo#" /> does not seem to work
 Is there another way around that?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.