PHP头条
热点:

phpsession有关问题


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

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

//index.php

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


//page.php

session_start();
echo $_SESSION['login'];

if(empty($_SESSION['login'])||$_SESSION['login']!='ok') //未登陆则跳回index
{
  ?>《script》setTimeout('window.location="index.php"', 1000);《script》 }
.....
.....

function goBack()
{
    AjaxTest();
    window.location.href = "./index.php";
}

function AjaxTest()
    {
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url = "ajax.php";
        url += "?login=out";
        xmlHttp.onreadystatechange=stateChanged 
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
    }

    function stateChanged() 
    { 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
            alert(xmlHttp.responseText );
        } 
    }

    function GetXmlHttpObject()
    {
        var xmlHttp=null;
        try
        {
            // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
            // Internet Explorer
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

www.phpzy.comtrue/phprm/5961.htmlTechArticlephpsession有关问题 php session问题 本帖最后由 u010001532 于 2013-06-08 18:00:51 编辑 我想用session实现登录用户访问特定页面,未登录用户不能访问。 但是现在直接在浏览器输入page的地址可以直...

相关文章

相关频道:

PHP之友评论

今天推荐