Sent String in PHP page to another HTML page

Asked

Viewed 526 times

0

Hello,

I started programming in PHP these days and I’m not able to return a String from a PHP page that runs in Backend to a PHP page with HTML and present this String

Edited: I will explain the process as a whole to improve the Understanding, I have a PHP initial page that contains only HTML that loads the TXT file for reading in this second PHP page with the code below. I need to return to a php page with HTML and show it to the User

$uploaddir = 'tempArq/';
$uploadfile = $uploaddir . $_FILES['Arquivo']['name'];
if (move_uploaded_file($_FILES['Arquivo']['tmp_name'], $uploadfile)) {
    echo "Arquivo Enviado<br/>";
    $retorno;
    $ponteiro = fopen($uploadfile, "r");
    $arr = array();
    while (!feof($ponteiro)) {
        $linha = fgets($ponteiro, 4096);
        array_push($arr, $linha);
        if (strlen($linha) >= 10){
        $resultado = ConsultaWebserices($linha);
        $retorno = "TiqueteID : $linha : Status" + $resultado;
    }else {
        echo "Tiquete ID $linha Invalido <br/>";
    }
}
fclose($ponteiro);
unlink($uploadfile);

I need to take the Value $return and call a PHP page with HTML and present this value in a Table. How do I make this call from the other page and get the $return amount on the other page to Submit.

  • 1

    It seems that this is a function that returns something, you could turn it into a function and only give a Return, or also if that’s not what you want and you want to move with the values through the cookie pages use http://php.net/manualen/features.cookies.php

  • concatenation in php is a point (.) so it would be $retorno = "TiqueteID : $linha : Status ".$resultado;

  • This one of yours if already works?

  • You can make in the own page of this processing or send to another page

  • Yes If Works, and I already modified the concatenation @adventistaam I don’t understand

2 answers

1

Includes the file on your page and calls the variable or whatever it is, ex the placeholder the input text:

<!DOCTYPE html>
<html>
<head>
    <title>

    </title>
</head>
<body>

<?php 

include 'seuarquivo.php';
//Suponde que a variável $texto exista no 'seuarquivo.php'
    echo "<input type='text' name='text' placeholder='$texto'>";
?>

</body>
</html>
  • That way if he has htmls in the other file the same will be shown on this page where he include

  • I think I did not detail a little superficially, I have a PHP HTML home page that loads a TXT file and calls this page that is pasted at the beginning, after the execution of this page I want to pick up the result and open a third page with the return.

1


Taking advantage of the block you reported can do two ways

    $uploaddir = 'tempArq/';
    $uploadfile = $uploaddir . $_FILES['Arquivo']['name'];
    if (move_uploaded_file($_FILES['Arquivo']['tmp_name'], $uploadfile)) {
        echo "Arquivo Enviado<br/>";
        $retorno;
        $ponteiro = fopen($uploadfile, "r");
        $arr = array();
        while (!feof($ponteiro)) {
            $linha = fgets($ponteiro, 4096);
            array_push($arr, $linha);
            if (strlen($linha) >= 10){
            $resultado = ConsultaWebserices($linha);
            $retorno = "TiqueteID : $linha : Status" + $resultado;
        }else {
            echo "Tiquete ID $linha Invalido <br/>";
        }
    }
    fclose($ponteiro);
    unlink($uploadfile);

1st form

$uploaddir = 'tempArq/';
    $uploadfile = $uploaddir . $_FILES['Arquivo']['name'];
    if (move_uploaded_file($_FILES['Arquivo']['tmp_name'], $uploadfile)) {
        echo "Arquivo Enviado<br/>";
        $retorno;
        $ponteiro = fopen($uploadfile, "r");
        $arr = array();
        $retorno = ""; 
        while (!feof($ponteiro)) {
            $linha = fgets($ponteiro, 4096);
            array_push($arr, $linha);
            if (strlen($linha) >= 10){
               $resultado = ConsultaWebserices($linha);
               $retorno .= "TiqueteID : $linha : Status" . $resultado."\n";
            }else {
               echo "Tiquete ID $linha Invalido <br/>";
            }
       }

    //mostrando o retorno na mesma página do processamento do arquivo:
    echo $retorno;
  }
    fclose($ponteiro);
    unlink($uploadfile);

2nd Way using the header

    $uploaddir = 'tempArq/';
    $uploadfile = $uploaddir . $_FILES['Arquivo']['name'];
    if (move_uploaded_file($_FILES['Arquivo']['tmp_name'], $uploadfile)) {
        echo "Arquivo Enviado<br/>";
        $retorno;
        $ponteiro = fopen($uploadfile, "r");
        $arr = array();
        $retorno = ""; 
        while (!feof($ponteiro)) {
            $linha = fgets($ponteiro, 4096);
            array_push($arr, $linha);
            if (strlen($linha) >= 10){
               $resultado = ConsultaWebserices($linha);
               $retorno .= "TiqueteID : $linha : Status" . $resultado."\n";
            }else {
               echo "Tiquete ID $linha Invalido <br/>";
            }
       }


  }
    fclose($ponteiro);
    unlink($uploadfile);
   //enviando o valor para outra página
   header ("location: suapagina.php?retorno=".$retorno);

Then on the other page you get

$retorno = $_GET['retorno'];
echo $retorno
  • I checked, but the header ("Location: your.php page? return=". $return); does not go up another page and the first example does not forget on the screen. The header ("Location: suapagina.php? retorno=". $return); on "your.php page" I put the internal path of the page, because my files are separated by packages and even mapping it does not open Example "header ("Location: APP VIEWS PGVIEW closedPreBaixa.php? return=". $return);"

  • How so: o primeiro exemplo não esquece na tela? And não sobe a outra?

  • That depends on the file that reads your text file

  • Are you using any framework?

  • I need the return open another page in php with the $return printed on this page the complication that after the execution of this code. //sending value to another page header ("Location: your page.php?return=".$return) Do not open my page.

  • Give any message? Why don’t you store $return in vector? by header it finds the next page?

  • No Msg appears, only the page does not open is a bank page does not load the necessary page, if it opens the page already resolves

  • There are ways you can put your code in github for us to analyze?

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.