Jump to content

Session without password?


argan328

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 [ [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();
?> 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.