php session variable problem

Discussion in 'PHP' started by newbie8899, Apr 16, 2008.

  1. #1
    Hi, all,

    I have a problem here.. for example in the first page - page1.php, i have a form. The form have LoginID and Pwd. when i click at the submit button, it will collect the LoginID and Pwd into the session variable.. then will link to page2.php. The problem i face now is i cannot get the session variable in page2.php.. below is my code.
    
    
    
    
    <?php 
    	session_start(); // start up your PHP session! 
    
    	$_SESSION['LoginID']  = $_REQUEST["LoginID"];
    	$_SESSION['Pwd'] = $_REQUEST["Pwd"];
    ?>
    
    <form name="form1" action="page2.php" method="POST">
    
    <table>
    	<tr>
                       <td>Login ID:</td><td><input name="LoginID" type="text" id="LoginID" size="20" </td>
                 </tr>
                 <tr>
                       <td>Password:</td><td><input name="Pwd" type="text" id="Pwd" size="20" </td>
                 </tr>
                 <tr>
                       <td><input name="submit" type="submit" id="submit" size="20" </td>
                 </tr>
    
    
    </form>
    
    
    PHP:
    Then in the second page, page2.php i do this:

    
    <?php 
    	 session_start();
                  echo $_SESSION[‘LoginID'];
                  echo $_SESSION[‘Pwd'];
    
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    </body>
    </html>
    
    
    
    PHP:
    but the session variable it got is empty.. anyone.. please help.. thank you in advance.
     
    newbie8899, Apr 16, 2008 IP
  2. MicroTheme

    MicroTheme Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hello,
    you must make a registered session like as :

    
    $valid=$_REQUEST["LoginID"];
    session_register('valid');
    
    PHP:
    then you can called it :

    
    $_SESSION['valid']
    
    PHP:
     
    MicroTheme, Apr 16, 2008 IP
  3. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Actually, the problem is with this bit:
    
    <?php 
    	 session_start();
                  echo $_SESSION[‘LoginID'];
                  echo $_SESSION[‘Pwd'];
    
    ?>
    
    PHP:
    You're using a backtick ( ` ) instead of an apostrophe ( ' ). IE `LoginId' needs to be 'LoginId'
     
    Synchronium, Apr 16, 2008 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    Amen to that
     
    bartolay13, Apr 16, 2008 IP