如何将PHP变量用作iframe元素的URL [英] How to use a PHP variable as an URL for an iframe element
问题描述
我对PHP很陌生(在CodeAcademy学习它),我想用
<!DOCTYPE html>
< html>
< body>
<?php
$ url = $ _GET ['url'];
print $ url;
?>
< form name =inputmethod =get>
Url:< input type =textname =urlaction =<?php echo $ url;?>>
< input type =submitvalue =Go>
< / form>
< iframe src =<?php echo $ url;?>>
< p>您的浏览器不支援iframe。< / p>
< / iframe>
< / body>
< / html>
上面的代码块是一个.php文件。我的问题是,iframe会导致我的域名的URL输入URL。更好的解释在这里。
我尝试使用 $ partial = substr($ url,x,y)
并使iframe 导致 echo $ partial
,这样原始域名就会被删除,只有您输入的网址位于iframe网址中。这没有用。我该如何解决这个问题?
只要检查网址是否有http:// b $ b else您的脚本添加http://
<!DOCTYPE html>
< html>
< body>
<?php
$ url = $ _GET ['url'];
print $ url;
if(strpos($ url,'http')=== 0){//在位置0找到
// ok
} else {
if (strpos($ url,'google')=== 0)或
(strppos($ url,'some.other.site1')=== 0)或
(strppos($ url ,'some.other.site2')=== 0))//在这里所有的知识SSL - 网站(这不可能是最终的解决方案)
{
$ url ='https:// 。$网址;
} else {
$ url ='http://'.$url;
}
}
print'< br />'。$ url;
?>
< form name =inputmethod =get>
Url:< input type =textname =urlaction =<?php echo $ url;?>>
< input type =submitvalue =Go>
< / form>
< iframe src =<?php echo $ url;?>>
< p>您的浏览器不支援iframe。< / p>
< / iframe>
< / body>
< / html>
I'm very new to PHP (Learning it at CodeAcademy) and I wanted to make a web browser kind of thing using an iframe
. This is what I have so far:
<!DOCTYPE html>
<html>
<body>
<?php
$url = $_GET['url'];
print $url;
?>
<form name="input" method="get">
Url: <input type="text" name="url" action="<?php echo $url; ?>">
<input type="submit" value="Go">
</form>
<iframe src="<?php echo $url; ?>">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
The block of code above is a .php file. My problem with this is that the iframe leads to the URL of my domain slash the URL you enter. A little better explanation is here.
I tried using a $partial = substr($url, x, y)
and making the iframe lead to echo $partial
so that the original domain is cut out and only the URL you entered is in the iframe URL. That didn't work. How can I fix this?
just check if the URL has a "http://" then proceed
else add a "http://" by your script
<!DOCTYPE html>
<html>
<body>
<?php
$url = $_GET['url'];
print $url;
if (strpos($url,'http') === 0) { //found at position 0
//ok
} else {
if ((strpos($url,'google') === 0) or
(strppos($url,'some.other.site1') === 0) or
(strppos($url,'some.other.site2') === 0)) // here all the knowns SSL - Sites (this can not be the ultimate solution)
{
$url = 'https://'.$url;
} else {
$url = 'http://'.$url;
}
}
print '<br/>'.$url;
?>
<form name="input" method="get">
Url: <input type="text" name="url" action="<?php echo $url; ?>">
<input type="submit" value="Go">
</form>
<iframe src="<?php echo $url; ?>">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
这篇关于如何将PHP变量用作iframe元素的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!