Redirecting GET as POST

I have a website that navigates via a form "POST"  (not GET)
method.  So you can't have a naked URL that drops a customer
on an item page.

When I go to do promotions it is impossible to have a
link right to a particular item

I am looking for a way (a Script ?)
That parses a regular (GET) hyperlink which contains elements
for the POST form.  

When the server receives the request it would cause the browser to
redirect using the elements provided as a POST request
as though the customer was normally navigating my site.
catdontdoAsked:
Who is Participating?
 
RobOwner (Aidellio)Commented:
What you're looking for is a router.  I use the slim framework.  It has a very small footprint and is very easy to use, including receiving all kinds of HTML requests and showing the appropriate content (or redirecting as necessary):

http://www.slimframework.com/ | http://docs.slimframework.com/

Please check it out and I'll be happy to answer any queries you have.
0
 
Steve BinkCommented:
While I have no doubt a router would work for this, my first instinct says it might be a little heavy-handed.  If all you need is to translate GET values into POST values, most languages can do this with a small bit of code inserted into the right place.  

What language/platform are you using for your current site?
0
 
RobOwner (Aidellio)Commented:
So in Slim your code would look like the following but I'm guessing at what you want and it's an example only of showing you how you can manipulate the data and requests as they come in

<?php
$app = new \Slim\Slim();

$app->post('/search', function () {
  $terms = $app->request->params('search_terms');
  // do something with the search terms (I haven't covered sanitizing input from the user and using filter_var() but you should USE it)
  $results_url = search_for_products($terms);  // your function
  $app->redirect($results_url);
});

$app->run();

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
RobOwner (Aidellio)Commented:
Steve does make a good point... when using any additional framework or library you want to make sure that you're not "bloating" your site with unnecessary code.  And of course I've assumed PHP which would be a deal-breaker if you're not using it! :)

One of the main reasons I use a router is for SEO.  Being able to take GET routes and essentially do what you can with POST and vice-versa but having "friendly" urls will help your site rank well in the search engines.
0
 
shalomcCTOCommented:
I am not so sure that slim will work here.

If I understand correctly, the question is about sending a 3xx redirection back to the client in response to a GET request, that will force the client to POST and get to the real location.

As far as I know this is not how HTTP works.

The only trick that may work is dynamic construction of a POST form, using the GET query string values in hidden fields, and use setTimeout to auto-submit the form to the target location.
0
 
RobOwner (Aidellio)Commented:
shalomc,

You're right, that's not how HTTP works.  However, my suggestion revolves around not doing it that way but rather take a request to a URL and based on the request type (GET or POST)  and perform the necessary action (as long as the GET request satisfies certain criteria).  

e.g.
$app = new \Slim\Slim();

$app->map('/foo/bar(/:id(/:product(/:size)))', function($id, $product, $size)  use ($app) {
	// this will receive requests to the URL "/foo/bar"
	// we can configure the logic here to accept either POST or GET but perform the same action if requirements are met
	if ($app->request->isGet()) {
		// check that id, product, size all are valid and if they are, do the same action as POST
		if ($valid) {
			$app->render('submitPage.php', array('id'=>$id, 'product'=>$product, 'size'=>$size);
		}
		else {
			// not valid so redirect
			$app->redirect("/search");
		}		
	}
	else if ($app->request->isPost()) {
		// do some action here
		$app->render('submitPage.php', $app->request->post());
	}
	else {
		// not a valid request so redirect
		$app->redirect("/search");
	}
})->via('GET', 'POST');

$app->run();

Open in new window

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.