Weird Session + Include Problem

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
cggreer
Forum Newbie
Posts: 14
Joined: Mon Jul 21, 2003 6:39 am

Weird Session + Include Problem

Post by cggreer »

G'day guys!

I'm trying to get user login on my current project working
Now, my main page has a php include() on it that puts either a login form, or a logout button on the page after it checks isset($_POST['username']);
Problem is this, when you login, the login script redirects you to the main page again, which SHOULD have a logout button there. Instead it just displays the login form.

Here's the weird part: if I get rid of that include() and paste the code that decides whether to display login/logout, straight into my main page everything works fine.

I use session_start() at the top of the main page, and the top of the login script. I've tried both with and without session_start() at the top of the included file and there's no difference.

I'm running PHP4.3.2 on Apache 2.0.45. Any help would be appreciated. I can't use Apache includes because the php doesn't get executed - help! eek!

Cheers,
Clinton Greer
cggreer@it.uts.edu.au
User avatar
massiveone
Forum Commoner
Posts: 29
Joined: Tue Jun 18, 2002 4:39 pm
Location: Canada
Contact:

Post by massiveone »

Have you tried pushing your variables into the session
such as this
you have a variable called $username
$_SESSION['username']=$username;?
cggreer
Forum Newbie
Posts: 14
Joined: Mon Jul 21, 2003 6:39 am

Post by cggreer »

I'm writing it to the $_SESSION variable.

My main page calls the login module that prints the login form or logout button.

Code: Select all

<?php //include("http://127.0.0.1/MyHSC/login_module.php"); ?>
That login module checks to see if the user is logged in like this:

Code: Select all

<?php if(!isset($_SESSION['MyHSC_Username'])) ?>
And finally the login script that communicates with the DB, sets the session variable, and returns the user to the main page, which should now display a button that says logout. But it just displays the login form again.

Code: Select all

<? php$_SESSION['MyHSC_Username'] = $username; ?>
Removing the include and just pasting the contents of the login_module in the main page makes everything work fine. Pulling hair out... Help!! 8O

Cheers,
Clinton Greer
cggreer@it.uts.edu.au
cggreer
Forum Newbie
Posts: 14
Joined: Mon Jul 21, 2003 6:39 am

Post by cggreer »

Woohoo! Fixed the problem... kinda.

The file I'm including is in the same directory as the one that calls it. If I use include("file.php"); and not include("http://server/file.php"); then it works no worries.

This poses a bit of a prob if I want to call it from another directory though. In php.ini I've set the include path to the directory under d:\program files\apache group\Apache2\htdocs\xxx that the file resides in, but still cannot refer to it using an absolute URL and get the session variables to carry across!

Suggestions welcome!

Clinton Greer
cggreer@it.uts.edu.au
Post Reply