vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   how does sessions work ? (https://vborg.vbsupport.ru/showthread.php?t=106105)

Mickie D 01-23-2006 03:49 PM

how does sessions work ?
 
i was wondering about sessions and wondered if anyone was experianced with using this feature and maybe can help a little ?

Say i had a page that had a form and the form sent infomation to another page (say a small popup - not adverts but info) and i would only want that page to display the info if the page i made sent the request ?

hope that sounds right it was a little difficult to explain and i think sessions can do this ?

for example if someone else sent the request i would want it to display the you do not have permission template ?

thanks for any advice

sde 01-23-2006 03:57 PM

you can set session variables like this:
PHP Code:

<?
$_SESSION['canViewTemplate'] = true;
?>

Then in your popup, you could test for it like this:
PHP Code:

<?
if ($_SESSION['canViewTemplate']) {
  // ok
} else {
  // not ok
}
?>

I know the PHP side of things.. not sure about displaying templates. I'm trying to figure this out myself in a post I made today.

Mickie D 01-23-2006 05:55 PM

so if i done something like this from the showpost.php page

insert somewhere

PHP Code:

$_SESSION['camefromshowpost'] = true

and in my new page whatever.php

add

PHP Code:

if ($_SESSION['camefromshowpost']) { 
  
$whatever "yes";
} else { 
  
$whatever "no";



thanks very much for the reply

sde 01-23-2006 06:02 PM

well once that is set, it is set for the entire session. you aren't really testing where they came from, you are testing if they have visited the page once during this session.

if you truely want to make sure they came from a certain page, use $_SERVER['HTTP_REFERER'].

for example, all you need on the popup page is:
PHP Code:

<?
if ( strstr($_SERVER['HTTP_REREFER'], "mydomain.com/mypage.php") ) {
  $whatever = "yes";
} else { 
  $whatever = "no";
}
?>

I use strstr to compare because the referer might be different if it's a page that has query variables in the url. i.e. http://mydomain.com/mypage.php?f=1&b=2

Mickie D 01-23-2006 06:51 PM

hi sde thanks i already use that method above ;)

but its a problem because many softwares like norton and loads of others block http referer so they wont get the variable i have if they came from showpost

anyway thanks very much for the help it looks like im back to the drawing board

sde 01-23-2006 07:44 PM

session does seems like the answer then. you will at least know the user has visited the required page at least once during the session before launching the template.

Mickie D 01-28-2006 12:21 PM

sorry to bring this back up again but i had some ideas about sessions ;)

just to clarify can that session code you posted above be used between to different php pages (non vb to vbpages)

thanks very much would be great if i could trace between pages where the user has been ;)

Regards
Mickie D

sde 01-28-2006 03:53 PM

maybe something like this would work:
PHP Code:

<?
// check if the current page is in the session array
if ( !in_array($_SERVER['SCRIPT_NAME'], $_SESSION['visited_pages']) ) {
  // if not, add it
  $_SESSION['visited_pages'][] = $_SERVER['SCRIPT_NAME'];
}
?>

so then to check if a user has visited a certain page, you could do this:
PHP Code:

<?
if ( in_array("somepage.php", $_SESSION['visited_pages']) ) {
  // user has visited somepage.php
} else {
  // user has not visited somepage.php
?>

keep in mind that $_SERVER['SCRIPT_NAME'] does not include the query variables. if you want to count the same php script with different query variables as different pages, then you should use $_SERVER['REQUEST_URI'] instead.

for example, with SCRIPT_NAME, these pages would all be the same:
/mypage.php?a=1
/mypage.php?a=52

REQUEST_URI includes the query variable in the value.


All times are GMT. The time now is 02:59 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01094 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete