Return to referring page

They have: 8 posts

Joined: Oct 1999

Greetings:

I have a shopping cart script that when the user clicks the add button, a subroutine runs that opens up the tabulation file and adds the appropriate items. It then returns the user to the cart page, or displays the tabulation page, depending on a redirection variable that I set to 1 or 0 in my configuration file. It accomplishes the redirection through the JavaScript history.back function. The problem with this is that the user usually sees a brief shot of the tabulation page just before being redirected. This is disturbing to some users, and confusing to a user that has a slow connection. I would like to rplace the JavaScript function with a PERL statement that accomplishes the same goal; the user stays on the shopping page until they are ready to checkout. Any code change that would accomplish this is greatly appreciated. Please see below for existing code:

code:

if ($useredirect eq '1') {
   print "Content-type: text/html\n\n    <html><body bgcolor=\#ffffff    onload=\"history.back()\">\n";
        
   }

else {
	&review_items;
	} [/code] 

They have: 850 posts

Joined: Jul 1999

Hmm, not sure if I understand this completely, but here goes nothing

$lasturl=$ENV{'HTTP_REFERER'};
#put this in when the user is at the URL you want them to be when they are redirected later on.

if ($useredirect eq '1')
{print "Location: $lasturl";}

else{}

Try that, if it doesn't work sorry

------------------
If you counted 24 hours a day, it would take 31,688 years to reach one trillion.

[This message has been edited by robp (edited 01 December 1999).]

They have: 8 posts

Joined: Oct 1999

Thanks for your help rob. I tried your simple fix that calls the environment variable, but I get premature end of script header error. I ran the edited script against a debugger that my ISP provides, and it doesn't show any problems, but then again it might just be a syntax checker. I was also thinking about putting something like:

code:


if ($useredirect eq '1') {
	print "Content-type: text/html <html><META HTTP-EQUIV\='refresh' CONTENT='0; url\=www.aroma-massage.com/cart.html'></html>\n";
        
	}
[/code]
But i don't know if that will work. I might need to ad some escapes in the code above, if it will work at all. I am pretty new at PERL and was handed this script to modify.  I will give you the entire subroutine code below so that you might be able to see why I'm getting 500 errors when I try your fix.  Thanks so much for you insight.

code:

# Add a item to the cart, show review page, unless they included a redirect variable.
sub add_item {
open (REFFILE,"$reffile") | | print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
@LINES=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;
open (REFFILE,">$reffile") | | print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|$usercurr\|NULL\|\n";
for ($i=1;$i<$SIZE;$i++) {
   	$_=$LINES[$i];
	my($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
	print REFFILE join "\|", $itemname,$itemprice,$itemquant,$weight,$itemid,"\|\n";
	}
print REFFILE join "\|", $FORM{'itemname'},$FORM{'itemprice'},$FORM{'itemquant'},$FORM{'weight'},$FORM{'itemid'};
print REFFILE "\|\n";
close(REFFILE);
if ($useredirect eq '1') {
	print "Content-type: text/html\n\n <html><body bgcolor=\#ffffff onload=\"history.back()\">\n";

	}
#if ($FORM{'redirect'}) {
#		print "Location: $FORM{'redirect'} \n\n";
#		}
else {
	&review_items;
	}
}
[/code] 

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.