How to pass data from one php to another without form? [closed]

-3

A very simple question, however, I do not know or remember. How can I send data from one php file to another, tb in php? This is not the case for form.

File 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 file:

<?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));

        }
    }
    
asked by anonymous 11.07.2016 / 22:28

2 answers

3

try this in file2.php :

include 'Arquivo1.php';

public function Alguma_Função() {
    global $msg;
}

or

include 'Arquivo1.php';
private $newmsg = '';

public function setMSG() {
    global $msg;
    $this->newmsg = $msg;
}
    
12.07.2016 / 22:46
2

It's very difficult to understand your question. But some alternatives:

Redirect from file1 to file2 passing data via GET (roughly):

Your URL would be link

And in file2 you recover using $ _GET : For example:

$variavel1 = $_GET['variavel1'];

Another way is for you to store this in a global variable, include file1 in file2 and retrieve it.

Using sessions

No file1

session_start();
$_SESSION['msg'] = $_GET['msg'];
header('Location: arquivo2.php');

No file2

session_start();
$msg = $_SESSION['msg'];
    
12.07.2016 / 21:33