简体   繁体   English

我一直回到php登录页面

[英]i keep coming back to login page in php

newbie here... so yeah, i already tried searching all those page-related about my question, but im still stuck... anyway, my problem is that i always keep getting back at my login page, which is my index.php oh btw, im still using PHP version 4.4.8 here is my code for my problematic main page, main.php 新手在这里...所以,是的,我已经尝试搜索所有与我的问题相关的页面,但是我仍然卡住了...无论如何,我的问题是我总是一直回到我的登录页面,这就是我的index.php哦,顺便说一句,我仍在使用PHP 4.4.8版,这是我有问题的主页main.php的代码

 <?php session_start(); include '../config.php'; if(!isset($_SESSION['admin'])){ header("location:index.php"); } ?> <!DOCTYPE HTML> <html> <head> <title>KSP Setia Finance</title> </head> <body> <h1>test page</h1> </body> </html> 

and here is my login page code, which is index.php 这是我的登录页面代码,即index.php

 <?php session_start(); include '../config.php'; ?> <!DOCTYPE html> <html > <head> <title>Login Form</title> </head> <body> <div class="login"> <h1>Login</h1> <form action="login_act.php" method="post"> <input type="text" name="username" placeholder="Username" required="required" /> <input type="password" name="password" placeholder="Password" required="required" /> <button type="submit" name="login" value="Login" class="btn btn-primary btn-block btn-large">Log In</button> </form> </div> <script src="js/index.js"></script> </body> </html> 

since everyone asking, here my login_act.php, already inserted with session_start 因为每个人都在问,这是我的login_act.php,已经插入了session_start

 <?php session_start(); include('../config.php'); if(isset($_POST['login'])){ $user = mysql_real_escape_string(htmlentities($_POST['username'])); $pass = mysql_real_escape_string(htmlentities(md5($_POST['password']))); $sql = mysql_query("SELECT * FROM user WHERE username='$user' AND password='$pass'") or die(mysql_error()); if(mysql_num_rows($sql) == 0){ echo 'User not found'; }else{ $row = mysql_fetch_assoc($sql); if($row['level'] == 1){ $_SESSION['admin']=$user; echo '<script language="javascript">alert("u are Login as Admin!"); document.location="index.php";</script>'; }else echo 'sorry, u cant access this one'; } } ?> 

在main.php上打印$ _SESSION的值,并检查是否有任何键作为'username'并检查login.php,您在$ _SESSION数组中存储了什么值

so i recently asking my friends, and here is the results: all i need is just put those $SESSION_START above all, or make another php and link them all. 所以我最近问我的朋友,这是结果:我需要的只是将$ SESSION_START放在首位,或者制作另一个php并将它们链接在一起。 so here my latest result that worked : main.php 所以这是我最新的有效结果:main.php

 <?php include 'access.php'; ?> <!DOCTYPE HTML> <html> <head> <title>KSP Setia Finance</title> </head> <body> <h1>test page</h1> </body> </html> 
access.php access.php

 <?php session_start(); if(!isset($_SESSION['admin'])){ echo '<script language="javascript">alert("you must Login!"); document.location="../index.php";</script>'; } ?> 

and last, config.php 最后是config.php

 <?php session_start(); mysql_connect("localhost","root",""); mysql_select_db("koperasi"); ?> 

i deleted that broken login_act.php, and making all the page i had to be linked directly with the access.php, which make it easier to manage the session. 我删除了损坏的login_act.php,并使所有页面都必须直接与access.php链接,这使得管理会话更加容易。 thank you to all that bear with my php problem and stupidity. 谢谢所有与我的PHP问题和愚蠢有关的人。 hope this all gonna help those who still wandering and asking the same question. 希望所有这些对仍在徘徊并询问相同问题的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM