Reputation: 540
I was randomly trying to develop a web browser that works in PHP. I know this is a really small program if you look into it but I don't seem to get it to work. though I have worked it out, but I cant get it to display pages.
Please have a look at my code below and tell me what I'm missing.
<?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>
I wrote this code, but did not seem to be getting the webpage to display. I tried both POST and GET methods. Please help, Im still a newbie :/
The second code was written by someone else, who I could not contact after he told me what to do, I would need serious help in the second code,
<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>
To be honest I seriously do not know how the second code is working :/
Upvotes: 2
Views: 11584
Reputation: 321
First of all I will say that many websites these days wont show up in iframes that are not stored on the same server. For example I can't use the following code and expect it to work.
<iframe src="http://www.google.com"></iframe>
The above code will display a big white box on my page. That is due to same origin policy
Now it is possible for you to bug a few companies to allow access for you. If they are using PHP in there site they can do it by using the following.
<?php header('Access-Control-Allow-Origin: *'); ?>
However that would be a hassle to not just you but to the companies as well. Not to mention a security risk to them. With your code I played around with it. And it works on my servers using POST instead of GET. But like I said it is very difficult to achieve your goals using iframes or even many standard forms of ajax request. You will need to be very creative to get this to work as a web browser.
You may want to try something along the lines of
<?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);
?>
Replace the above user agent with a user agent of your choice. I'll have to play around with this some more but I hope I helped.
Upvotes: 3
Reputation: 29985
Your first code looks pretty close:
<iframe src="<?php $address ?>" id="frame" height="800px" width="1100px" />
Make that
<iframe src="<?php echo $address; ?>" id="frame" height="800px" width="1100px" />
Upvotes: 3