Function Header location not working. please help me

  • voquocnguyen
  • Born
  • Born
  • voquocnguyen
  • Posts: 2

Post 3+ Months Ago

I have a sample code:
index.php

PHP Code: [ Select ]
<?php
include_once('session.php');
if($mod == 'admin' && !$userInfo->isFounder()) $mod = strtolower(DEFAULT_ADMIN_OP);
include_once("mod/".$mod.".mod.php");
?>
  1. <?php
  2. include_once('session.php');
  3. if($mod == 'admin' && !$userInfo->isFounder()) $mod = strtolower(DEFAULT_ADMIN_OP);
  4. include_once("mod/".$mod.".mod.php");
  5. ?>



session.php

PHP Code: [ Select ]
<?php
# Start session
session_start();
# Need to be re-coded here. We need a class
# If there is a session varibale 'userId', assign a global UserInfo object named 'authUser'
if(isset($_SESSION['userId']) && $_SESSION['userId']) {
include_once('class/users.class.php');
$users = new Users;
$userId = $_SESSION['userId'];
$userInfo = $users->getUserInfo($userId);
$template->assign('authUser',$userInfo);
} else {
$mod = 'login';
$template->assign('amessages',$amessages);
include_once('mod/login.mod.php');
}
?>
  1. <?php
  2. # Start session
  3. session_start();
  4. # Need to be re-coded here. We need a class
  5. # If there is a session varibale 'userId', assign a global UserInfo object named 'authUser'
  6. if(isset($_SESSION['userId']) && $_SESSION['userId']) {
  7. include_once('class/users.class.php');
  8. $users = new Users;
  9. $userId = $_SESSION['userId'];
  10. $userInfo = $users->getUserInfo($userId);
  11. $template->assign('authUser',$userInfo);
  12. } else {
  13. $mod = 'login';
  14. $template->assign('amessages',$amessages);
  15. include_once('mod/login.mod.php');
  16. }
  17. ?>



login.mod.php

PHP Code: [ Select ]
<?php
$templateFile = "login.tmp.html";
$error ='';
if(!$_POST) {
 
}else{
include_once('class/users.class.php');
$users = new Users;
$username = trim($request->element("username"));
$password = trim($request->element("password"));
$userId = $users->authenticateUser($username,$password);
if($userId) {
$_SESSION['userId'] = $userId;
header('location: '.ADMIN_SCRIPT.'?mod=index');
} else {
$_SESSION['userId'] = 0;
$error = $amessages['invalid_user_password'];
}
$template->assign('error',$error);
}
?>
  1. <?php
  2. $templateFile = "login.tmp.html";
  3. $error ='';
  4. if(!$_POST) {
  5.  
  6. }else{
  7. include_once('class/users.class.php');
  8. $users = new Users;
  9. $username = trim($request->element("username"));
  10. $password = trim($request->element("password"));
  11. $userId = $users->authenticateUser($username,$password);
  12. if($userId) {
  13. $_SESSION['userId'] = $userId;
  14. header('location: '.ADMIN_SCRIPT.'?mod=index');
  15. } else {
  16. $_SESSION['userId'] = 0;
  17. $error = $amessages['invalid_user_password'];
  18. }
  19. $template->assign('error',$error);
  20. }
  21. ?>



When i submit form.
$userId have value. But function header not working.
I'm from Vietnam so my english is very little capital. Expect any help.
Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Cae
  • Expert
  • Expert
  • User avatar
  • Posts: 734

Post 3+ Months Ago

I may just be being blind, but I do not see 'ADMIN_SCRIPT' defined anywhere in your workflow...
  • voquocnguyen
  • Born
  • Born
  • voquocnguyen
  • Posts: 2

Post 3+ Months Ago

I have use command "echo". It display : index.php?mod=index
The "ADMIN_SCRIPT" is a constant.
I define it :
define("ADMIN_SCRIPT","index.php");

The problem here is not accept Session. If i'm not use function "header location". I use orther page and use method redirect. It run but not accept session.
So, when it redirect complete $_SESSION['userId'] = ''. Why that?
  • Cae
  • Expert
  • Expert
  • User avatar
  • Posts: 734

Post 3+ Months Ago

Sorry, the post title mentioned the header not working, so I though your problem was with your 'header()' call.


Are you calling 'session_start()' on the page you are redirecting to?

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 70 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.