Solved

redirect to previous page and refresh it

Posted on 2004-08-31
35
551 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:ktjamms2
  • 15
  • 11
  • 5
  • +1
35 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 11944613
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
 
LVL 21

Expert Comment

by:pinaldave
ID: 11944627
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
 
LVL 21

Expert Comment

by:pinaldave
ID: 11944643
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11944836
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
 
LVL 21

Expert Comment

by:pinaldave
ID: 11944926
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
 

Author Comment

by:ktjamms2
ID: 11945036
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
 
LVL 21

Expert Comment

by:pinaldave
ID: 11945092
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11945218
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
 

Author Comment

by:ktjamms2
ID: 11945479
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
 
LVL 18

Expert Comment

by:Plucka
ID: 11962728
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
 

Author Comment

by:ktjamms2
ID: 11962940
What is the Cold Fusion syntax to store the previous page in a session variable?
0
 
LVL 18

Accepted Solution

by:
Plucka earned 250 total points
ID: 11963012
<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
 

Author Comment

by:ktjamms2
ID: 11968511
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
 
LVL 18

Expert Comment

by:Plucka
ID: 11968739
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
 
LVL 18

Expert Comment

by:Plucka
ID: 11968761
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
 

Author Comment

by:ktjamms2
ID: 11972756

<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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11973513
Yes like this :

<A HREF="nextpage.cfm?#session.urltoken#&ReturnTo=#CGI.SCRIPT_NAME#">whatever</A>
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:ktjamms2
ID: 11974427
what is the advantage of killing all session variables when the browser is closed?
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 11974444
It prevents session hijacking.
0
 

Author Comment

by:ktjamms2
ID: 11974743
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11974821
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
 

Author Comment

by:ktjamms2
ID: 11974975
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
 

Author Comment

by:ktjamms2
ID: 11975041
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11975103
Youneed a ? after teh .cfm before teh #session.....
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 11975113
Also make sure it is enclosed in a cfoutput
0
 

Author Comment

by:ktjamms2
ID: 11975414
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11975476
Try this on the page :

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

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

and see what prints....
0
 

Author Comment

by:ktjamms2
ID: 11975578
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
 

Author Comment

by:ktjamms2
ID: 11975923
<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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11976214
what exactly does it display?
0
 

Author Comment

by:ktjamms2
ID: 11976479
/page.cfm&CFID=12345&CFTOKEN=12345678
0
 

Author Comment

by:ktjamms2
ID: 11976737
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 11976955
The problem is that you need a ? after the .cfm as I mentioned several messages back...
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 11976966
Well time out is not really something we can address....
0
 

Author Comment

by:ktjamms2
ID: 11978072
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now