News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Session interrupt

Started by Bounty_y2k, November 15, 2014, 12:18:07 PM

Previous topic - Next topic

Bounty_y2k

Hi,I have a problem with my website and forums. On my main website I start a session but it gets interrupted when accessing forums. I did a print_r($_SESSION); on every page on my webs and it shows something like this:
Line 8 : Array ( ) //not yet created
Line 22 : Array ( [bbthemes] => 3 ) //created

After this executed all web pages are like:

Line 8 : Array ( [bbthemes] => 3 )
Line 22 : Array ( [bbthemes] => 3 )


And on main page of forums:
Line 8 : Array ( [session_value] => 879cb419b7112192002f6124d9631e91 [session_var] => ada78ff138f1 [mc] => Array ( [time] => 1416071540 [id] => 0 [gq] => 0=1 [bq] => 0=1 [ap] => Array ( ) [mb] => Array ( ) [mq] => 0=1 ) [ban] => Array ( [last_checked] => 1416071540 [id_member] => 0 [ip] => [ip2] => [email] => ) [log_time] => 1416071540 [timeOnlineUpdated] => 1416071540 )
//no 'bbthemes' session and there should be
Line 22 : Array ( [session_value] => 879cb419b7112192002f6124d9631e91 [session_var] => ada78ff138f1 [mc] => Array ( [time] => 1416071540 [id] => 0 [gq] => 0=1 [bq] => 0=1 [ap] => Array ( ) [mb] => Array ( ) [mq] => 0=1 ) [ban] => Array ( [last_checked] => 1416071540 [id_member] => 0 [ip] => [ip2] => [email] => ) [log_time] => 1416071540 [timeOnlineUpdated] => 1416071540 [bbthemes] => 13 )
//new one created


It seems like smf session reset my webs session.
Any ideas on how can I get this to work?

Arantor

SMF does its own session fixation for security purposes.

Ideally use SMF's wherever possible. Without knowing what you are doing on your site, I can't give you any advice.

Bounty_y2k

So there is no way to keep any session except SMF's original on forums?

Arantor

I didn't say that.

However, SMF's is harden - and proven - against things like session fixation which your own code may not be. As I said, more information would be helpful to giving you a better answer.

Bounty_y2k

Oh sorry.
This is whats going on.
I have style.php witch randomizes a number and by that number builds styles for my web site.

<?php
session_start();

$maxt 20;
$dark false;
$adresa "http://".$_SERVER['HTTP_HOST']."/website/";
print_r($_SESSION); //test
if (isset($_COOKIE['bbtheme'])) {
 
$ran $_COOKIE['bbtheme'];
 
}else if(isset($_SESSION["bbthemes"])){
 
$ran $_SESSION["bbthemes"];
 
}else if(!isset($_COOKIE['bbtheme']) && !isset($_SESSION["bbthemes"])){
 
$ran rand(1$maxt);
 
$_SESSION["bbthemes"] = $ran;
 
}
 
if(isset($_GET['bbthemef']) && $_GET['bbthemef'] !== '' && is_numeric($_GET['bbtheme'])){ 
 
$bbthemef $_GET['bbthemef']; 
 
if($bbthemef $maxt || $bbthemef 1){
 
$ran rand(1$maxt);
 
} else {
 
$ran $bbthemef;
 
}
 
}
 
print_r($_SESSION); //test
$body "body{ background-image:url(\"".$adresa."/source/img/bgs/".$ran.".jpg\");}";
        
$style "<style type='text/css'>".
$body.
"</style>";
        
//i simply echo $body inside <head> tags to get styles
?>


This file is included in all of my web pages and index.template.php of my theme.
So it basically checks for cookies,sessions and if there is none it renders a random number.
But sessions on site and forums work independently so I get two different styles for my site and forums.

Arantor

Yeah, there's security issues with doing that. Session hijacking is a thing.

Quick solution: include SMF's SSI.php then don't start your own session. You get access to SMF's session data and $_SESSION will work as expected (provided you set subdomain independent cookies to on) and can also make use of information about whether the user is logged in or not should you want to do such.

Randomising the user experience rarely works well.

Bounty_y2k

So I would just need to replace session_start(); in my style.php with include '/path/SSI.php'; ?
How can I set sub domain independent cookies? (sry,first time I hear about this).

Arantor

Yes, pretty much that's what you do. SMF starts its own session which it protects.

As for setting subdomain independent cookies, Admin > Configuration > Server Settings > Sessions and Cookies.

This is required because otherwise SMF's cookie will be restricted to the folder in which SMF resides.

Bounty_y2k

I get the following error outside the forums:
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in ..path\source\style.php on line 3

Warning: include(..path/forum/SSI.php): failed to open stream: no suitable wrapper could be found in path..\source\style.php on line 3

Warning: include(): Failed opening '..path/forum/SSI.php' for inclusion in ..path\source\style.php on line 3

Arantor

You are not supposed to include it by way of an http:// link. Use the correct path to its actual file.

Bounty_y2k

Works like a charm. Thank you very much,you helped me a lot. :)

Bounty_y2k

Sorry for this,it fails again -.-
It worked on my localhost but on real host something is wrong.
Session isn't set until user visits forums when he does sessions work for whole website and forums but before user visits the forum sessions aren't stored.
I include ssi.php like this:
$urld = $_SERVER["REQUEST_URI"];

if (strpos($urld, 'forum') !== false){
(include "SSI.php") or die('fail 1');
} else {
(include "forum/SSI.php") or die('fail 2');
}

The page does not 'die' so it should work well but it does not....:/

Kindred

Why are you doing that?

SSI itself already has a check to see if SMF is running (and won't load the conflicting parts of itself, if it is)


just

include("/home/youracct/public_html/forum/SSI.php");

nothing more, nothing less.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Bounty_y2k

Of course...sorry for that :D Thank you again.

Bounty_y2k

Ok,back on problem no.1
I just added this into my php:

include("/home/myacc/public_html/forum/SSI.php");

if (isset($_COOKIE['bbtheme'])) {
$ran = $_COOKIE['bbtheme'];
echo 'Found Cookie = '.$ran;
}else if(isset($_SESSION["bbthemes"])){
$ran = $_SESSION["bbthemes"];
echo 'Found Session = '.$ran;
}else if(!isset($_COOKIE['bbtheme']) && !isset($_SESSION["bbthemes"])){
$ran = rand(1, $maxt);
$_SESSION["bbthemes"] = $ran;
echo 'Creating Session = '.$ran;
}


I get "Creating Session" on every page before I visit forums, after visiting forums that I get "Found Session" on every page forum and non-forum. It seems like on first time on the page it creates session but on the second SSI.php overwrites it and unset it...so its really never stored. Sorry for bothering you so much with this.

Kindred

why are you loading SSI multiple times on a page?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Bounty_y2k

#16
That is the first and only time i include SSI.php. Oh,sorry, by 'adding' I was talking about echo's..

Bounty_y2k


Arantor

Are you still running session_start() before? Any other session code beforehand?

Bounty_y2k

Nope,this is the beginning of the one and only file that does the job.
<?php
//(include("/home/web/public_html/forum/SSI.php")) or die('Fail!');
include("/home/web/public_html/forum/SSI.php");

//print_r($_SESSION); //test
if (isset($_COOKIE['bbtheme'])) {
 
$ran $_COOKIE['bbtheme'];
 
//echo 'Found Cookie = '.$ran;
 
}else if(isset($_SESSION["bbthemes"])){
 
$ran $_SESSION["bbthemes"];
 
//echo 'Found Session = '.$ran;
 
}else if(!isset($_COOKIE['bbtheme']) && !isset($_SESSION["bbthemes"])){
 
$ran rand(1$maxt);
 
$_SESSION["bbthemes"] = $ran;
 
//echo 'Creating Session = '.$ran;
 
}

Advertisement: