A. php文件为什么直接可在url中访问执行
php是一种脚本语言,要执行PHP文件就需要web服务器来解析。所以在本地部署web服务器(比如:apache,nginx,IIS等等),然后将PHP文件放在服务目录,打开浏览器地址栏输入访问的地址(url)就可以看到执行该文件的结果了。
B. PHP怎么调用网页
a.php
<?php
/*不知道你是想跳转还是取回网页内容后显示
$type为TRUE时采用页面跳转方式
$type为FALSE时采用取回内容后显示
*/
$type = TRUE;
if( isset( $_GET['url'] ) ){
$url = 'http://' . $_GET['url'];
if( $type ){
header("Location: $url");
}else{
$page = file_get_contents($url);
echo $page;
}
}else{
echo '未设置URL参数';
}
?>
C. php打开URL的几种方法
PHP中打开URL地址的几种方法总结,这里的函数主要用于小偷采集等函数。
1:用file_get_contents
以get方式获取内容
复制代码代码如下:
<?php
$url='http://www..com/';
$html=file_get_contents($url);
//print_r($http_response_header);
ec($html);
printhr();
printarr($http_response_header);
printhr();
?>
示例代码2:用fopen打开url,
以get方式获取内容
复制代码代码如下:
<?
$fp=fopen($url,'r');
printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)){
$result.=fgets($fp,1024);
}
echo"urlbody:$result";
printhr();
fclose($fp);
?>
示例代码3:用file_get_contents函数,以post方式获取url
复制代码代码如下:
<?php
$data=array('foo'=>
'bar');
$data=http_build_query($data);
$opts=array(
'http'
=>array(
'method'=>'POST',
'header'=>"Content-type:
application/x-www-form-urlencoded".
"Content-Length:".strlen($data).
"",
'content'=>$data
),
);
$context=
stream_context_create($opts);
$html=
file_get_contents('http://localhost/e/admin/test.html',false,$context);
echo$html;
?>
示例代码4:用fsockopen函数打开url,以get方式获取完整的数据,包括header和body
复制代码代码如下:
<?
functionget_url
($url,$cookie=false){
$url=parse_url($url);
$query=
$url[path]."?".$url[query];
ec("Query:".$query);
$fp=fsockopen(
$url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
if(!$fp){
returnfalse;
}else{
$request="GET$queryHTTP/1.1";
$request.="Host:$url[host]";
$request.="Connection:Close";
if($cookie)$request.="Cookie:$cookie
";
$request.="";
fwrite($fp,$request);
while(!@feof($fp)){
$result.=@fgets($fp,
1024);
}
fclose($fp);
return$result;
}
}
//获取url的html部分,去掉header
functionGetUrlHTML($url,$cookie=false){
$rowdata=get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return$body;
}
returnfalse;
}
?>
D. PHP如何实现url/do的形式
url/?do是一种URL参数,需要你在后台进行处理,比如你写上一个url:
localhost/index.php?id=123
那么在后台你使用$_GET['id']就可以获取到这个123,然后进行相应的处理,还有就是比如discuz的那种?mod=xxx&action=yyy的那种,原理都是一样的,取得内容后直接进行处理即可。
E. 为什么我这个php程序运行后URL会自动变更为www.localhost
$link = mysql_connect( "localhost", "root", "123456" );
这条语句是有问题的,因为你的数据不是安装在本机,所以你不能用localhost来代替IP地址的写法,所以你这里只能写你空间提供商的IP地址,比如:
$link = mysql_connect( "198.11.11.1", "root", "123456" );写IP地址就不会报错了
F. php在提执行一个 $action之后如何返回原来的url
比如说你从test.php跳转到~/demo.php?action=xxx,顺便POST一个变量过来,刷新的时候文件开头判断这个变量存在不,不存在跳到原始url
G. php如何通过url调用php文件中的方法
题主所描述的这种形式,是MVC设计模式的典型应用。
通过使用PSR4来实现自动加载,可以通过处理路由来实现
//处理路由的方法
staticpublicfunctionroute()
{
//获取的模块
$_GET['m']=isset($_GET['m'])?$_GET['m']:'Index';
//获取行为动作action又叫方法
$_GET['a']=isset($_GET['a'])?$_GET['a']:'index';
$controller='Controller\'.$_GET['m'].'Controller';
//echo$controller;
$c=new$controller();
//$c->$_GET['a']();
call_user_func(array($c,$_GET['a']));
}
最终可实现以下形式:

H. php 如何执行url
PHP:
header('Location: http://www.example.com/');
file_get_contents(http://it.sohu.com/7/1002/17/column20466721_3257.shtml);
I. 几种php访问url的方法
常用的就三种吧,
file_get_contents(), fopen, curl
一般用 curl 扩展的比较多,除此以外还有其他方法
fsockopen 啥的