Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change variable in session and redirect user

    Hello There,

    I've set-up a web site but I absolutely need a disclaimer to be agreed by the visitor when he open the web page.

    I've got an structure with php include and everything work great.

    I've added a session to store a variable to know if the user has or not agreed the disclaimer:

    PHP Code:
    session_start();
    $_SESSION['Disclaimer'] = 0// store session data 
    To check if the disclaimer must be display:

    PHP Code:
    if($_SESSION['Disclaimer'] == 0)
       
    $page $page_disclaimer
    This is in my Index php which manage the include.

    So now I've set-up a page "Disclaimer" to be include in the page index.php

    My problem is I want via a form in the page Disclaimer.php change the variable $_SESSION['Disclaimer'] to 1 and redirect to home page.

    Here is the code which is not working, I'm not even sure the variable is properly change to 1 and it keep display the disclaimer:

    PHP Code:
    <form method="LINK" action="<?PHP $_SESSION['Disclamer'] = 1;
    echo(
    "index.php?page=Home");
    ?>">
      <input type="submit" value="I agree" />
    </form>
    I've tried many method but no correct result....I'm not a php dev so any help will be welcome.

    Tks
    Last edited by santino_london; 12-17-2010 at 11:55 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Change
    <form method="LINK" action="<?PHP $_SESSION['Disclamer'] = 1;
    echo("index.php?page=Home");
    ?>">
    to
    PHP Code:
    <form method="GET" action="index.php?page=Home&amp;unset"
    and at the top of "Home" page, add the following code
    PHP Code:
    if(isset($_GET['unset']))
     
    $_SESSION['Disclamer'] = 
    (assuming, all you pages have a call to session_start() at the top )
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tks for the reply.

    Ok I tried but I probably miss something.

    I'm starting only one session (as I assume otherwise you have multiple session??) in my Index page which include the other page like Home, Disclaimer, about,...

    so I've added in he php of the index page this section:

    PHP Code:
    if(isset($_GET['unset']))
     
    $_SESSION['Disclamer'] = ;

    if(
    $_SESSION['Disclaimer'] == 0)
        
    $page $page_disclaimer
    my form in the page "Disclaimer" itself include in the index page:

    PHP Code:
    <form method="GET" action="index.php?page=Home&amp;unset"
      <
    input type="submit" value="I agree" />
    </
    form
    And I just start one session at the beginning of my php which manage the include in the Index page:

    PHP Code:
    <?php
    session_start
    (); 
    $_SESSION['Disclaimer'] = 0// store session data
    But still a disclaimer include all the time after I click on Agree
    Last edited by santino_london; 12-17-2010 at 11:54 AM.

  • #4
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone to suggest a solution?

    Tks

  • #5
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    I'm starting only one session (as I assume otherwise you have multiple session??) in my Index page which include the other page like Home, Disclaimer, about,...
    At the start of every page BEFORE ANY SPACE OR ANY CODE other than <?php start session

    PHP Code:
    <?php
    session_start
    ();
    //rest of the code
    Also do what abduraooft said in early post after that

    Also you may have to do a value check if you have a "disagree" button also ... by using the corresponding $_POST[] or $_GET[] variables

    And dont start sessions once its started later in the SAME page.... (in another page you HAVE to start)

    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_GET['submit_button']) && $_GET['submit_button']=="I agree")
    {
    //redirect or set the page here
    }
    ?>

    <form method="get" action="YOUR_HOME.php">
      <input name="submit_button" type="submit" value="I agree" />
    </form>
    Last edited by adarshakb; 12-17-2010 at 06:41 PM.
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #6
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by adarshakb View Post
    At the start of every page BEFORE ANY SPACE OR ANY CODE other than <?php start session

    PHP Code:
    <?php
    session_start
    ();
    //rest of the code
    Tks for helping!

    I've already try to start a session at the beginning of each page but it generate the error below when it include Disclaimer.php:

    Code:
    Notice: A session had already been started - ignoring session_start()
    So I can only start one session in the index page.

    Just to summarize, here what I've got:

    Page Disclaimer.php (which is include in index.php)

    PHP Code:
    <body>
    <
    form method="GET" action="index.php?page=Home&amp;unset"
      <
    input type="submit" value="I agree" />
    </
    form>
    </
    body
    Home.php (I start a session but it generate an error as well)

    PHP Code:
    <body>
    <?php
    session_start
    (); 
    if(isset(
    $_GET['unset']))
     
    $_SESSION['Disclaimer'] = 
    ?>

    and index.php at the beginning of the page:

    PHP Code:
    <body>
    <?php
    session_start
    (); 
    ?>
    and in html section I include the other pages:

    PHP Code:
    <?php 
    $_SESSION
    ['Disclaimer'] = 0// store session data

    //code which manage the include

    if($_SESSION['Disclaimer'] == 0)
        
    $page $page_disclaimer;
    So at the moment, I can see first the Disclaimer but impossible to change the variable $_SESSION['Disclaimer'] to 1 so the visitor can see any other pages.
    Last edited by santino_london; 12-18-2010 at 09:57 AM.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    So I can only start one session in the index page.
    That's what you actually need.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    That's what you actually need.
    Ok so any idea why it do not work? What I do wrong?

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    and in html section I include the other pages:
    What do you mean by that? Have you written the php code in an .html file?

    Anyway, to "use" session, you need to have a call to the function session_start() at the top of all pages.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #10
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    At the start of every page BEFORE ANY SPACE OR ANY CODE other than <?php start session...
    you may have misunderstood me...

    You have to start it at top of ALL pages.

    But say you have a include() in the page... that page shouldnt start a session again.

    Thus only 1 session is started
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #11
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    Quote Originally Posted by santino_london View Post
    Home.php (I start a session but it generate an error as well)

    PHP Code:
    <body>
    <?php
    session_start
    (); 
    if(isset(
    $_GET['unset']))
     
    $_SESSION['Disclaimer'] = 
    ?>

    and index.php at the beginning of the page:

    PHP Code:
    <body>
    <?php
    session_start
    (); 
    ?>
    You are starting the output BEFORE you start the session
    It should come BEFORE all other things.
    So <body> THEN session start is wrong.....

    Put this at the TOP <?php session_start() ?>
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs


  •  

    Posting Permissions

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