0
I have a PHP that after performing an operation it calls an external URL and returns the value of this external URL, using curl_exec.
However, I need to pass a parameter to this new url, preferably as a session one. How can I pass this parameter which in this case is:
$transactionReference
Follows my code:
echo 'codigo da transação: '.$transactionReference;
// chama a url de geração da nota fiscal
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://nhaac.com/envianfe.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $transactionReference);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
Just to illustrate the other PHP that this call makes is like this:
<?php
session_start();
require 'conexao.php';
if($transactionReference):
echo 'codigo do fornecedor já no nfe: '.$transactionReference;
endif;
require_once ('client-php/lib/init.php');
echo 'codigo do fornecedor já no nfe: '.$transactionReference;
..
..
..
..
..
Maybe this is where I’m not knowing how to pick up the variable.
I don’t understand what you mean by "I need to pass a parameter to this new url,". What’s in
$transactionReference
?– Inkeliz
$transactionReference is the reference code of an ID of my table that should be used there in this new URL, to return the value I want.
– Ramos
Possible duplicate of As I pass parameters through Curl?
– Daniel Omine
@Danielomine is similar to this one. But I want to pass a parameter, preferably as a session.
– Ramos
Maybe it’s the other PHP, I’ll edit the question showing the other PHP...
– Ramos
just modify post by get... But it seems that you have a secondary doubt that is to receive the parameter. For this, just invoke
$_GET['nome_variavel']
or$_POST['nome_variavel']
. But there is also another issue that is going through session. If both pages are from the same domain, you can simply set up the session on the first page without the need for Curl, request, etc.. It is confused and unfocused what you ask for. If it is not duplicated it is "not clear enough"..– Daniel Omine