导航:首页 > 编程语言 > php获取来路页面

php获取来路页面

发布时间:2023-08-26 11:41:38

php 获取来源页面URL

$_SERVER['HTTP_REFERER']

是可以的。

你做两个页面。t1/php ,t2.php
t1.php 的页面输出
$_SERVER['HTTP_REFERER'] 和
<a href='t2.php'>t2.php</a>

t2.php 的页面输出
$_SERVER['HTTP_REFERER'] 和
<a href='t1.php'>t1.php</a>

你就可以看到效果了。

当然直接输入地址:$_SERVER['HTTP_REFERER']=“”,通过两个超链接互相访问就考到
$_SERVER['HTTP_REFERER'] 的值了。

Ⅱ php获取指定网页内容

一、用file_get_contents函数,以post方式获取url

<?php

$url='http://www.domain.com/test.php?id=123';

$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

)

);

$ctx= stream_context_create($opts);

$html= @file_get_contents($url,'',$ctx);

二、用file_get_contents以get方式获取内容

<?php

$url='http://www.domain.com/?para=123';

$html=file_get_contents($url);

echo$html;

?>

三、用fopen打开url, 以get方式获取内容

<?php

$fp=fopen($url,'r');

$header= stream_get_meta_data($fp);//获取报头信息

while(!feof($fp)) {

$result.=fgets($fp, 1024);

}

echo"url header: {$header} <br>":

echo"url body: $result";

fclose($fp);

?>

四、用fopen打开url, 以post方式获取内容

<?php

$data=array('foo2'=>'bar2','foo3'=>'bar3');

$data= http_build_query($data);

$opts=array(

'http'=>array(

'method'=>'POST',

'header'=>"Content-type: application/x-www-form-

urlencoded Cookie:cook1=c3;cook2=c4 " .

"Content-Length: " .strlen($data) ." ",

'content'=>$data

)

);

$context= stream_context_create($opts);

$html=fopen('http://www.test.com/zzzz.php?id=i3&id2=i4','rb',false,$context);

$w=fread($html,1024);

echo$w;

?>

五、使用curl库,使用curl库之前,可能需要查看一下php.ini是否已经打开了curl扩展

<?php

$ch= curl_init();

$timeout= 5;

curl_setopt ($ch, CURLOPT_URL,'http://www.domain.com/');

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,$timeout);

$file_contents= curl_exec($ch);

curl_close($ch);

echo$file_contents;

?>

Ⅲ php如何获取当前页面url路径

function curPageURL() {
$pageURL = 'http';

if ($_SERVER["HTTPS"] == "on")
{

$pageURL .= "s";
}
$pageURL .= "://";

if ($_SERVER["SERVER_PORT"] != "80")
{

$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] .

$_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"] .

$_SERVER["REQUEST_URI"];
}
return $pageURL;}?>

(3)php获取来路页面扩展阅读:

  1. 获取域名或主机地址 :echo $_SERVER['HTTP_HOST'].""; #localhost

  2. 获取网页地址:echo $_SERVER['PHP_SELF'].""; #/blog/testurl.php

3.获取网址参数:echo $_SERVER["QUERY_STRING"].""; #id=5

4.获取用户代理:echo $_SERVER['HTTP_REFERER']."";

Ⅳ 请问下 php 怎么获取 ajax 请求 来源页面的 完整 url 地址啊

PHP在经常要用到上一页的地址,如在设置要登陆跳转的页面上。
$_SERVER['HTTP_REFERER'] //可以得到上一页的地址
$_SERVER[PHP_SELF] //得到当前页面地址
$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"] //这个可以得到带参数的地址

Ⅳ php如何获取调用页面的来源地址

使用PHP编写程序的时候,想要获取当前页面的URL,可以了用函数来实现;

参考方法如下:

php
//说明:获取完整URL
functioncurPageURL()
{
$pageURL='http';
if($_SERVER["HTTPS"]=="on")
{
$pageURL.="s";
}
$pageURL.="://";
if($_SERVER["SERVER_PORT"]!="80")
{
$pageURL.=$_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$pageURL.=$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return$pageURL;
}
?>
阅读全文

与php获取来路页面相关的资料

热点内容
数据库查询系统源码 浏览:614
php5314 浏览:354
完美国际安装到哪个文件夹 浏览:666
什么app可以扫一扫做题 浏览:537
程序员编码论坛 浏览:923
淘点是什么app 浏览:658
中国高等植物pdf 浏览:453
51单片机时间 浏览:181
后台如何获取服务器ip 浏览:264
单片机流水灯程序c语言 浏览:232
程序员第二职业挣钱 浏览:237
运行里怎么输入服务器路径 浏览:837
pythonstepwise 浏览:508
刘一男词汇速记指南pdf 浏览:61
php认证级别 浏览:366
方舟编译啥时候推送 浏览:1009
php手机验证码生成 浏览:674
哲学思维pdf 浏览:14
凌达压缩机有限公司招聘 浏览:533
weblogic命令部署 浏览:35