Website not keeping user logged in.

Started by jollyrogue, August 16, 2009, 09:47:39 AM

Previous topic - Next topic

jollyrogue

I made my site require ssi.php on every page and have guests need to log in on pages that we want to protect.

My menu.php (which is included in every page) contains


require ("C:\\xampp\\htdocs\\site\\forum\\SSI.php");
$_SESSION['login_url'] = 'http://localhost/site/index.php';
$_SESSION['logout_url'] = 'http://localhost/site/index.php';


i also tried adding session_start(); above the ssi requirement.

when trying to login though using ssi_login(); i get directed to the forum logged in instead of the homepage and when i go back to the homepage, it still shows as being a guest, even though i'm logged into the forum.
Strangely though, when i use ssi_logout(); to logout of the site (and the logout button on the forum), i get redirected to the homepage like it is supposed to

So because of this, I can't view any content on the site because i'm being shown as a guest. It all worked fine though when i first put in all the code yesterday, it just stopped working when i came back to my computer today and checked everything.

If you need more information to help me just ask and i'll provide it.

Arantor

First up, don't use session_start(). SSI.php does that itself.

Secondly... are you using SMF 1 or SMF 2?
Holder of controversial views, all of which my own.



Arantor

Is SSI.php being included as the very first thing on the page? It doesn't look like it - which is likely part of why it fails.
Holder of controversial views, all of which my own.


jollyrogue

I have $siteurl="http://localhost/site"; before it to save me entering the url everywhere (and ensures i dont have to change it everywhere as well)

should it be moved to after the ssi.php line?

Arantor

That wasn't that I meant.

Do you have anything being printed before SSI.php is included? You said it's included from menu.php - is there something output before menu.php loads?

It might just be simpler to post some of the code here.
Holder of controversial views, all of which my own.


jollyrogue

nope. the only line thats before include ("menu.php") is a variable telling menu.php what the page title is.

this is basically the first thing on every page.


<?php
$pagetitle
= "Gaming";
include (
"menu.php")
?>

Arantor

No blank line above it in each page, nor a space?

What does menu.php contain?
Holder of controversial views, all of which my own.


jollyrogue

#8
nope, <?php is line 1.

my menu.php is this:


<?php
$siteurl
="http://localhost/site";
require (
"C:\\xampp\\htdocs\\site\\forum\\SSI.php");
$_SESSION['login_url'] = 'http://localhost/site/index.php';
$_SESSION['logout_url'] = 'http://localhost/site/index.php';
?>
<?php

echo '
<html>
<head>
<title> Website  - '
, $pagetitle, ' </title>
<link rel="stylesheet" type="text/css" href="'
,$siteurl,'/default.css"/>
<link rel="shortcut icon" href="'
,$siteurl,'/favicon.ico" />
</head>
<body>
<div id="mainpage">
<div id="topsection">
<div id="logo">
<h1><a href="'
,$siteurl,'/index.php"><img src="',$siteurl,'/images/logo.png" style="margin: 4px;" /></a></h1>
<br />
</div>
</div>
<div id="menu">
<ul id="main">
<li><a href="'
,$siteurl,'/index.php">Home</a></li>
<li><a href="'
,$siteurl,'/forum">Forum</a></li>
<li><a href="'
,$siteurl,'/gaming.php">Gaming</a></li>
<li><a href="'
,$siteurl,'/shoutbox.php">Shoutbox</a></li>
<li><a href="'
,$siteurl,'/halloffame.php">Hall of Fame</a></li>
<li><a href="'
,$siteurl,'/links.php">Links</a></li>
'
;
?>
<?php
if ($context['user']['is_guest'])
{
echo '
  <li><a href="login.php">Login</a></li>
  '
;
}
else
{
echo '
<li>'
;?><?php ssi_logout();?><?php echo '</li>
'
;
}
?>
<?php
echo '
</ul>
</div>
'
;

Arantor

In the forum's configuration, do you have subdomain-specific cookies turned on or off?
Holder of controversial views, all of which my own.


jollyrogue

Use subdomain independent cookies -  is checked.

but i noticed - Enable local storage of cookies - is checked too, it says wont work well with SSI.. :/

Arantor

That's very likely the cause of the problem - untick it, log out, log back in and see if that works.
Holder of controversial views, all of which my own.


jollyrogue

Ok it seems to be working somewhat now :). I appear as logged in. I still get redirected to the forum on login though and the logout on the site doesn't work. I get a Session verification failed. Please try logging out and back in again, and then try again. message.. which is ironic as im trying to logout :/

Advertisement: