0

I am implementing a payment system into my website. When making a payment, i create a transaction_id and a order_id. The transaction_id is needed by the third party in order to make a succesful payment. The order_id is for me to identify which order comes with which transaction.

After making a payment, the user returns to the 'return page'. this URL would be something like: 'www.myawesomewebsite.com/return' however, it add the order_id after the link. So this url would look like: 'www.myawesomewebsite.com/return?#31102014033349-3'.

When i am on this page, i want to parse the URL in order to retrieve the order_id. However, if i do something like this:

array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(17) "www.myawesomewebsite.com" ["path"]=> string(27) "/return"

As you can see, it doesn't return the query in the URL. If i var_dump(Request::url()); It also returns "www.myawesomewebsite.com/return". Somehow it can't 'see' the order_id in the URL.

My question, how can i successfully retrieve the order_id?

Jeroen
  • 167
  • 2
  • 16
  • 3
    See here: http://stackoverflow.com/questions/3664257/why-the-hash-part-of-the-url-is-not-in-the-server-side. The solution is to use a real variable like `?var=31102014033349-3` – jeroen Oct 31 '14 at 15:14
  • 1. nowhere in the URL is there `order_id` 2. anything after `#` is not passed to the server. – AbraCadaver Oct 31 '14 at 15:14
  • @AbraCadaver 1. '#31102014033349-3' is the order_id. 2. i changed the order_id to only contain numbers. It still can't read it. – Jeroen Oct 31 '14 at 15:16
  • @jeroen so what you are saying is i have to use jquery to get the order_id? I don't think it is possible in this case to use jquery. – Jeroen Oct 31 '14 at 15:18
  • Use this type of URL `http://www.myawesomewebsite.com/return?order_id=31102014033349-3` – CS GO Oct 31 '14 at 15:18
  • No, query is not the right word here. You need to generate a valid *query string* like in my example. – jeroen Oct 31 '14 at 15:19
  • 1. NO 2. Reread my #2. The only way to do this with PHP is how @AncientGeek stated. – AbraCadaver Oct 31 '14 at 15:21
  • @jeroen ugh, misinterpretation of query.. my bad. I'll try your example. Will let you know. Ancient Geek, will let yo know too – Jeroen Oct 31 '14 at 15:21
  • 3
    WTF!?!? Are there two @Jeroen here? My brain almost exploded trying to follow this! – AbraCadaver Oct 31 '14 at 15:23
  • @AbraCadaver hahahahhahah – Jeroen Oct 31 '14 at 15:24

1 Answers1

2
<?php

    $url = "http://www.myawesomewebsite.com/return?order_id=31102014033349-3";

    $host = parse_url( $url );

    var_dump( $host );

?>


Output:

array(4) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(24) "www.myawesomewebsite.com"
  ["path"]=>
  string(7) "/return"
  ["query"]=>
  string(25) "order_id=31102014033349-3"
}

OR simple get by :

$_GET["order_id"];
CS GO
  • 914
  • 6
  • 20
  • Just found out $_GET['order_id']; does the trick. And BTW, your output isn't correct. The query isn't there (in my case). – Jeroen Oct 31 '14 at 15:29