URL跳转代码
1.代码:
- <? $url=$_GET["url"];header("Location:"."http://".$url);?>
复制代码
如保存为aaa.php,可以实现aaa.php?url=www.baidu.com跳转到百度的效果.
这个简单的调用了默认的$_GET变量.以及php默认跳转Location:
2.实例升级:增加if循环
代码:
代码如下:
- <?
- $url=$_GET["url"];
- if (strlen($url >=3)){
- header("Location:"."http://".$url);
- }
- ?>
- <html>
- <head>
- <title>URL转向页</title>
- </head>
- <body>
- <form id="url" name="url" method="get" action="#">
- <label>http://
- <input name="url" type="text" value="" />
- </label>
- <input type="submit" name="Submit" value="提交" />
- </form>
- </body>
- </html>
复制代码
|