session variable problem

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

    #1

    session variable problem

    #register variable
    session_registe r("product1") ;
    session_registe r("product2") ;
    $product1="Palm pilot";
    $product2="Powe r mac 5";

    #print variable from another page
    print "Your chosen products are:\n\n";
    print "<ul><li>$produ ct1\n<li>$produ ct2\n</ul>\n";

    why the above code return

    Your chosen products are:
    Notice: Undefined variable: product1 in C:\Program Files\Apache
    Group\Apache2\h tdocs\session\s ession3.php on line 11

    Notice: Undefined variable: product2 in C:\Program Files\Apache
    Group\Apache2\h tdocs\session\s ession3.php on line 11
  • Rainer Herbst

    #2
    Re: session variable problem

    sky2070 schrieb:[color=blue]
    > #register variable
    > session_registe r("product1") ;
    > session_registe r("product2") ;
    > $product1="Palm pilot";
    > $product2="Powe r mac 5";
    >
    > #print variable from another page
    > print "Your chosen products are:\n\n";
    > print "<ul><li>$produ ct1\n<li>$produ ct2\n</ul>\n";
    >
    > why the above code return
    >
    > Your chosen products are:
    > Notice: Undefined variable: product1 in C:\Program Files\Apache
    > Group\Apache2\h tdocs\session\s ession3.php on line 11
    >
    > Notice: Undefined variable: product2 in C:\Program Files\Apache
    > Group\Apache2\h tdocs\session\s ession3.php on line 11[/color]

    check your setting for register_global s!

    HTH!
    rainer

    Comment

    • Matthias Esken

      #3
      Re: session variable problem

      skywalker2070@h otmail.com (sky2070) schrieb:
      [color=blue]
      > #register variable
      > session_registe r("product1") ;
      > session_registe r("product2") ;
      > $product1="Palm pilot";
      > $product2="Powe r mac 5";
      >
      > #print variable from another page
      > print "Your chosen products are:\n\n";
      > print "<ul><li>$produ ct1\n<li>$produ ct2\n</ul>\n";
      >
      > why the above code return
      >
      > Your chosen products are:
      > Notice: Undefined variable: product1 in C:\Program Files\Apache
      > Group\Apache2\h tdocs\session\s ession3.php on line 11
      >
      > Notice: Undefined variable: product2 in C:\Program Files\Apache
      > Group\Apache2\h tdocs\session\s ession3.php on line 11[/color]

      Seems simple. In your php.ini register_global s is not set "On". On the
      other hand, you can't expect that this value is always "On". On newer
      versions of PHP (> 4.0.x) you should use

      #register variable
      $_SESSION["product1"]="Palm pilot";
      $_SESSION["product2"]="Power mac 5";

      #print variable from another page
      print "Your chosen products are:\n\n";
      print
      "<ul><li>$_SESS ION['product1']\n<li>$_SESSION['product2']\n</ul>\n";

      Matthias

      Comment

      Working...