[BETA] Guest Sessions MOD

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Post Reply
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

[BETA] Guest Sessions MOD

Post by Arty »

This mod removes session id from url for guests. This allowes bots (like googlebot) to spider forum correctly without adding session id to urls. And guests won't have more than one session from same ip.

Mod version: 0.04

Code: Select all

################################################################# 
## MOD Title: Guest Sessions MOD
## MOD Version: 0.04
## MOD Author: CyberAlien <no@public_email> (Vjacheslav Trushkin) http://www.phpbbstyles.com
## MOD Description: 
##		This mod removes session id for guests from url and this way
##		guests who don't have cookies like different robots will use
##		correct urls. It can be used to allow googlebot and other
##		search engines to spider your forum correctly.
##
## Installation Level:	Easy
## Installation Time:	1-2 Minutes
## Files To Edit (1): includes/sessions.php
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 

# 
#-----[ OPEN ]--------------------------------------------- 
# 
includes/sessions.php

#
#-----[ FIND ]---------------------------------------------
# around line 157
	$sql = "UPDATE " . SESSIONS_TABLE . "
		SET session_user_id = $user_id, session_start = $current_time, session_time = $current_time, session_page = $page_id, session_logged_in = $login, session_admin = $admin
		WHERE session_id = '" . $session_id . "' 
			AND session_ip = '$user_ip'";

# 
#-----[ REPLACE WITH ]---------------------------------------
# 
	$sql_ip = $user_id == ANONYMOUS ? " AND session_ip = '$user_ip'" : '';
	$sql = "UPDATE " . SESSIONS_TABLE . "
		SET session_ip = '$user_ip', session_start = $current_time, session_time = $current_time, session_page = $page_id, session_logged_in = $login, session_admin = $admin
		WHERE session_id = '" . $session_id . "' $sql_ip 
			AND session_user_id = '$user_id'";

#
#-----[ FIND ]---------------------------------------------
# around line 210
	$SID = 'sid=' . $session_id;

# 
#-----[ REPLACE WITH ]---------------------------------------
# 
	$SID = $user_id > 0 ? 'sid=' . $session_id : '';

#
#-----[ FIND ]---------------------------------------------
# around line 288
				$SID = ($sessionmethod == SESSION_METHOD_GET || defined('IN_ADMIN')) ? 'sid=' . $session_id : '';

# 
#-----[ REPLACE WITH ]---------------------------------------
# 
				$SID = $userdata['user_id'] > 0 ? (($sessionmethod == SESSION_METHOD_GET || defined('IN_ADMIN')) ? 'sid=' . $session_id : '') : '';

#
#-----[ FIND ]---------------------------------------------
# around line 340
	//
	// If we reach here then no (valid) session exists. So we'll create a new one,
# 
#-----[ BEFORE, ADD ]---------------------------------------
# 
	elseif(empty($sessiondata))
	{
		// try to login guest
		$sql = "SELECT u.*, s.*
			FROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
			WHERE s.session_ip = '$user_ip' 
				AND s.session_user_id = " . ANONYMOUS . "
				AND u.user_id = s.session_user_id 
					LIMIT 0, 1";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
		}

		$userdata = $db->sql_fetchrow($result);

		if ( isset($userdata['user_id']) )
		{
			if ( $current_time - $userdata['session_time'] > 60 )
			{
				$sql = "UPDATE " . SESSIONS_TABLE . " 
					SET session_time = $current_time, session_start = $current_time, session_page = 0
					WHERE session_id = '" . $userdata['session_id'] . "'";
				if ( !$db->sql_query($sql) )
				{
					message_die(CRITICAL_ERROR, 'Error updating sessions table', '', __LINE__, __FILE__, $sql);
				}
			}
			return $userdata;
		}
	}

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
To download it as .mod file click here.

Mod updated for phpBB 2.0.15
Last edited by Arty on Sun May 08, 2005 10:46 am, edited 8 times in total.
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
User avatar
Xxh2kxX
Registered User
Posts: 149
Joined: Fri Aug 22, 2003 6:03 pm
Contact:

hey ..

Post by Xxh2kxX »

hey thanks for this mod ..

i need to know iam use this mod .

Code: Select all

#-----[ OPEN  ]------------------------------------------ 
includes/sessions.php 

#-----[ FIND ]------------------------------------------ 
   global $SID; 

if ( !empty($SID) && !preg_match('#sid=#', $url) ) 

#-----[ REPLACE WITH ]------------------------------------------ 
   global $SID, $HTTP_SERVER_VARS; 

   if ( !empty($SID) && !preg_match('sid=', $url) && !strstr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'Googlebot') && !strstr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'slurp@inktomi.com')) 

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM
if i add this also is there any problem ?

Thankyou :D
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

$SID will be empty so those both if() will return false instead of true. you'll need to remove "!empty($SID) && " from those if()'s
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

updated to 0.02

when user loggs in session id stays the same and with this algorythm it might cause problem when several users try to share same session id with different user ids. so i changed query to reuse user's old session when logged in instead of changing guest session.
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Einstein
Registered User
Posts: 247
Joined: Sat Oct 18, 2003 9:48 pm
Location: Finland
Contact:

Re: [BETA] Guest Sessions MOD

Post by Einstein »

CyberAlien wrote: And guests won't have more than one session from same ip.

How does this MOD behave when there are two different computers behind a NAT? One session for both?
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

If both users are guests then one session for both users.

If at least one of those users logged in then every user will have separate session.
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

This mod works. Now google spiders my forum correctly. Here is proof: http://www.google.com/search?q=phpbb+si ... 8&oe=utf-8 (that forum is slightly modified - it also adds style id to urls that is not part of this mod, but it works same was for googlebot as this mod) :D

So i guess i'll put it in validation soon when i'll make sure that there are no bugs.
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Darlantan
Registered User
Posts: 369
Joined: Wed Mar 13, 2002 1:37 pm

Post by Darlantan »

does anonymous posting work if browser has cookies turned off?
Shoshan.net
Registered User
Posts: 29
Joined: Fri Dec 19, 2003 4:46 pm
Location: USA
Contact:

Post by Shoshan.net »

Hi.

There's something with this Mod.
I am logged in automatically, which means, even if I close the browser and open a new one I will still be logged in. Now, after installing this Mod, whenever I close the browser and open a new one to go to the board, I have to log in again. What could it be?
Nice Mod! :idea:
No siggie....
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

Darlantan: yes, guests can post even without cookies.

Shoshan.net: works for me. try clearing your cookies for that domain
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Shoshan.net
Registered User
Posts: 29
Joined: Fri Dec 19, 2003 4:46 pm
Location: USA
Contact:

Post by Shoshan.net »

CyberAlien wrote: Shoshan.net: works for me. try clearing your cookies for that domain


What I want is to always be logged in and it's not happening. What could it be?
No siggie....
agiacosa
Registered User
Posts: 186
Joined: Mon Jan 19, 2004 1:45 pm

Post by agiacosa »

Thanks for this. I will try it this weekend and report back. There is so much confusion about this topic that I very much appreciate you doing this.
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

Shoshan.net wrote:
CyberAlien wrote:Shoshan.net: works for me. try clearing your cookies for that domain


What I want is to always be logged in and it's not happening. What could it be?

It could be old incorrect cookies set for incorrect path. Try clearing cookies.
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Shoshan.net
Registered User
Posts: 29
Joined: Fri Dec 19, 2003 4:46 pm
Location: USA
Contact:

Post by Shoshan.net »

I cleared all cookies before and no, it's not happening. :?
No siggie....
User avatar
Arty
Former Team Member
Posts: 16654
Joined: Wed Mar 06, 2002 2:36 pm
Name: Vjacheslav Trushkin
Contact:

Post by Arty »

Sorry, i don't know what can be causing it. This mod doesn't change autologin code and autologin works for me on modded forums.
Vjacheslav Trushkin / Arty.
Free phpBB 3.1 styles | New project: Iconify - modern SVG framework
Post Reply

Return to “[2.0.x] MODs in Development”