Cookie dos not expire. Why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carlos Marangon

    Cookie dos not expire. Why?

    Hello!


    I made the code below.

    <?php
    if ($Test6 != '') {
    $Test6++;
    setcookie("Test 6",$Test6, time()+10); // select cookie name
    } else {
    setcookie("Test 6",1, time()+10); //Create value 1
    $Test6 = 1;
    }
    $numvisits = $Test6;
    if ($numvisits<6)
    {
    print("ACCESS") ;
    }

    else
    {
    print("DENIED") ;
    }


    It works fine in my localhost and after 10 seconds,
    if I reload It grant access, but it does not work on
    my server.
    Why?

    []

    CAlos
  • Reply via newsgroup

    #2
    Re: Cookie dos not expire. Why?

    Carlos Marangon wrote:
    [color=blue]
    > Hello!
    >
    >
    > I made the code below.
    >
    > <?php
    > if ($Test6 != '') {
    > $Test6++;
    > setcookie("Test 6",$Test6, time()+10); // select cookie name
    > } else {
    > setcookie("Test 6",1, time()+10); //Create value 1
    > $Test6 = 1;
    > }
    > $numvisits = $Test6;
    > if ($numvisits<6)
    > {
    > print("ACCESS") ;
    > }
    >
    > else
    > {
    > print("DENIED") ;
    > }
    >
    >
    > It works fine in my localhost and after 10 seconds,
    > if I reload It grant access, but it does not work on
    > my server.
    > Why?
    >
    > []
    >
    > CAlos[/color]

    Everytime you refresh the page $Test6 will never have a value... your
    cookie is available in $_COOKIE['Test6'], not $Test6... Thus, before
    your 'if' conditional statement at line 1, put in something like

    $Test6=$_COOKIE['Test6'];

    See if that helps you - if not, let me know and if I'll do my best to
    help...

    randelld

    Comment

    • Carlos Marangon

      #3
      Re: Cookie dos not expire. Why?

      Hello!

      It just works on localhost.

      I am trying to make a code that deny user access when it typethe
      incorrect password 3 times. The code works fine in my localhost but at
      the server it alwauys says DENIED.

      If you have any idea please reply me.


      []

      Carlos


      Reply via newsgroup <reply-to-newsgroup@pleas e.com> wrote in message news:<2pCZb.582 042$ts4.45214@p d7tw3no>...[color=blue]
      > Carlos Marangon wrote:
      >[color=green]
      > > Hello!
      > >
      > >
      > > I made the code below.
      > >
      > > <?php
      > > if ($Test6 != '') {
      > > $Test6++;
      > > setcookie("Test 6",$Test6, time()+10); // select cookie name
      > > } else {
      > > setcookie("Test 6",1, time()+10); //Create value 1
      > > $Test6 = 1;
      > > }
      > > $numvisits = $Test6;
      > > if ($numvisits<6)
      > > {
      > > print("ACCESS") ;
      > > }
      > >
      > > else
      > > {
      > > print("DENIED") ;
      > > }
      > >
      > >
      > > It works fine in my localhost and after 10 seconds,
      > > if I reload It grant access, but it does not work on
      > > my server.
      > > Why?
      > >
      > > []
      > >
      > > CAlos[/color]
      >
      > Everytime you refresh the page $Test6 will never have a value... your
      > cookie is available in $_COOKIE['Test6'], not $Test6... Thus, before
      > your 'if' conditional statement at line 1, put in something like
      >
      > $Test6=$_COOKIE['Test6'];
      >
      > See if that helps you - if not, let me know and if I'll do my best to
      > help...
      >
      > randelld[/color]

      Comment

      • Geoff Berrow

        #4
        Re: Cookie dos not expire. Why?

        I noticed that Message-ID:
        <2cfc228.040221 0912.11ddc99e@p osting.google.c om> from Carlos Marangon
        contained the following:
        [color=blue]
        >I am trying to make a code that deny user access when it typethe
        >incorrect password 3 times. The code works fine in my localhost but at
        >the server it alwauys says DENIED.
        >
        >If you have any idea please reply me.[/color]

        I use this - just include it at the beginning of any file you want to
        protect.

        <?php
        // Check to see if $PHP_AUTH_USER already contains info

        if (!isset($GLOBAL S['PHP_AUTH_USER'])) {

        // If empty, send header causing dialog box to appear

        header('WWW-Authenticate: Basic realm="My Private Stuff"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Authorization Required.';
        exit;

        } else if (isset($GLOBALS['PHP_AUTH_USER'])) {

        if (($GLOBALS['PHP_AUTH_USER'] != "Username") ||
        ($GLOBALS['PHP_AUTH_PW'] != "Password") ) {

        header('WWW-Authenticate: Basic realm="My Private Stuff"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Authorization Required.';
        exit;

        } else {
        echo "
        <P>You're authorized!</p>
        ";
        }
        }
        ?>

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Reply via newsgroup

          #5
          Re: Cookie dos not expire. Why?

          Carlos Marangon wrote:
          [color=blue]
          > Hello!
          >
          > It just works on localhost.
          >
          > I am trying to make a code that deny user access when it typethe
          > incorrect password 3 times. The code works fine in my localhost but at
          > the server it alwauys says DENIED.
          >
          > If you have any idea please reply me.
          >
          >
          > []
          >
          > Carlos[/color]

          I'm sorry - I'm lost - I don't see how it would work since $Test6 should
          never have a value everytime it starts, thus

          $Test6++;
          setcookie("Test 6",$Test6, time()+10); // select cookie name

          will mean $Test6 will always equal 1 everytime the browser refreshes...
          and the cookie that is set will also be always set to 1 on that basis.
          Thus, $Test6 (or $numvisits) will always be less than 6, therefore
          always giving you access... Is there a time, when run locally, that you
          get access denied? My guess is not...

          I've relooked at your code and find it will not work as designed, even
          if $Test6 had values... Hears why...

          - $Test6 will always equal nothing since you've not given it a value
          meaning the code in the first brace will *always* run. It will set a
          cookie called Test6 to 1 and the cookie will expire in ten seconds. You
          have a remark statement that says "select cookie name" - setcookie()
          sets a cookie, it does not select it.
          - The 'else' part of your if conditional statement never runs since
          $Test6 never has a value. If it were to run, it would continually set
          the cookie to the number 1, and set $Test6 to 1.
          - $numvisits gets the value of $Test6 meaning you've now copied a
          variable (?) and it too now equals 1.
          - Your last if conditional statement says if $numvisits is less than 6
          (which it is) then to grant access.

          Conclusion: Access is always given...

          Therefore, can you confirm that you do at some point, either locally or
          on your server sometime or other get an ACCESS DENIED? My guess is you
          never do, at anytime, regardless where the script is hosted.

          <?php
          if ($Test6 != '') {
          $Test6++;
          setcookie("Test 6",$Test6, time()+10); // select cookie name
          } else {
          setcookie("Test 6",1, time()+10); //Create value 1
          $Test6 = 1;
          }
          $numvisits = $Test6;
          if ($numvisits<6)
          {
          print("ACCESS") ;
          }

          else
          {
          print("DENIED") ;
          }
          ?>

          Comment

          • Reply via newsgroup

            #6
            Re: Cookie dos not expire. Why?

            Geoff Berrow wrote:
            [color=blue]
            > I noticed that Message-ID:
            > <2cfc228.040221 0912.11ddc99e@p osting.google.c om> from Carlos Marangon
            > contained the following:
            >
            >[color=green]
            >>I am trying to make a code that deny user access when it typethe
            >>incorrect password 3 times. The code works fine in my localhost but at
            >>the server it alwauys says DENIED.
            >>
            >>If you have any idea please reply me.[/color]
            >
            >
            > I use this - just include it at the beginning of any file you want to
            > protect.
            >
            > <?php
            > // Check to see if $PHP_AUTH_USER already contains info
            >
            > if (!isset($GLOBAL S['PHP_AUTH_USER'])) {
            >
            > // If empty, send header causing dialog box to appear
            >
            > header('WWW-Authenticate: Basic realm="My Private Stuff"');
            > header('HTTP/1.0 401 Unauthorized');
            > echo 'Authorization Required.';
            > exit;
            >
            > } else if (isset($GLOBALS['PHP_AUTH_USER'])) {
            >
            > if (($GLOBALS['PHP_AUTH_USER'] != "Username") ||
            > ($GLOBALS['PHP_AUTH_PW'] != "Password") ) {
            >
            > header('WWW-Authenticate: Basic realm="My Private Stuff"');
            > header('HTTP/1.0 401 Unauthorized');
            > echo 'Authorization Required.';
            > exit;
            >
            > } else {
            > echo "
            > <P>You're authorized!</p>
            > ";
            > }
            > }
            > ?>
            >[/color]

            I don't see how the above would resolve his situation - You've not given
            him any information as to how he could authorize other users...

            randelld

            Comment

            Working...