Solved

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

Posted on 2006-07-05
19
236 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
Comment Utility
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
Comment Utility
Example?
0
 

Author Comment

by:will4062
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
The storeid adds to the URL fine
0
 
LVL 51

Expert Comment

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

Expert Comment

by:Perl_Diver
Comment Utility
>> 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
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.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
I skimmed through the thread so if I missed something my apologies.
0
 
LVL 51

Expert Comment

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

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

12 Experts available now in Live!

Get 1:1 Help Now