Hi All I have created a login page from there it ll be rooted to checklogin.php and where I do verification for the userid and password then it ll be rooted to menu.php. I have used session to pass the username from login to menu page and where i am getting the below error..... Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\myth\checklogin.php:1) in C:\xampp\htdocs\myth\checklogin.php on line 2 admin Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\myth\checklogin.php:1) in C:\xampp\htdocs\myth\checklogin.php on line 27 Here are my pages.... Login.php <?php session_start(); $_SESSION['username'] = $_POST['username']; ?> <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> </p> <p> </p> <p> </p> <p> </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> </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"> </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"> </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"> </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" > </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"> </td> </tr> </table></td> </tr> </table> </form> ss </BODY> </HTML> Checklogin.php <?php session_start(); $_SESSION['username'] = $_POST['username']; ?> <?php ob_start(); require("config.php") ; $username=$_POST['username']; $password=$_POST['password']; if ((!$username) || (!$password)) { header('location:index.php?i=1'); exit; } // $password=md5($password); echo $password; $sql="SELECT * FROM $tbl_admin WHERE adminuser='$username' and adminpass='$password'"; $result=mysql_query($sql); $count=mysql_fetch_array($result); if ($count){ header("location:menu.php"); exit; }else{ header("location:login.php?i=2"); exit; } ob_end_flush(); ?> menu.php <?php session_start(); $_SESSION['username'] = $_POST['username']; echo $username; ?> <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> </p> <p> </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"> </td> <td height="40" align="center" bgcolor="#0473AE" class="headtxt"> </td> <td height="40" align="center" bgcolor="#0473AE" class="headtxt"> </td> <td height="40" align="center" bgcolor="#0473AE" class="headtxt"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> s <p> </p> <p> </p> ss </BODY> </HTML>
be sure to remove any space or new line in your checklogin.php file. it must start with <?. And something else, do not set session_start() everytime, maybe its better if you just check it once or at least control it with : if (!isset($_SESSION)) {session_start();} Code (markup):
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> </p> <p> </p> <p> </p> <p> </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> </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"> </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"> </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"> </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" > </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"> </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> </p> <p> </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"> </td> <td height="40" align="center" bgcolor="#0473AE" class="headtxt"> </td> <td height="40" align="center" bgcolor="#0473AE" class="headtxt"> </td> <td height="40" align="center" bgcolor="#0473AE" class="headtxt"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> </BODY> </HTML>