PHP编码逻辑

时间:2017-07-26 01:35:22

标签: php mysql session if-statement login

我有一些代码总是在else / if语句中返回$ aid = 1。任何人都可以帮我弄清楚为什么这可能在逻辑中发生?

<?php
session_start();
require('includes/config.php'); 
if(!$user->is_logged_in()){ header('Location: login.php'); }

include_once("config.php");

if(isset($_SESSION['account_id'])) {
$aid = $_SESSION['account_id'];
} else if(isset($_POST['aid'])) {
$aid = $_POST['aid'];
} else if(isset($_GET['aid'])) {
$aid = $_GET['aid'];
} else {$aid='1';}

include_once('includes/top.php');?>

快速背景(如果有帮助)...这是登录。一旦客户登录,我试图只在数据库中显示他们的数据。我已经提取了所有正确的数据,但我无法让登录用户使用正确的account_id进行调用。如果我要将最后的$ aid = 1更改为$ aid = 2,那么它将正确地提取所有account_id = 2信息,但它会为每个登录的人执行此操作。

非常感谢任何建议。

谢谢!

以下是登录功能

<?php 
require_once('includes/config.php');
if( $user->is_logged_in() ){ header('Location: main.php'); } 

if(isset($_POST['submit'])){

    $username = $_POST['username'];
    $password = $_POST['password'];

if($user->login($username,$password)){ 
    $_SESSION['username'] = $username;
    header('Location: main.php');
    exit;

    } else {
        $error[] = 'Invalid username/password or your account has not been activated.';
    }

}
$title = 'Login';
require('layout/header.php'); 
?>

php下面有一些html在表单中调用。如果这也有帮助,我可以加载它。谢谢!

此外,account_id是在管理部分内管理的。数据库的clients表中有一个关联的account_id,用于指定每个用户拥有的帐户。

1 个答案:

答案 0 :(得分:0)

如果其他条件页面您没有发布并获取任何数据,那么post和get方法将无效。然后你需要确保会话设置与否。在此之后,只有你能够找到$ aid的确切值。