Re: Using header(location: ......php) within a class not working



ajtrichards@xxxxxxxxxxxxxx wrote:
Hi.

Can someone tell me why this code is not working?

<?php
session_start();
class tta_globals {

function check_session_state(){
if(!$_SESSION['logged_in']){
header('Location: login.php');
die();
}
}
}

$tta_globals = new tta_globals();

$tta_globals -> check_session_state();
?>

When I run this code it doesn't redirect the user? I have checked and
double checked to make sure that there is no session['logged_in']
anywhere.

Can anyone help?

Regards,
Alex.
Ajtrichards Web Solutions
http://www.ajtrichards.co.uk


Are you sure that you have no output (even whitespace) prior to the header call? Headers have to be sent before any other output.

Robin
.



Relevant Pages

  • Re: Ever seen a mail failure like this?
    ... The mail code is straight out ... website to an email address of that same website. ... If you use this MIME message class and set the Return-Path header and ... Find and post PHP jobs ...
    (comp.lang.php)
  • Re: Show image img src=img.php?img=1.jpg help
    ... When i do that the image type is detected correctly as jpeg, ... But earlier you said this really is a bmp, ... I haven't actually tried mixing session_startwith header(); ...
    (comp.lang.php)
  • auto_prepend_file not working with apache 2.2, windows xp and ph
    ... In order for PHP ... different values for several directives, ... The environment variables are not hashed into the $_ENV. ... (e.g. by adding its signature to the Web server header). ...
    (alt.php)
  • Re: !DOCTYPE Problem
    ... I'm getting a header already sent error ... If the <!DOCTYPE is missing, ... If everything else in the php code is correct, ... then it is too late to mess with the header exchange. ...
    (alt.html)
  • nested tables in a form, need an Excel button moved over a column, has some php
    ... I have a page with a form that is included into a php page. ... some php variables which are headers based on the user choices. ... the form output will go to Excel not to the browser. ... There is a included included header under that says home, ...
    (comp.infosystems.www.authoring.html)