www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: trying to have a pop up that is remembered and checked globally

  1. #1
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459

    trying to have a pop up that is remembered and checked globally

    if you view my topic here
    http://www.webdeveloper.com/forum/sh...085#post990085

    i am trying to have it where once they enter the SITE they have to agree they are 18 years of age or older, no matter what they do, if they click NO it remembers that, how would i make something like this on every page so there is no way of getting around it

  2. #2
    Join Date
    Apr 2007
    Posts
    1,664
    Use a session variable. Have the yes link/button set a SESSION value and test for it on every page using an included file or function call.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  3. #3
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    oh could you help me with that, I dont know much about it

  4. #4
    Join Date
    Apr 2007
    Posts
    1,664
    First put this on the page and see if session is auto started

    Open a new file and add this code ( just this code) to the very top of the file (no spaces before)
    PHP Code:
    <?
    $_SESSION
    ['test']='testing';
    echo 
    $_SESSION['test'];
    ?>
    Save it and visit it in a browser. If you dont see 'testing' then you need to add this

    PHP Code:
    <?
    session_start
    ();
    $_SESSION['test']='testing';
    echo 
    $_SESSION['test'];
    ?>
    Then you should see 'testing' and the SESSION is good. if you need to start the session the you need to do that on every page using SESSION variables.

    Open a new file and add this code.
    PHP Code:
    <?
    $kick_to
    ="/index.php";
    if(!isset(
    $_SESSION['over18'])) header("Location: $kick_to");//kicks user to root folder index file. Change to anything you need 
    ?>
    Save this file as kick.php remember the path to where the file is saved

    Open a new file and add this code to the top of every page you want to protect.
    PHP Code:
    <?
    include "/path/to/kick.php";//change to the real path
    ?>
    <html>
    <head>
    etc, etc...
    index.php is presumably your site's entry page and where I'm kicking users to. Here have the javascript that handles showing the pop up. I've used a simple confirm but ou could use a pop up, hidden div etc and submit a form that reloads the index.php page.

    PHP Code:
    <?
    //unset($_SESSION['over18']);//uncomment to reset SESSION var
    ?>
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function agecheck(){
    <?
    if(@$_GET['ru18']=="yes")$_SESSION['over18']=1;
    if(!isset(
    $_SESSION['over18'])){
    ?>
        var r=confirm("Are you over 18? If yes click OK")
        if (r==true){
            document.location="<?=$_SERVER['SCRIPT_NAME']?>?ru18=yes";

        }else{
            alert('No pron for you!');
        }
    <?
    }
    ?>
    }
    //-->
    </script>

    </head>
    <body onload="agecheck()">
    <?
    if(!isset($_SESSION['over18'])) exit;//no session var so stop displaying content.
    ?>
    hello grown ups!
    </body>
    </html>
    Back up your original index.php and save above code as index.php in your root folder.

    Please be specific with any problems you have. There never too much details when posting a problem.
    Last edited by SyCo; 03-19-2009 at 01:41 PM.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  5. #5
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    225
    This script is untested, but it should work.

    PHP Code:
    <?
    session_start
    ();  // This line must be at the top of the document for sessions to work

    function age_check() {

        if (!isset(
    $_SESSION['age'])) {    // Check if the user have answered the question or not
        
            
    if (isset($_POST['over_18'])) {        // If the user said (s)he was over 18
            
                
    $_SESSION['age'] = "over";        // Set a session variable that can be accessed anywhere from the script
            
            
    }
            else if (isset(
    $_POST['under_18'])) {    // If the user said (s)he was under 18
            
                
    $_SESSION['age'] = "under";
            
            }
            else {        
    // Show the user the form
                
    echo "<form name='age_check' method='post' action=''>";
                echo 
    "Are you 18 years of age or older? ";
                echo 
    "<input type='submit' value='Yes' name='over_18'> ";
                echo 
    "<input type='submit' value='No' name='under_18'>";
                echo 
    "</form>";
                exit;  
    // Exit after the form
            
    }
            
            
    $url $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];   // Get the url of the current page
            
    header("Location: $url");    // Refresh the page
        
    }
    }

    age_check();   //  Call the function

    // Lets see if the user is 18+ years old
    if ($_SESSION['age'] == "over")
        echo 
    "You are 18 years of age or older";
    else
        echo 
    "You are less than 18 years old";
    ?>
    EDIT: The odds of two people posting at the same time.

  6. #6
    Join Date
    Apr 2007
    Posts
    1,664
    If you don't want to kick then to the index you could just do this.

    Create the include with this code

    PHP Code:
    <?
    if(@$_GET['ru18']=="yes")$_SESSION['over18']=1;
    if(!isset(
    $_SESSION['over18'])){
    ?>
        var r=confirm("Are you over 18? If yes click OK")
        if (r==true){
            document.location="<?=$_SERVER['SCRIPT_NAME']?>?ru18=yes";

        }else{
            alert('too young');
        }
    <?
    }

    ANd include it on every page you want to protect like this

    PHP Code:
    <?
    //unset($_SESSION['over18']);//uncomment to reset SESSION var
    ?>
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function agecheck(){
    <?
    include "/path/to/agecheck.php";
    ?>
    }
    //-->
    </script>

    </head>
    <body onload="agecheck()">
    <?
    if(!isset($_SESSION['over18'])) exit;//no session so stop displaying content.
    ?>
    hello grown ups!
    </body>
    </html>
    and be sure to call the js function onload too.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  7. #7
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    Quote Originally Posted by Quidam View Post
    This script is untested, but it should work.

    PHP Code:
    <?
    session_start
    ();  // This line must be at the top of the document for sessions to work

    function age_check() {

        if (!isset(
    $_SESSION['age'])) {    // Check if the user have answered the question or not
        
            
    if (isset($_POST['over_18'])) {        // If the user said (s)he was over 18
            
                
    $_SESSION['age'] = "over";        // Set a session variable that can be accessed anywhere from the script
            
            
    }
            else if (isset(
    $_POST['under_18'])) {    // If the user said (s)he was under 18
            
                
    $_SESSION['age'] = "under";
            
            }
            else {        
    // Show the user the form
                
    echo "<form name='age_check' method='post' action=''>";
                echo 
    "Are you 18 years of age or older? ";
                echo 
    "<input type='submit' value='Yes' name='over_18'> ";
                echo 
    "<input type='submit' value='No' name='under_18'>";
                echo 
    "</form>";
                exit;  
    // Exit after the form
            
    }
            
            
    $url $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];   // Get the url of the current page
            
    header("Location: $url");    // Refresh the page
        
    }
    }

    age_check();   //  Call the function

    // Lets see if the user is 18+ years old
    if ($_SESSION['age'] == "over")
        echo 
    "You are 18 years of age or older";
    else
        echo 
    "You are less than 18 years old";
    ?>
    EDIT: The odds of two people posting at the same time.
    and do i put this on the top of every page or just make a php page for this?

  8. #8
    Join Date
    Apr 2007
    Posts
    1,664
    Quote Originally Posted by Baby Jai View Post
    and do i put this on the top of every page or just make a php page for this?
    Err, you have 2 solutions (3 now) and I went to great lengths to explain how to use it and mine has your requested pop up and also handles not displaying code to under 18s and determining if auto stat is set. Yet you chose the shorter version and ask how to use it?

    I like helping people who like to learn but that just seems lazy to me.

    .
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  9. #9
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    Quote Originally Posted by SyCo View Post
    First put this on the page and see if session is auto started

    Open a new file and add this code ( just this code) to the very top of the file (no spaces before)
    PHP Code:
    <?
    $_SESSION
    ['test']='testing';
    echo 
    $_SESSION['test'];
    ?>
    Save it and visit it in a browser. If you dont see 'testing' then you need to add this

    PHP Code:
    <?
    session_start
    ();
    $_SESSION['test']='testing';
    echo 
    $_SESSION['test'];
    ?>
    Then you should see 'testing' and the SESSION is good. if you need to start the session the you need to do that on every page using SESSION variables.

    Open a new file and add this code.
    PHP Code:
    <?
    $kick_to
    ="/index.php";
    if(!isset(
    $_SESSION['over18'])) header("Location: $kick_to");//kicks user to root folder index file. Change to anything you need 
    ?>
    Save this file as kick.php remember the path to where the file is saved

    Open a new file and add this code to the top of every page you want to protect.
    PHP Code:
    <?
    include "/path/to/kick.php";//change to the real path
    ?>
    <html>
    <head>
    etc, etc...
    index.php is presumably your site's entry page and where I'm kicking users to. Here have the javascript that handles showing the pop up. I've used a simple confirm but ou could use a pop up, hidden div etc and submit a form that reloads the index.php page.

    PHP Code:
    <?
    //unset($_SESSION['over18']);//uncomment to reset SESSION var
    ?>
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function agecheck(){
    <?
    if(@$_GET['ru18']=="yes")$_SESSION['over18']=1;
    if(!isset(
    $_SESSION['over18'])){
    ?>
        var r=confirm("Are you over 18? If yes click OK")
        if (r==true){
            document.location="<?=$_SERVER['SCRIPT_NAME']?>?ru18=yes";

        }else{
            alert('No pron for you!');
        }
    <?
    }
    ?>
    }
    //-->
    </script>

    </head>
    <body onload="agecheck()">
    <?
    if(!isset($_SESSION['over18'])) exit;//no session var so stop displaying content.
    ?>
    hello grown ups!
    </body>
    </html>
    Back up your original index.php and save above code as index.php in your root folder.

    Please be specific with any problems you have. There never too much details when posting a problem.
    lol i set it to seasamestreet.com and no good, check out NOT SAFE FOR WORK! juicy6.com and you will see what im talking about, it doesnt even give me a pop up
    Last edited by Baby Jai; 03-19-2009 at 02:34 PM.

  10. #10
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    Quote Originally Posted by SyCo View Post
    Err, you have 2 solutions (3 now) and I went to great lengths to explain how to use it and mine has your requested pop up and also handles not displaying code to under 18s and determining if auto stat is set. Yet you chose the shorter version and ask how to use it?

    I like helping people who like to learn but that just seems lazy to me.

    .
    no i went with yours, but no good, check it out please, and can i remove the testing on the top

  11. #11
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    in opera i dont get a pop up at all

  12. #12
    Join Date
    Apr 2007
    Posts
    1,664
    i set it to seasamestreet.com
    Set what? Where do I say change a URL? If you don't know what you're doing and you change stuff I'm not surprised it's not working.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  13. #13
    Join Date
    Apr 2007
    Posts
    1,664
    Quote Originally Posted by Baby Jai View Post
    no i went with yours, but no good, check it out please, and can i remove the testing on the top
    What?

    Please re read it and follow the instructions more carefully.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  14. #14
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    ok i followed it to a T!

    PHP Code:
    <?
    $kick_to
    ="index.php";
    if(!isset(
    $_SESSION['over18'])) header("Location: $kick_to");//kicks user to root folder index file. Change to anything you need 
    ?>
    that to me MEANS that i can change ANYTHING to i need, if you look at the code on the pages you will see it doesnt work, every link i go to after the main page goes to index.php because i inlcuded this on all the pages I wanted to protect, it works ok in IE but not in Firefox and in Opera

    The session part i dont understand, im not that great with php, I mean i dont want it saying testing on every page

  15. #15
    Join Date
    Apr 2007
    Posts
    1,664
    Quote Originally Posted by Baby Jai View Post
    in opera i dont get a pop up at all
    Work fine in Opera for me.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles