argan328 Posted June 5, 2007 Share Posted June 5, 2007 Hi I have created a website with a terms of service statement and a checkbox on the index page... users have to agree to the TOS before viewing the contents of the site. If a user has not agreed to the TOS and tries to link directly into one of the content pages I want them to be redirected to the index page until they click on the checkbox... I don't want to require a password, I just want them to click on the checkbox at each session. I think I need a session class but am not sure if that would do the job. Can anyone help confirm that a session class alone would accomplish this?? Thanks so much! Argan Link to comment https://forums.phpfreaks.com/topic/54367-session-without-password/ Share on other sites More sharing options...
Caesar Posted June 6, 2007 Share Posted June 6, 2007 Sessions or cookies would be fine. <?php if(!isset($_SESSION['tos'])) { header("location: index.php?notice=tos"); } ?> Link to comment https://forums.phpfreaks.com/topic/54367-session-without-password/#findComment-268881 Share on other sites More sharing options...
argan328 Posted June 6, 2007 Author Share Posted June 6, 2007 Thx Caesar. I would expect this code go on every one of the content pages (I know HTML better than PHP at this point)-- but would I set the variable 'tos' in the session class itself or on the index page? Argan Link to comment https://forums.phpfreaks.com/topic/54367-session-without-password/#findComment-268892 Share on other sites More sharing options...
argan328 Posted June 6, 2007 Author Share Posted June 6, 2007 I'm going to try to use this basic session code I found at http://www.weberdev.com/get_example-4175.html <?php class sessions { /********************************************** ** ** Beginner's session handling class ** ** Author..: leapinglangoor [ [email protected] ] ** Date....: 30th May 2005 ** Ver.....: v1.00 ** ** Desc....: This is a beginner's class to use sessions. ** This is meant more for for educational purposes rather ** than implimentation. There should be no problems using this. ** **********************************************/ /***************************** ** func - sessions() ** @Constructor ** @Access - public ** @Desc - The cunstructor used for warming up ** and preparing the sessions. ** @params - None *****************************/ function sessions() { // Let's initialise the sessions session_start(); } /***************************** ** func - set_var() ** @Access - public ** @Desc - Set a session variable ** @param $var_name - the variable name ** @paran $var_val - value for $$var_name *****************************/ function set_var( $var_name, $var_val ) { if( !$var_name || !$var_val ) { return false; } $_SESSION[$var_name] = $var_val; } /***************************** ** func - get_var() ** @Access - public ** @Desc - Get a session variable ** @param $var_name - the variable name to be retrieved *****************************/ function get_var( $var_name ) { return $_SESSION[$var_name]; } /***************************** ** func - delete_var() ** @Access - public ** @Desc - Delete a session variable ** @param $var_name - the variable name to be deleted *****************************/ function del_var( $var_name ) { unset( $_SESSION[$var_name] ); } /***************************** ** func - delete_vars() ** @Access - public ** @Desc - Delete session variables contained in an array ** @param $arr - Array of the elements ** to be deleted *****************************/ function del_vars( $arr ) { if( !is_array( $arr ) ) { return false; } foreach( $arr as $element ) { unset( $_SESSION[$element] ); } return true; } /***************************** ** func - delete_all_vars() ** @Access - public ** @Desc - Delete all session variables ** @params - None *****************************/ function del_all_vars() { del_all_vars(); } /***************************** ** func - end_session() ** @Access - public ** @Desc - Des! ! troy the session ** @params - None *****************************/ function end_session() { $_SESSION = array(); session_destroy(); } }// End class sessions ?> example.php: <?php include( 'class.session.php' ); // Use this in every page you wa! nt to use sessions first $sess = new sessions() // To set a variable $name = 'langoor, leapinglangoor'; $sess->set_var( 'name', $name ); // Let's retrieve it $name_got = $sess->get_var( 'name' ); // Let's delete the var $sess->del_var( 'name' ); // We're done let's exit $sess->end_session(); ?> Link to comment https://forums.phpfreaks.com/topic/54367-session-without-password/#findComment-268897 Share on other sites More sharing options...
dbillings Posted June 6, 2007 Share Posted June 6, 2007 sessions in a nut shell. Only use session_start() at the top of the html of php page, what I mean is don't have a page use session_start() and then try to use an include("page.php"); that also has a session_start() or it will give you a header has already been sent error. Make sure to put the session_start() at the very begining of the script even before any whitespace. Declaring a session variable $_SESSION['tos'] = value; calling a session variable echo $_SESSION['tos']; It's really that simple. Link to comment https://forums.phpfreaks.com/topic/54367-session-without-password/#findComment-268904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.