Treehouse: Grow your CSS skills. Land your dream job.

$_GET to $_POST?

  • # February 28, 2012 at 7:57 am

    I get a callback from a checkout server (Mal’s E-commerce) which includes GET data (used to calculate shipping) in the URL.

    I need to create an ‘intermediary’ script that reads, checks and POSTs this data on to the checkout page on my server that will be presented to the visitor. I’ve read of some ‘onload’ JavaScript ways to do this, but I wouldn’t be happy with a ‘no Javascript’ fail.

    Current Process:

    1. Checkout server redirects the client to a /shipping/ script on my server, including query string data.

    Required Behaviour:

    2. Checkout server redirects to a script on my server which checks and converts the query string data into POST (form) data which is the ‘submitted’ to the /shipping/ script.

    Or maybe I’m overcomplicating it? The aim is for the client not to see all the data in the query string when reaching the /shipping/ page on our server. I’m fairly certain that I can’t ask the other server to POST instead BTW.

    Thanks guys. :D

    # February 28, 2012 at 9:40 am

    Why not use a session on the server variable on the server instead?

    # February 28, 2012 at 9:48 am

    Sounds good, if you could elaborate on the concept slightly for me. :D

    # February 28, 2012 at 9:52 am

    Do you mean use a script to put the query string into a session, then redirect to the shipping calculator page and pull the data back from the session variable?

    # February 28, 2012 at 10:20 am

    You got it, that way the client never sees this data and it’s easier to manage

    # February 28, 2012 at 10:29 am

    Ah great thanks. Now to code it. :D

    # February 28, 2012 at 10:48 am

    Any tips for parsing the values back out of the string – “units=0&value=36.55…”?

    # February 28, 2012 at 10:53 am

    are you using PHP?

    # February 28, 2012 at 10:54 am

    Sorry, yes PHP.

    # February 28, 2012 at 10:56 am
    $_SESSION = $_GET;
    $_SESSION = $_GET;

    There ya go, the GET values from the URL are now stored in your session

    # February 28, 2012 at 10:58 am

    Ah of course! I had put the whole query string into a session variable. Thanks again. :D

    # March 1, 2012 at 3:38 am

    Filter your data though! Make sure you have floats where you expect floats and strings where you accept strings.

    Otherwise there could be a whole load of problems later on

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.