Home >Backend Development >PHP Tutorial > php session有关问题

php session有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:46:15723browse

php session问题

本帖最后由 u010001532 于 2013-06-08 18:00:51 编辑 我想用session实现登录用户访问特定页面,未登录用户不能访问。

但是现在直接在浏览器输入page的地址可以直接访问。求指导。

//index.php
<br />
session_start();<br />
if(Login() == true)<br />
{<br />
  $_SESSION['login'] = 'ok';<br />
  //跳转到page.php<br />
}<br />
else<br />
{<br />
  echo "Login error";<br />
}<br />


//page.php
<br>
session_start();<br>
echo $_SESSION['login'];<br>
<br>
if(empty($_SESSION['login'])||$_SESSION['login']!='ok') //未登陆则跳回index<br>
{<br>
  ?><script>setTimeout('window.location="index.php"', 1000);</script><br>
}<br>
.....<br>
.....<br>
<script><br />
function goBack()<br />
{<br />
    AjaxTest();<br />
    window.location.href = "./index.php";<br />
}<br />
<br />
function AjaxTest()<br />
    {<br />
        xmlHttp=GetXmlHttpObject();<br />
        if (xmlHttp==null)<br />
        {<br />
            alert ("Browser does not support HTTP Request");<br />
            return;<br />
        }<br />
        var url = "ajax.php";<br />
        url += "?login=out";<br />
        xmlHttp.onreadystatechange=stateChanged <br />
        xmlHttp.open("GET",url,true)<br />
        xmlHttp.send(null)<br />
    }<br />
<br />
    function stateChanged() <br />
    { <br />
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")<br />
        {<br />
            alert(xmlHttp.responseText );<br />
        } <br />
    }<br />
<br />
    function GetXmlHttpObject()<br />
    {<br />
        var xmlHttp=null;<br />
        try<br />
        {<br />
            // Firefox, Opera 8.0+, Safari<br />
            xmlHttp=new XMLHttpRequest();<br />
        }<br />
        catch (e)<br />
        {<br />
            // Internet Explorer<br />
            try<br />
            {<br />
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");<br />
            }<br />
            catch (e)<br />
            {<br />
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); <div class="clear">
                 
              
              
        
            </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn