一个PHP Web浏览器

问题描述 投票:0回答:2

我随机尝试开发一个可以在PHP中运行的Web浏览器。我知道这是一个非常小的程序,如果你研究它,但我似乎没有让它工作。虽然我已经解决了,但我不能让它显示页面。

请看下面的代码并告诉我我错过了什么。

<?php
    $address = $_GET['address']
?>

<html>
    <head>
        <title>NeXon Web</title>
        <link href="css/style.css" type="text/css" media="all"/>
    </head>

    <body>
        <div id="header">
            <img src="images/logo.png" id="logo"/>
            <img src="images/back.png" id="back" />
            <img src="images/fwd.png" id="fwd"/>
            <form method="GET" action="index.php">
                <input name="address" type="address" id="address" placeholder="Address..."/>
                <input type="submit" value="Go" id="submit"/>
            </form>
        </div>
        <div id="body">
            <iframe src="<?php $address ?>" id="frame" height="800px" width="1100px" />
        </div>
    </body>
</html>

我写了这段代码,但似乎没有显示网页。我尝试了POST和GET方法。请帮忙,我还是个新手:/

第二个代码是由其他人编写的,在他告诉我该怎么做后我无法联系,我需要在第二个代码中提供认真的帮助,

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
@import="style.css";
</style>
</head>

<body>
<?php
if($_POST){

$url=$_POST['url'];



}
?>
<script language="javascript">

function w(){  window.open('$url');  }

</script>


<div class="box">
    <form method="post" action="index.php">
        Address: <input type="text" name="url" id="url" class="input_text" />
        <input type="submit" value="submit" class="button">
    </form>
</div>

<div class="url">



</div>
</body>
</html>

说实话,我真的不知道第二个代码是如何工作的:/

php browser
2个回答
2
投票

你的第一个代码非常接近:

<iframe src="<?php $address ?>" id="frame" height="800px" width="1100px" />

做那个

<iframe src="<?php echo $address; ?>" id="frame" height="800px" width="1100px" />

2
投票

首先,我要说现在很多网站都不会出现在没有存储在同一台服务器上的iframe中。例如,我不能使用以下代码并期望它工作。

<iframe src="http://www.google.com"></iframe>

上面的代码会在我的页面上显示一个大白框。这是由于same origin policy

现在您可能会错误地向一些公司发送信息以允许您访问。如果他们在那里使用PHP,他们可以使用以下方法。

<?php header('Access-Control-Allow-Origin: *'); ?>

然而,这不仅对你而且对公司来说也是一个麻烦。更不用说给他们带来安全风险了。用你的代码我玩它。它可以在我的服务器上使用POST而不是GET。但就像我说使用iframe甚至许多标准形式的ajax请求来实现你的目标非常困难。您需要非常有创意才能将其作为Web浏览器使用。

你可能想尝试一些类似的东西

<?php
ini_set("user_agent","Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/BuildID) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36");
$data = file_get_contents("http://www.example.com",0);
?>  

用您选择的用户代理替换上述用户代理。我将不得不更多地玩这个,但我希望我帮助。

© www.soinside.com 2019 - 2024. All rights reserved.