Jump to content

why does my session end?


chris_s_22

Recommended Posts

my connect.php starts the session just so you know

i can navigate arround my site fine except when i come to this page. it lets me in but then when i try to leave no matter what page i go to or which page i come from it shows the error !is_authed

 

Also can someone check my code i wasnt sure if i could do a loop within another one

<?php
include_once 'Connect.php';
if (!is_authed()) 
{
     die ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.');
}
?>
<html><head><title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css"></head>
<body>
<div class=logo><?php include "logo.php";?></div>
<div class=navigationbarbox><?php include "navigationbar.php";?></div>
<div class=welcome>
<?php
// Checks friends
$member = $_SESSION["id"];	
$query = ("SELECT * FROM friends WHERE member = '$member'");
$result= mysql_query ($query) or die ('Could not query.');
$exist = mysql_num_rows($result);  
if($exist=='0')
{
echo"You have no friends";
}
else // if any friends gets
{
	while ($row = mysql_fetch_assoc($result))
	{
	$friendwithid = $row["friendwith"];

		$query = ("SELECT * FROM members WHERE $friendwith = '$friendwithid'");
		$result= mysql_query ($query) or die ('Could not query.');
		while ($row = mysql_fetch_assoc($result))
		{
		$photo = $row["photo"];
		$username = $row["username"];
		}

	echo "<img src='http://www.myurl.co.uk/NEWTEACH/userimages/$photo' width='100' height='150'><br>";
	echo"$username<br>";
	echo'<a href="friendsdelete.php?userid='.$userid.'">Remove Friend</a>';
	}
}		
?>
</div>
<div class=footerbox><?php include "footer.php";?></div>
</body>
</html>

Link to comment
Share on other sites

i dont think the problem is the is_authed function as ive used this on all my pages i wish to protect without any problem. it basically checks session data

 

if i take out this part and replace with a simple echo statment it works fine which tells me it is this part of the code

while ($row = mysql_fetch_assoc($result))
	{
	$friendwithid = $row["friendwith"];

		$query = ("SELECT * FROM members WHERE $friendwith = '$friendwithid'");
		$result= mysql_query ($query) or die ('Could not query.');
		while ($row = mysql_fetch_assoc($result))
		{
		$photo = $row["photo"];
		$username = $row["username"];
		}

	echo "<img src='http://www.myurl.co.uk/NEWTEACH/userimages/$photo' width='100' height='150'><br>";
	echo"$username<br>";
	echo'<a href="friendsdelete.php?userid='.$userid.'">Remove Friend</a>';
	}

Link to comment
Share on other sites

It's pretty hard to tell exactly where the problem is coming from. You're on the right track with trying to isolate the code that's causing the problem, but I'd take that a step further and keep eliminating parts of that while loop until it works. You should start by removing the images and see if that changes anything.

Link to comment
Share on other sites

silly me in the inner loop i was using same variables as the outter loop

ive since changed them im now getting the echo message "You have no friends"

even though i know in database there is

 

my connect.php consists of session start, conects to database then calls for the functions page.

i use a include to connect.php on each page so a session should be there

but ive realised that if i

echo out the session id its blank but if i echo out session username it shows the username

any advice guys?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.