[SOLVED] Session trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oyse
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2004 3:37 am

[SOLVED] Session trouble

Post by oyse »

Bech100 | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

I am having a trouble with sessions. The code works fine in Opera, but in Mozilla I get into trouble ( this might be a mozilla bug, but what do I know ).

I have a login in page as follows.

Code: Select all

<?php

session_start();
$knownUser;
if( !empty($_POST[ 'username' ]) && !empty( $_POST[ 'password' ] ) ){
//athenticate
}

if( $knownUser ){
//redirect user to index page
if( isset( $_SESSION[ 'pageSession' ] ) ){
echo 'isset';
} 
}else{
//create login page
}
?>
If the user is authenticated he is redirected to a index page with the following code:

Code: Select all

<?php
session_start();

$page;

//a session has not been created
if( !isset( $_SESSION[ 'pageSession' ] ) ){
//redirect back to login
 }else{
//show page
}

?>
For some reason this works fine Opera, but not in Mozilla In Mozilla the session is active when the user is authenticated because it prints isset, but when the user comes to the index page he is redirect back to the login page. Has anyone encountered this problem before? I am doing something wrong? If this is a commen problem is there a work around?

Bech100 | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

can you post the redirect part of the script?
oyse
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2004 3:37 am

Post by oyse »

This is the function that creates the redirect header. $this->redirectAdress is either index.php or login.php

Code: Select all

function createRedirectHeader(){
    $newline = "\n";

    echo '<?xml version="1.0" encoding="UTF-8"?>' . $newline ;
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"';
    echo '"http://w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . $newline;
    echo '<meta http-equiv="refresh" content="3;URL=' . $this->redirectAdress . '">' . $newline;
    echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' . $newline;
    echo '<head>' . $newline;
    echo '<title>' . $this->title . '</title>' . $newline;
    echo '<link rel="stylesheet" href="' . $this->stylesheet . '" />' . $newline ;
    echo '</head>' . $newline;
//this didn't help    
//echo '<body onLoad="window.location=''' . $this->redirectAdress . '''" >' . $newline;
}
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

That isn't valid 1.0 Transitional XHTML, so yes it is likely it wouldn't work in Mozilla.
oyse
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2004 3:37 am

Post by oyse »

Thank you. I didn't know the <meta> tags had be inside the <head> tag and there where some other bugs there to. Now everything is working just fine in Mozilla as well.

Here is my new and improved code which produces valid 1.0 transitional XHTML if anyone is interrested

Code: Select all

function createRedirectHeader(){

    $newline="\n"; //used to format html output.

    echo '<?xml version="1.0" encoding="UTF-8"?>' . $newline ;
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ';
    echo '"http://w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . $newline;
    echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' . $newline;
    echo '<head>' . $newline;
    echo '<meta http-equiv="refresh" content="3;URL=' . $this->redirectAdress . '" />' . $newline;
    echo '<title>Redirect</title>' . $newline;
    echo '<link rel="stylesheet" href="stylesheets/main.css" />' . $newline ;
    echo '</head>' . $newline;
    echo '<body>' . $newline;
    echo '<h3>If you are not directly redirected press <a href="' . $this->redirectAdress . '"> this </a>link</h3>';
    echo '</body></html>';

  }
Post Reply