有一个很难的问题,php获取javascript的值来判断域名来路,后期不好处理~
全部代码如下
首先你在浏览器中运行,打开控制台观察
http://localhost/test.php
<a href="test1.php">跳转到test1</a>
<?php<br />session_start();<br />require "./test2.php";<br />class A{<br /> function __construct()<br /> {<br /> $b=new B();<br /> $b->judge();<br /> }<br /> function judge()<br /> {<br /> if($_SESSION['status']==1){<br /> return true; <br /> }else{<br /> return false; <br /> }<br /> }<br /> function run()<br /> {<br /> if($this->judge()){<br /> echo 'success'; <br /> }else{<br /> echo 'error'; <br /> }<br /> }<br />}<br />$a=new A();<br />$a->run();<br />?>
<?php<br />session_start();<br />class B{<br /> function judge()<br /> {<br /> echo '<script><br /> var xmlhttp;<br /> if (window.ActiveXObject){<br /> xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");<br /> }else{<br /> xmlhttp = new XMLHttpRequest();<br /> }<br /> xmlhttp.open("POST", "./test3.php", true);<br /> xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");<br /> xmlhttp.send("data="+document.referrer);<br /> console.log(document.referrer); //控制台观察<br /> xmlhttp.onreadystatechange = function(){<br /> if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {<br /> }<br /> };</script>';<br /> }<br />}<br />?>
<?php<br />session_start();<br />if(stristr($_POST['data'], 'localhost')){<br /> $_SESSION['status']=1;<br /> }else{<br /> $_SESSION['status']='';<br /> }<br />?>