dpv21589 2017-07-26 01:35
浏览 59

PHP编码逻辑

I have some code that always is returning $aid=1 within an else/if statement. Can anyone help me figure out why this may be happening within the logic?

<?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');?>

Quick background (if it helps)... This is for a login. Once a client signs in I am trying to get only their data within the database to show. I have all of the correct data being pulled, but I cannot get the logged in user to call in the correct account_id. If I were to change the last $aid=1 to $aid=2, then it would correctly pull all of account_id=2 information, but it would do it for every logged in person.

Any advice is greatly appreciated.

Thanks!

Below is the login function

<?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'); 
?>

There is some html below the php that calls in the form. I can load that up if that helps too. Thanks!

Also, the account_id's are managed within the admin section. There is an associated account_id within the clients table of the database that specifies which account each user has.

  • 写回答

1条回答 默认 最新

  • dongtangjie0495 2017-07-26 05:51
    关注

    If else condition page your are not post and get any data's so post and get method will not work. Then u need to make sure session is set or not. After that only u can able to find out the exact value of $aid.

    评论

报告相同问题?