PHP: transferring a large array between two sites

I am trying to pass a large array between two sites in PHP. I am an administrator in both. An array is created on one site, and after its creation, I want to automatically redirect the user to another site and transfer the processed array.

I can’t use SEXION superglobal because it is limited to a specific domain. GET is not suitable because the array is too long. I'm not sure if POST is suitable, and if there is a way to automatically send data without forcing the user to click a button and submit some form. I know javascript can be used for this, but prefer to have something more robust.

I am relatively new to PHP and would like to hear about other ways to accomplish this. Thank!

+3
source share
10 answers

The easiest way is to use an HTTP library such as cURL and configure and send the POST request to another site. In addition, the IP address of users will allow you to link published data. Without JavaScript, you cannot redirect the user with POST data.

One thing you might want to learn about using the above method is that depending on how it is implemented, the user may arrive before the data is executed.

POST, HTTP, , ( , ) php. ( POST, -, 8 )

+4

HTTP POST cURL serialize() ed .

+2

- :

  • A (, sha1 (timestamp + session id + random()))
  • cURL B,
  • B - : (CHAR), (BLOB)
  • http://ServerB/?data_token=[TOKEN GENERATED IN STEP 1]
  • B , db, db .
+2
+1

:

(ar) (a) (b)

:

  • (a) url (url) (b), Array ( ar), , , json json_encode (ar). Array (ar) url, , , mysql .

    $uid = md5(uniqid(mt_rand(), true)); // to generate unique id
    
  • (a) (b), $uid

    $url = "http://server-b/page"; // url to page
    header('Location: $url?uid=$uid');
    
  • (b) url (a) ()

    $uid = $_GET['uid']; // uid
    $url_server_a = "http://server-a/webservice?uid=$uid";
    $ar = json_decode(file_get_contents($url_server_a));
    
+1

, , , , . , , , , .

: , , ...

0

, "" ( -), . 2 1, ""

0

, : , memcache , .

0

, . ( = "POST" ) .

0

JSON , JSON, JSON PHP, LONG-URL.

0

Source: https://habr.com/ru/post/1724655/


All Articles