dpjr86761 2014-04-17 11:28
浏览 21
已采纳

如何自动将数据从服务器发送回客户端并显示它?

So I have this "client" PHP page, and a "server" PHP page. And I'm trying to send a value from the client to the server using the GET-method. And then I want to send the information back again from the server to the client and display it. How do I accomplish this?

At first the client page contains merely a link to the server page that also sends some information with it. E.g: <a href="server.php?firstname=myfirstname&lastname=nylastname">link</a>

But when the server has sent back the data, I do not want to display the link anymore. I just want to show the information, something like:

first name: myfirstname
last name: mylastname

How do I accomplish this? After doing some research I found this redirect function, but I'm not sure if I can or if I should use it:

function redirect($url, $statusCode = 303){
            header('Location: ' . $url, true, $statusCode);
            die();
        }

And if I should use it: How do I send the data that I need back to the client with it using GET? Can I just do something like:

<?php
    $firstname = $_GET["firstname"];
    $lastname = $_GET["lastname"];

    redirect("client.php?firstname=$firstname&lastname=$lastname") //I'm guessing putting the variables in like this doesn't work...

    function redirect($url, $statusCode = 303){
        header('Location: ' . $url, true, $statusCode);
        die();
    }
?>

But even if this works. I still don't know how to change the appearance of the client page when I send back the data from the server page. Is it even possible?

Oh: And I want to send the information back to the client as the MIME type text/plain

  • 写回答

1条回答 默认 最新

  • dpr81047 2014-04-17 11:56
    关注

    Try this, create a index.php and put this in it.

    <?php
    
    $firstname = $_GET['firstname'];
    $lastname = $_GET['lastname'];
    
    if ($firstname || $lastname){
        $print = true;
    } else {
        $print = false;
    }
    
    ?>
    
    <html>
    <body>
    
    <?php
    if($print==true){
        echo "Firstname: ".$firstaname."<br>Lastname: ".$lastname;
    }
    ?>
    <a href="page2.php?firstname=myfirstname&lastname=nylastname">link</a>
    

    Then make a page2.php and put this in it.

    <?php
    
    $firstname = $_GET['firstname'];
    $lastname = $_GET['lastname'];
    
    header("location: index.php?firstname=$firstname&lastname=$lastname");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line