Solved

How to do a HTTP (check) query string redirect?

Posted on 2006-07-05
19
240 Views
Last Modified: 2013-12-25
We are trying to make a redirect on our site based on the following scenario:

On the main page of a shopping cart, the user picks from 2 categories.  After picking a category, the user picks accessories to go with that product.

Upon picking THE CATEGORY, we want the main product for that category to automatically add to their cart, and then proceed to the accessories page.

The problem is, it HAS to goto the view cart page upon adding the main category product.. So we want it to redirect the user to the accessory page based on the previous location that they came from.

We want to add a query string, where it would tell which product category is picked from the main page.

On the cart page that it redirects to when you click one of the categories, we want it to see that if the category selected equals 1 or 2, then it redirects to the next page in the process for that category
0
Comment
Question by:will4062
  • 6
  • 6
  • 3
  • +2
19 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 17046440
I'd just add a hidden field with category and then the view cart page simply has to see what value is in the category field and redirect to the appropriate page based on the number.
0
 

Author Comment

by:will4062
ID: 17050219
Example?
0
 

Author Comment

by:will4062
ID: 17051592
This is what I want to do to clarify it:

Main Page --> Choose Item 1 or 2
Item 1 ----> shopping cart (redirect to cart on click)
Item 2 ----> shopping cart (redirect to cart on click)
Shopping Cart ----> Item 1 pages (redirects to item 2 pages based on previous url)
Shopping Cart ----> Item 2 pages (redirects to item 2 pages based on previous url)
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 17052273
a bit confusing to me, somehow ...
Could you please explain what you mean by redirect?

Anyway, assuming following:
  1. maiin page /main.cgi:
     user chose item 1 and wants the accessories, therfore in the main page are following links:
     <a href="/.cgi?item=1">1. accessories</a>
     <a href="/accessories.cgi?item=2">2. accessories</a>
 2. accessories page /accessories.cgi:
    contains a form for your accessories, like:
    <form name="accessories" action="/main.cgi">
       <input type="hidden" name="category" value="1" />
             <!-- above inserted by your accessories.cgi from its parameter item= -->
       <input name="a1" .... />
       <input name="a2" .... />
       <input type="submit"  />
  3. main page again which was produced by main.cgi:
0
 

Author Comment

by:will4062
ID: 17052576
Sorry, it sounds like you understood it a bit wrong

Basically, the user goes through a "building block" process, where they pick one required item on the main page (which is automatically added to the cart), then they goto a list of accessories that are available only for that item (which are on a seperate page than the main page).

However, after they pick the required item on the main page, they are redirected to the shopping cart. It has to work like this because of our cart system. So, we want it to redirect back to the accessories page from the cart based on which required item they selected.

This is what I have tried on the required item page:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=post>
             
<input type=hidden name=storeid value=*107a534098078ee10e04>
<input type=hidden name=dbname value=products>
<input type=hidden name=function value=add>
<input type=hidden name=itemnum value=2>

<input type=image class="add" src="http://test.com/store/media/straight.gif" name="Add to Cart" value=2 alt="Add to Cart">

</form>

But, it doesnt work because it wont add the required item value to the url
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17052738
> But, it doesnt work because it wont add the required item value to the url
for post method the parameters are not added to the URL, but send as body in the HTTP request
You either have to parse the POST parameters, or change the form to method=get
0
 

Author Comment

by:will4062
ID: 17053136
The storeid adds to the URL fine
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17053668
and the others add too, separated by &
otherwise you have a buggy browser
0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17054376
>> This is what I have tried on the required item page:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=post>
             
<input type=hidden name=storeid value=*107a534098078ee10e04>
<input type=hidden name=dbname value=products>
<input type=hidden name=function value=add>
<input type=hidden name=itemnum value=2>

<input type=image class="add" src="http://test.com/store/media/straight.gif" name="Add to Cart" value=2 alt="Add to Cart">

</form>

change this line:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=post>

to:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=get>

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17056353
Perl_Diver, did you read my comments?
if the method is post, nothing gets added to the URL (except by buggy browsers)
if the method is get, all gets added to the URL (except by buggy browsers)
( and I also do not see any malware, like JavaScript, ActiveX, which might do it)
;-)
0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17059654
I skimmed through the thread so if I missed something my apologies.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17059983
no worries, we all have bad days ... ;-)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17069311
What language is order.cgi written in?  Do you have to rely on GET methods?  There's generally not much need to use them.
0
 

Author Comment

by:will4062
ID: 17081484
I actually figured it out using cookies and if -else statements. Ill post how I did it if anyone is interested
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17081730
using cookies or hidden form fields is rather the same, except that hidden form fields work with any browser while cookies depend on the user's browser configuration
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17086014
Please post the solution as the question was pretty generic, so it was a little hard to help without more detailed information.
0
 

Author Comment

by:will4062
ID: 17100392
Here is just everything I have on the cart page:

<script>
if (document.referrer=="http://snaphitch.com/store/product7.html")
{
  alert ("The shank was added to your cart. Now choose a kingpin required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
else if (document.referrer=="http://snaphitch.com/store/product8.html")
{
  alert ("The shank was added to your cart. Now choose a kingpin required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
</script>
<script>
var adjusted = document.cookie.split("/adjustable.gif");
if(adjusted.length>1)
{
  adjusted = adjusted[1].split("/")[0];
  alert ("The Adjustable Snap Hitch was added to your cart. Now choose a drop shank required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/page4.html";
}
else
{
  adjusted="";
}
</script>
<script>
var straight = document.cookie.split("/straight.gif");
if(straight.length>1)
{
  straight = straight[1].split("/")[0];
  alert ("The Straight Snap Hitch was added to your cart. Now choose a kingpin ball assembly to match your trailer's coupler.")
  window.location ="http://www.snaphitch.com/store/page3.html";
}
else
{
  straight="";
}
</script>

<script>
var shank1 = document.cookie.split(":QH-13");
var shank2 = document.cookie.split(":QH-13L");
if(document.referrer=="http://www.snaphitch.com/store/page4.html" && shank1.length>1)
{
  shank1 = shank1[1].split(":")[0];
  alert ("The shank was added to your cart. Now choose a kingpin required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
else
{
  shank1="";
}
if(document.referrer=="http://www.snaphitch.com/store/page4.html" && shank2.length>1)
{
  shank2 = shank2[1].split(":")[0];
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
else
{
  shank2="";
}
</script>

<script>
if(document.referrer=="http://www.snaphitch.com/store/page3.html"  || document.referrer=="http://www.snaphitch.com/store/kingpin.html" || document.referrer=="http://snaphitch.com/store/product3.html" || document.referrer=="http://snaphitch.com/store/product4.html" || document.referrer=="http://snaphitch.com/store/product5.html" || document.referrer=="http://snaphitch.com/store/product6.html")
{
  alert ("Congratulations, you've successfully built your Snap Hitch!")
}
</script>


And on the individual pages:

<script>
var redirs = document.cookie.split("/straight.gif");
if(redirs.length>1)
{
  redirs = redirs[1].split("/")[0];
  window.location ="http://www.snaphitch.com/store/page3.html";
}
else
{
  redirs="";
}
</script>
<script>
var redirss = document.cookie.split("/order.cgi");
if(redirss.length>1)
{
  redirss = redirss[1].split("/")[0];
  window.location ="http://www.snaphitch.com/cgi-bin/sc/order.cgi?storeid=*107a524308078e910ed1&function=show";
}
else
{
  redirss="";
}
</script>
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17633988
PAQed with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

713 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