treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] $_GET to $_POST?

  • 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
  • Why not use a session on the server variable on the server instead?
  • Sounds good, if you could elaborate on the concept slightly for me. :D
  • 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?
  • You got it, that way the client never sees this data and it's easier to manage
  • Ah great thanks. Now to code it. :D
  • Any tips for parsing the values back out of the string - "units=0&value=36.55..."?
  • are you using PHP?
  • Sorry, yes PHP.
  • @session_start();
    $_SESSION['units'] = $_GET['units'];
    $_SESSION['value'] = $_GET['value'];
    There ya go, the GET values from the URL are now stored in your session
  • Ah of course! I had put the whole query string into a session variable. Thanks again. :D
  • 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