du5739 2012-07-07 19:09
浏览 85
已采纳

登录脚本的主要支持

Whenever I change pages to like blog or forum it looses the session. I then click login and it has the session so its says your already logged in.Support? ---> http://www.kdogisthebest.webege.com/

username: demouser

password: demouser

login.php

<?php session_start();  require_once('connections/Main.php');

if($_SESSION['username']) {

    echo '<div class="error_message">Attention! You, '.$_SESSION['username'].' are already logged in.</div>';   echo "<br />";  echo "Go <a target='top' href='index.php'>back</a> to the page you were viewing before this.</li>";     
exit(); }

.../// Skipped database check ///...

// Check that at least one row was returned 
    $rowCheck = mysql_num_rows($result); 

    if($rowCheck > 0) { 
    while($row = mysql_fetch_array($result)) { 

      // Start the session and register a variable 
      if(isset($_POST['remmemberme'])){
          setcookie(kitbusername, $uesr, time()*24);
      }
      $_SESSION['username'] = $user;
      //session_register('username'); 

      echo '<script> parent.document.location.href = "index.php"; </script>';

      } ?>

logout.php

<?php 
session_start();
// unset cookies
if (isset($_SERVER['HTTP_COOKIE'])) {
    $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
    foreach($cookies as $cookie) {
        $parts = explode('=', $cookie);
        $name = trim($parts[0]);
        setcookie($name, '', time()-1000);
        setcookie($name, '', time()-1000, '/');
    }
}
if($_SESSION['username']) {
session_unset(); 
session_destroy(); 
header("Location: index.php"); } 
else { header("Location: index.php"); } ?>

header.php

<div id="loginoutbox" class="ablack">
<div style="display: inline-block; font-size: 14px; padding-left: 20px;">Hello <?php  if($_COOKIE['kitbusername']) { echo $_COOKIE['kitbusername'];} else {echo $_SESSION['username'];} ?>! | </div>
<a id="register" href="http://www.kdogisthebest.webege.com/admin/" class="button">Dashboard</a> |
<a id="signin" href="#fallr-confirmlike" class="button">Logout</a>      
<?php }else{ ?>
<div style="display: inline-block; font-size: 14px; padding-left: 20px;">Hello Guest!</div>
<a id="register" href="#fallr-register" class="button">Register</a> |
<a id="signin" href="#fallr-signin" class="button">Login</a>
<?php } ?>
</div>
</div>
  • 写回答

1条回答 默认 最新

  • dongmu1914 2012-07-07 19:35
    关注

    I noticed that the variable $user is misspelled as $uesr in the setcookie function. If that was not your intention, that could possibly be the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀