foxhound |
|
---|---|
I am trying to identify a user/guest and know if he is on my website while he connects to a different server. So, for that I am using a session in some custom php I wrote over the last few weeks.
Oh, I know there are already sessions created but those are of no use for me as they are the same for the entire session. I need to create unique session values with each page request so i can cross check a users presence. <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|
Dayver |
|
---|---|
Read extensions/extdevguide and try to create a simple plugin myplug with two files 1) myplug.setup.php 2) myplug.global.php in his us hook "input" or "global" with your needed code. Then your code will be attached in common.php (will load with ever page request) but common.php not be hacked and after upgrades your code be will work Pavlo Tkachenko aka Dayver
|
foxhound |
|
---|---|
Thanks, that link was very usefull.
Added 5 days later: Ok, here is the first plugin I have made and I am actually hoping anyone can take a look and tell me if I should change something or if things should be done differently. <?php /* ==================== [BEGIN_SED] File=plugins/sessions/sessions.php Version=1.0 Updated=2015-march-21 Type=Plugin Author=Foxhound Description=Insert a unique session with each pageload on pages only [END_SED] [BEGIN_SED_EXTPLUGIN] Code=sessions Part= File=sessions Hooks=global Tags= Minlevel=0 Order=1 [END_SED_EXTPLUGIN] ============ */ if (!defined('SED_CODE')) { die('Wrong URL.'); } // here we check if we are working on the download system, if no all session stuff is set else we exit if ($cfg['plugin']['sessions']['workinprogress'] != 'Yes') { $ses_pageid = sed_import('id','G','INT'); $ses_userid = $usr['id']; $ses_username = $usr['name']; if ($ses_username == "") { $ses_username = "guest"; } $ses_userip = $usr['ip']; $ses_sql1 = sed_sql_query("SELECT online_ip, online_location, online_sessionid, online_randomer FROM $db_online WHERE online_ip='$ses_userip'"); while ($row = sed_sql_fetcharray($ses_sql1)) { $ses_userloc = $row['online_location']; $ses_usersessionid = $row['online_sessionid']; $ses_randomer = $row['online_randomer']; } if ($ses_userloc == "Pages") { $dwnldlink_sql1 = sed_sql_query("SELECT page_id, page_extra_url FROM $db_pages WHERE page_id='$ses_pageid'"); while ($row = sed_sql_fetcharray($dwnldlink_sql1)) { $ses_downloadurl = $row['page_extra_url']; } // create random string $ses_randomer = ""; $ses_str_length = xx; for($ses_i=0; $ses_i<$ses_str_length; $ses_i++){ $ses_rand_number = mt_rand(0,xx); $ses_string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $ses_randomer .= substr($ses_string, $ses_rand_number, 1); } $ses_usersessionid = md5($ses_xxxxx . md5($ses_randomer)); $ses_sql1 = sed_sql_query("UPDATE $db_online SET online_sessionid='$ses_usersessionid', online_randomer='$ses_randomer' WHERE online_ip='$ses_userip'"); } // this is required cause we never know if the visitor does actually click the downloadlink on the page he visitted! if (($ses_userloc != "Pages") && ((!empty($ses_usersessionid)) || (!empty($ses_randomer)))) { $ses_sql_u1 = sed_sql_query("UPDATE $db_online SET online_sessionid='', online_randomer='' WHERE online_ip='$ses_userip'"); } } ?>
<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|
|
This post was edited by foxhound (2015-03-21 22:53, 9 years ago) |
Dayver |
|
---|---|
Pavlo Tkachenko aka Dayver
|
foxhound |
|
---|---|
Yeah, its for Genoa, I still have not moved over to Sienna :) $location = 'Pages'; $z = 'page';
Added 16 hours later: Ahhhh, I see. Location is already an available variable so I dont have to query the DB for the location at all. ($location) <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|
|
This post was edited by foxhound (2015-03-23 10:50, 9 years ago) |
Dayver |
|
---|---|
This see in start Page module file https://github.com/Cotonti/Cotonti/blob/genoa/page.php#L14 / But only for Genoa Pavlo Tkachenko aka Dayver
|
foxhound |
|
---|---|
I see, thanks for the info. Saved me an additional query which was not really needed and since its a very busy website with many hundreds active visitors each minute whatever I can save is welcome :) <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|