Forum Moderators: coopster

Message Too Old, No Replies

Function Header location not working. pls help me

Function Header locatio

         

voquocnguyen

10:45 pm on May 23, 2010 (gmt 0)

10+ Year Member



I have a sample code:
index.php

<?
include_once('session.php');
if($mod == 'admin' && !$userInfo->isFounder()) $mod = strtolower(DEFAULT_ADMIN_OP);
include_once("mod/".$mod.".mod.php");
?>


session.php

<?
error_reporting(9);
# 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');
}
?>


login.mod.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);
}
?>


When i submit form.
$userId have value. But function header not working. Help me, pls

voquocnguyen

10:51 pm on May 23, 2010 (gmt 0)

10+ Year Member



And i run it on PHP 5.3.0 it run Perfect. But it not run on PHP 5.2.X
Help me.
Thanks

Matthew1980

7:38 am on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there voquocnguyen,

I think as this may be down to something as simple as you using the short tags (<? ?>), not all server installations support this, so good practice to always use (<?php ?>) this make sure as you are compatible for all servers, and as you say it runs on one and not the other, seems logical to me that, that could be a cause.

I assume as your constant ADMIN_SCRIPT has the full path stored in it, also, the error_reporting, I always find that using: error_reporting(E_ALL); is the best way to set it, I'm not too sure on 9 - though I could be wrong there.

Also, when instanciating a new class, you will more than likely need to use the $users = new Users(); way to declare it, at least that's how I have always known it to be.

Cheers,
MRb

Anyango

9:16 am on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there any blank spaces or white lines or any output to browser before header call ? Even if there is one simple single being printed then your call won't work. Check for that too

voquocnguyen

4:46 pm on May 24, 2010 (gmt 0)

10+ Year Member



Thanks all.
But i try again and use full tag " <?php & ?> " and error_reporting(E_ALL); but not run.
But I feel weird. When I use the "echo" before function "header" but it not display error.
Can help me ? I will send full code for you.

Thanks
Nguyên Võ

Anyango

6:59 pm on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Has to be some output before header call, is display_errors set to On?

voquocnguyen

7:34 pm on May 24, 2010 (gmt 0)

10+ Year Member



When i test some output before function "header". I use error_reporting(E_ALL);.

[edited by: jatar_k at 1:23 pm (utc) on May 25, 2010]
[edit reason] sorry no links please [/edit]