将参数添加到 iframe 源

Add parameter to iframe source

我需要在我的 Android 应用 WebView 中显示一个 iframe,该 iframe 存在于位于网络服务器上的 HTML 文件中。 在根据用户输入在 WebView 中显示它之前,我需要向 iframe 源添加一个参数。

我的php代码:

    <?php

    if (isset($_POST['amount'])){
        $amount = $_POST['amount'];
        $intamount = (int)$amount;
        echo $intamount;
    }

    if (isset($_POST['currency'])){

        $currency = $_POST['currency'];
        $intcurrency = (int)$currency;
    }

    if (isset($_POST['lan'])){

        $lan = $_POST["lan"];
    }

    if (isset($_POST['email'])){

        $email_address = $_POST["email"];
    }

    if (isset($_POST['name'])){

        $name = $_POST['name'];
    }




    $iframe_source = 'https://sampleurl.php?sum='.$intamount.'&currency='.$intcurrency.'&cred_type=1&trButtonColor=008080&email='.$email_address.'&contact='.$name;

    echo $iframe_source;

?>

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8"/>



    </head>

    <body>


        <iframe width="370" height="455" src="<?php
            echo $iframe_source;
        ?>" frameborder="5" allowfullscreen></iframe>

    </body>

</html>

例如,我可以向 php 文件发出 post 请求来执行此操作吗?如果是,有没有办法在 php 文件中添加 html 代码并将其显示在我的 WebView 中? 有一个更好的方法吗? 非常感谢。

为什么不在收到用户输入后从您的 Web 服务器加载 PHP。

您可以执行 POST 或 GET 请求。

所以加载的状态http://example.com/webview.htmlhttp://example.com/webview.php?user_paramter=value

现在 webview.php 看起来与 webview.html 基本相同,但有一些小的变化:

<?php
    $user_paramter = $_GET['user_paramter'];
    $link = 'https:iframedemo.php?sum=13&currency=1&user_paramter=' . $user_paramter;
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
    </head>
    <body>
        <iframe width="370" height="455" src="<?php
            echo $link;
        ?>" frameborder="0" allowfullscreen></iframe>
    </body>
</html>

您的应用程序将收到一个具有正确 iframe source/Link

的 HTML 文件

如果 PHP 脚本在用户输入之前被接收,那么 $_POST$_GET 是空的,没有任何作用。因此,如果您在 PHP 脚本的开头执行 var_dump($_POST) 并且您有类似 array(0) {} 的内容,那么问题不在于 PHP 脚本或 iframe 本身。您必须找到一种在用户输入后如何调用页面的方法。