Session in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alien
    New Member
    • Sep 2007
    • 61

    Session in php

    Hi guys,

    I was doing a bit of experiment in php's session so i can apply something similar to another problem I am working on.


    Basically I am implementing a clicker which will count the number of clicks using sessions.


    [code='php']
    <?php
    session_start() ;

    if(!isset($_ses sion['val']) )
    $_session['val'] = 0;
    else
    $_session['val']++;
    ?>
    <html>
    <body>
    <form>
    <a href="tester.ph p?v=clicked">Cl ick this Link</a>
    </form>
    <?php
    if($_GET['v'] == "clicked")
    $_session['val']++;

    echo $_session['val'];
    ?>
    </body>
    </html>
    [/code]

    When I load page for first time i get 0, after first click it echos out 1 as it should but then it doesnt go up any more. Cant see whats different 2nd time and onwards as the value should get incremented.

    Any ideas will be appreciated. Thanks heaps.
  • Alien
    New Member
    • Sep 2007
    • 61

    #2
    Found the problem. Its $_SESSION instead of $_session. Didnt know small caps would have caused problems. Thanks for looking at it anyway. :)

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      don’t you get an undefined index error when you load the page for the first time?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by Alien
        Found the problem. Its $_SESSION instead of $_session. Didnt know small caps would have caused problems. Thanks for looking at it anyway. :)
        They always will - PHP _is_ case-senstive (in most cases (no pun intended) - I think you can write internal functions either upper- or lower-case and have it work. Variables, however, do not <sarcasm>enjo y</sarcasm> this <sarcasm>abilit y</sarcasm>.

        Comment

        Working...