Weird Issue

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
ryanod
Forum Newbie
Posts: 3
Joined: Fri May 11, 2007 8:12 pm

Weird Issue

Post by ryanod »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok, I know a million people ask questions about login scripts. Well, I did my research and I created my own login / PW protection system. It works great - except for ONE page.

The strange thing is, that one page has the exact same files included that all the other pages do. This leads me to believe the $_SESSION variable is not accessable from this one page.

How is this possible?

Every page has a session_start(); before the <DOCTYPE> declaration in the <head> to ensure every page has access to the $_SESSION variable. The code I use to check if a user is logged in is as follows:

Code: Select all

<?php
		if(isset($_SESSION['logged']) && ($_SESSION['logged'] == true)){
			echo('<span class="login"><a href=' . $root . 'login/logout.php>Logout</a></span>');
		}
		else{
			echo('<span class="login"><a href="#" onclick="$(\'#ifxElement\').BlindDown(500);return false;">Login</a></span>');
		}
	
		include("login/index.php");
	?>
This only works on some pages even though the only thing different on these pages is the content in the body. What could possible be causing this to happen? I have also noticed that sometimes the session ID is passed in the URL (which I DON'T want to happen) and other times it isn't. It is almost like the site is short circuiting. There is no pattern. It's just crazy. Help me please!!!! I have spent THREE DAYS working on this one issue!!!

RyanOD


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

are you getting an error?, please specify the problem and post a sample of a page thats not working, because there is not enough information to help you.
ryanod
Forum Newbie
Posts: 3
Joined: Fri May 11, 2007 8:12 pm

More info. . .

Post by ryanod »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok, the issue is this. Whenever you click on one of the products (after logging in on the homepage), you get logged out when the products page is loaded. The registration page and the submit page load just fine without logging you out. However, they all use the same files to check for logged in / logged out. The product page is somehow killing the $_SESSION. I have tried everything, but it won't work. You can see it all at http://www.tablashirt.com. Feel free to log on with the following:

User: ryan@yahoo.com
PW:ryan

Once you are in, click on a product and see how you get logged out. Please disregard ALL the content on the site as it is just temporary crap I am using to test this structure.

Interestingly enough, once you get auto-logged out, logging in AGAIN and then going to the products results in it working fine.

Here is the code all my pages include that checks if the user is logged in or not and responds accordingly:

Code: Select all

<div id="masthead">
	<a href="<?php echo("http://www.tablashirt.com")?>"><img src="<?php echo("$root" . "images/logo.gif")?>" alt="Tablashirt" /></a>
	<?php
		if(!isset($_SESSION['logged']) || $_SESSION['logged'] !== true) {
			echo('<span class="login"><a href="#" onclick="$(\'#ifxElement\').BlindDown(500);return false;">Login</a></span>');
		}
		else{
			echo('<span class="login"><a href=' . $root . 'login/logout.php>Logout</a></span>');
		}
		include("login/index.php");
	?>
	<div id="nav">
		<ul>
			<li><a href="<?php echo"$root" . "submit/"?>">Submit</a></li>
			<li><a href="<?php echo"$root" . "score/"?>">Score</a></li>
			<li><a href="<?php echo"$root" . "shop/"?>">Shop</a></li>
			<li><a href="<?php echo"$root" . "registration/"?>">Join</a></li>
		</ul>
	</div>
</div>
In order to isolate the issue, I removed EVERYTHING except the the <head> file (which has session_start() in it) and the masthead.php file you see above from the products.php page. It still logs me out. Let me make this perfectly clear to everyone. I have 4 pages (home, submit, registration, and products) that all leverage the same <head> and masthead file shown above. All of them react to the $_SESSION exactly as they should EXCEPT the products page. Bear in mind the fact that if I take ALL the content out of the product page, it still kills the $_SESSION.

Is the name 'products' disallowed for folders or files? I know that sounds nuts, but nothing else makes sense. If you load in content from a db query do you have to handle $_SESSION in a different way? Really, that shouldn't matter as I have removed the query and the page still logs me out.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ryanod
Forum Newbie
Posts: 3
Joined: Fri May 11, 2007 8:12 pm

Observation

Post by ryanod »

I have found that if you log in from the main page and then log in again from a product page you stay logged in everywhere. It seems the product page demands a login and and all the other pages demand their own login as well. Weird!!

I'm guessing someone out there has an idea why that could happen.

Please help me!! I've wasted three days on this ridiculous nonsense!

Thanks in advance.

RyanOD
Post Reply