How can I pass variables from one php file to another on another server?

-1

I need to send several variables from one script to another script that I have on another server, for example the first script gets the title content and tags of the posts created on the web page, so I need to put that data in variable and then send them to the other script that is on another server, which must collect those variables and then use them in the script.

look on the Internet and I found something about using Get but I think it is necessary to click on the link so you can send the data but I just want to pass the variables I do not need any form or buttons because everything is done by means of code does not need interaction with the user.

This is what I found:

//mandar datos
<a href="http://url.pagina.destino/?variable1=valor1&variable2=valor2">Enlace a página de destino</a>

//obtener datos
<?php
$v1 = $_GET['variable1'];
$v2 = $_GET['variable2'];
?>
    
asked by Jose Rodriguez 10.07.2017 в 04:25
source

2 answers

0

To replace the "click" that one would do in the browser you can use Curl from php where you request, send it, and you can receive a response from the remote script confirming that it was received and there were no errors.

The variables you can send with the GET method in the "query" part of the url, or send them with the POST method in the body of the request. In the first case, in the remote script, you raise them with $ _GET and in the second as $ _POST.

Your example arms the url to use the GET option.

EXAMPLE

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://url.pagina.destino/?variable1=" . $v1_validado . "&variable2=" . $v2_validado);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch); 

In $ output you receive the response you send back from the other server.

    
answered by 10.07.2017 в 06:35
0

you have two ways of doing it if it is from backend you can use CURL or Guzzle if it is from frontend you can use an AJAX request validating the CORS if the other script is under another domain

    
answered by 03.12.2017 в 12:49