-3
A very simple question, though, I don’t know or remember. How can I send data from one php file to another, tb in php? Not the case of form.
php 1:
header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,X-Prototype-Version,X Requested-With');
include_once("conPDO.php");
$pdo = conectar();
$msg = utf8_decode($_GET['mensagem']);
$idUsuario = $_GET['idUsuario'];
$idCep = $_GET['idCep'];
$nomeRemetente = $_GET['nome'];
$usuarioRemetente = $_GET['usuario'];
$uf = $_GET['uf'];
$cidade = $_GET['cidade'];
$bairro = $_GET['bairro'];
$logradouro = $_GET['logradouro'];
$dia = $_GET['dia'];
$hora = $_GET['hora'];
$foto = '';
$cidade = utf8_decode($cidade);
$bairro = utf8_decode($bairro);
$logradouro = utf8_decode($logradouro);
header('Location: websocket/src/MyApp/Chat.php?msg='.$msg);
I want to pass these variables, above, to the following php below
php 2:
<?php
$msg = $_GET['msg'];
echo $msg;
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
// Store the new connection to send messages to later
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
public function onMessage(ConnectionInterface $from, $msg) {
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
$dados = json_decode($msg, true);
$dados['id'] = $from->resourceId;
foreach ($this->clients as $client) {
// The sender is not the receiver, send to each client connected
$client->send(json_encode($dados));
}
}
point to the specific location, in the second file, where the variables would be read.. There are several ways to solve from a gross use of
global
to object orientation..– Daniel Omine
Sorry, but what do you mean, point out the specific location in the second file? And it wouldn’t be in the first?
– GustavoSevero
show where the variables of the first file are read in the second file... make a drawing, put a comment in the code, finally
– Daniel Omine
@Danielomine, I can not draw here kkk but put in bold, give a reread.
– GustavoSevero
sorry.. unavailable to reply... need to collaborate if you want some help right, because it takes other people’s time...
– Daniel Omine
Buddy, I’ve put in bold what I need, it doesn’t help?
– GustavoSevero
You have a PHP page that receives the data and you want to pass it on to another PHP page? Why not process the data on the page that receives it?
– Fleuquer Lima
Why this other page is an API that’s ready and I got from git, understand @Fleuquerlima?
– GustavoSevero