php session问题
PHP session
我想用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><?}..........<script language="javascript">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"); } } return xmlHttp; }</script>
//ajax.php
<? $login = $_GET["login"]; session_start(); unset($_SESSION['login']); session_destroy(); echo "success";?>
回复讨论(解决方案)
你访问page.php页面时 输出的session有值么?
还有最后在page.php的if中跳页面后面加上exit;
你访问page.php页面时 输出的session有值么?
还有最后在page.php的if中跳页面后面加上exit;
登录了打印的是ok
加了exit也是一样
你访问page.php页面时 输出的session有值么?
还有最后在page.php的if中跳页面后面加上exit;
登录了打印的是ok
加了exit也是一样
你已经登录了,当然可以直接访问page.php了
你访问page.php页面时 输出的session有值么?
还有最后在page.php的if中跳页面后面加上exit;
登录了打印的是ok
加了exit也是一样
你已经登录了,当然可以直接访问page.php了
但是通过goBack返回到index,还是可以直接在浏览器输入page的地址直接访问
你访问page.php页面时 输出的session有值么?
还有最后在page.php的if中跳页面后面加上exit;
登录了打印的是ok
加了exit也是一样
你已经登录了,当然可以直接访问page.php了
但是通过goBack返回到index,还是可以直接在浏览器输入page的地址直接访问
session 保存在服务器端,你已经登录过了之后,就存在这个状态,所以你可以直接访问page.php。除非你触发退出登录功能,或者干掉session。
你访问page.php页面时 输出的session有值么?
还有最后在page.php的if中跳页面后面加上exit;
登录了打印的是ok
加了exit也是一样
你已经登录了,当然可以直接访问page.php了
但是通过goBack返回到index,还是可以直接在浏览器输入page的地址直接访问
session 保存在服务器端,你已经登录过了之后,就存在这个状态,所以你可以直接访问page.php。除非你触发退出登录功能,或者干掉session。
对啊,我就是要干掉session,但还是不行额。。。
session_start();
unset($_SESSION['login']);
session_destroy();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:
