Jump to content

Recommended Posts

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

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 [ leapinglangoor@yahoo.co.in ]
** 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();
?> 

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.