URGENT - Remodified the code - still it's not working...

Discussion in 'PHP' started by mythili, Mar 27, 2011.

  1. #1
    Hi All

    I have remodified the code and still I am not able to print the session value in the corressponding page...

    I have used the below code in the main.php page to get the session value ..BUT THE VALEU SI NOT GETTING PRINTED ...

    $username = $_SESSION['username'];
    echo $username;




    Login.php


    <?
    session_start();
    if(!session_is_registered(myusername)){
    header("location:login.php");
    }
    ?><HTML>
    <HEAD>
    <TITLE> Admin Login </TITLE>
    <link href="css/tblbrd.css" rel="stylesheet" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href="css/text.css" rel="stylesheet" type="text/css">
    <link href="css/heading.css" rel="stylesheet" type="text/css">
    <style>
    body{
    background-color:#0473AE;
    }
    .txt{
    font-family: Tahoma, Geneva, sans-serif;
    font-size:12px;
    font-weight:bold;
    color: #000;
    }
    .adtxt{
    font-family: Arial, Helvetica, sans-serif;
    font-size:20px;
    font-weight:bold;
    color:#333333;

    }

    .adtxt1 { font-family: Tahoma, Geneva, sans-serif;
    font-size:14px;
    font-weight:bold;
    color: #000;
    }
    .txt1 { font-family: Tahoma, Geneva, sans-serif;
    font-size:12px;
    font-weight:bold;
    color:#FFF;
    }
    </style>
    </HEAD>
    <body>


    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <form name="form" method="post" action="checklogin.php"><table width="617" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="617" height="501" bgcolor="#FFFFFF"><table width="607" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF" class="tblbrd">
    <tr>
    <td width="599" height="69" align="center" valign="top" bgcolor="#e5e3e4" class="adtxt"><p><img src="images/banner.jpg" width="600" height="100"><br>
    </p></td>
    </tr>
    <tr>
    <td height="290" align="center" valign="top"bgcolor="#0473AE"><br>
    <br>
    <table width="411" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
    <td width="403" height="222" colspan="0" valign="top" bgcolor="#0473AE"><p>&nbsp;</p>
    <table width="321" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
    <td width="319"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="tblbrd">
    <tr align="center">
    <td height="33" colspan="4" bgcolor="#F2F2F2"><strong class="adtxt1">User Login</strong></td>
    </tr>
    <tr>
    <td height="19" colspan="4" align="right" bgcolor="#E5E3E4" class="txt1">&nbsp;</td>
    </tr>
    <tr>
    <td width="101" height="35" align="right" bgcolor="#E5E3E4" class="txt">Username</td>
    <td width="11" height="35" align="center" bgcolor="#E5E3E4">&nbsp;</td>
    <td width="207" height="35" colspan="2" bgcolor="#E5E3E4"><input name="username" type="text" id="username" ></td>
    </tr>
    <tr>
    <td width="101" height="35" align="right" bgcolor="#E5E3E4" class="txt">Password</td>
    <td height="35" align="center" bgcolor="#E5E3E4">&nbsp;</td>
    <td height="35" colspan="2" bgcolor="#E5E3E4"><input name="password" type="password" id="password"></td>
    </tr>
    <tr align="center">
    <td height="45" colspan="4" bgcolor="#E5E3E4"><input type="submit" name="Submit" value="Login"></td>
    </tr>
    <tr align="center">
    <td height="27" colspan="4" bgcolor="#FFFFFF" >&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table>
    <br>
    <br></td>
    </tr>
    </table>
    <br>
    <br></td>
    </tr>
    <tr>
    <td height="25" valign="top" bgcolor="#e5e3e4" background="images/top_menu.jpg">&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table>
    </form>
    ss
    </BODY>
    </HTML>




    Checklogin.php
    <?php
    ob_start();
    include "config.php";
    $username=$_POST['username'];
    $password=$_POST['password'];

    if ((!$username) || (!$password))
    {
    header('location:index.php?i=1');
    exit;
    }
    $sql="SELECT * FROM $tbl_admin WHERE adminuser='$username' and adminpass='$password'";
    echo $sql;
    $result=mysql_query($sql);
    //$count=mysql_fetch_array($result);
    $count=mysql_num_rows($result);

    if($count==1){
    session_register("username",$username);
    session_register("password",$password);
    header("location:menu.php");
    }
    else {
    echo "Wrong Username or Password";
    }
    ob_end_flush();

    ?>



    menu.php
    <?
    session_start();
    //if(!session_is_registered(username)){
    $username = $_SESSION['username'];
    echo $username;
    //header("location:main_login.php");

    ?>

    <HTML>
    <HEAD>
    <TITLE> Admin Login </TITLE>
    <link href="css/tblbrd.css" rel="stylesheet" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href="css/text.css" rel="stylesheet" type="text/css">
    <link href="css/heading.css" rel="stylesheet" type="text/css">
    <style>
    body{
    background-color:#0473AE;
    }
    .border{
    border:1px solid #ffffff;
    }
    .txt{
    font-family: Tahoma, Geneva, sans-serif;
    font-size:12px;
    font-weight:bold;
    color:#FFF;
    }
    .headtxt{
    font-family: Arial, Helvetica, sans-serif;
    font-size:16px;
    font-weight:bold;
    color:#4b5676;
    text-decoration:none;
    }
    .headtxt a : hover{
    font-family: Arial, Helvetica, sans-serif;
    font-size:16px;
    font-weight:bold;
    color:#4b5676;
    text-decoration:none;
    }
    .adtxt{
    font-family: Tahoma, Geneva, sans-serif;
    font-size:14px;
    font-weight:bold;
    color: #000;

    }
    .menutxt{
    font-family: Arial, Helvetica, sans-serif;
    font-size:18px;
    font-weight:bold;
    color: #ffffff;
    }

    </style>
    </HEAD>
    <body>


    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table width="595" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
    <tr>
    <td width="593" height="375" bgcolor="#ffffff"><table width="571" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="571" height="61" align="center" bgcolor="#0473AE"><span style="font-family:Tahoma, Geneva, sans-serif; font-size:22px; font-style: italic font-weight:bold; color:#ffffff;">Weekly Work Report</span></td>

    </tr>
    <tr>
    <td height="294" align="center" bgcolor="#0473AE"><table width="79%" border="0" cellpadding="0" cellspacing="0" bgcolor="#fffff" class="tblbrd">
    <tr>
    <td width="18%" height="125" align="center" bgcolor="#0473AE" class="menutxt"><img src="images/add.png" width="68" height="68"></td>
    <td width="35%" height="125" align="left" bgcolor="#0473AE" class="headtxt">
    <a href="statusinput.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; text-decoration:none; color:#ffffff;">Insert Data</a></td>
    <td width="18%" align="left" bgcolor="#0473AE" class="headtxt"><img src="images/view.png" width="68" height="68"></td>
    <td width="29%" height="125" align="left" bgcolor="#0473AE" class="headtxt"><a href="index1.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; font-style: italic font-weight:bold; text-decoration:none; color:#ffffff;">View Data</a></td>
    </tr>
    <tr align="center">
    <td height="89" align="center" bgcolor="#0473AE"><img src="images/report.png" width="68" height="68"></td>
    <td height="89" align="left" bgcolor="#0473AE"><span class="headtxt"><a href="reportview.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; font-style: italic font-weight:bold; text-decoration:none; color:#ffffff;">Report View</a></span></td>
    <td height="89" align="left" bgcolor="#0473AE"><span class="headtxt"><img src="images/logout.png" width="73" height="66"></span></td>
    <td height="89" align="left" bgcolor="#0473AE" class="headtxt"><a href="logout.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; font-style: italic font-weight:bold; text-decoration:none; color:#ffffff;">Logout</a></td>
    </tr>
    <tr>
    <td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
    <td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
    <td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
    <td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table></td>
    </tr>
    </table>


    </BODY>
    </HTML>
     
    mythili, Mar 27, 2011 IP
  2. nklven

    nklven Peon

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you checked weather you got value while you create session?
     
    nklven, Mar 27, 2011 IP
  3. mythili

    mythili Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Pls let me know how to check it?
     
    mythili, Mar 27, 2011 IP
  4. joy1986joy

    joy1986joy Member

    Messages:
    189
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #4
    menu.php
    <?
    session_start();
    //if(!session_is_registered(username)){
    $username = $_SESSION['username'];
    echo $username;
    //header("location:main_login.php");
    
    ?>
    PHP:
    In above code you are not geting the user name from previous page. In there what is the value of $username?
     
    joy1986joy, Mar 28, 2011 IP
  5. mythili

    mythili Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I am not getting any values in the Main.php from the checklogin page the value is not getting printed

    Where echo $username returns no value
     
    mythili, Mar 28, 2011 IP