i'm using php 5.4.3, I'm wondering if it's possible to use function session_start().
my idea is to have a login page, then use the username in all pages of the site, the problem is that the $username is not visible in the second page...
index.php
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log in</title>
<meta name="alex" content="sermail" />
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#00814B ">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#339900 ">
<tr>
<td colspan="3"><strong>Log in </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
checklogin.php
<?php
// Connect to server and select databse.
//conecção ao servidor
$conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
$db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");
// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM members WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['username'] = '$username';
header("location:menu.html");
}
else {
echo "Wrong Username or Password";
}
?>
menu.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sermail</title>
<meta name="author" content="Alex" />
<link rel="stylesheet" type="text/css" href="styles/styles.css" />
<style type="text/css" media="view">
.printbutton {
visibility: show;
}
</style>
<script LANGUAGE="javascript">
<!-- defines size of window -->
function ScreenSize(w,h){
window.resizeTo(w,h);
}
</script>
<script >
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("<p>Benvindo <?php ?></p>")
myWindow.focus()
</script>
</head><body bgcolor="#00814B" onload= "javascript:void window.ScreenSize(250,640); ">
<table><tr> <td><img src="imas/sermaillogo.png"></td></tr></table><br/>
<div>
<FORM>
<INPUT type="button" style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"class="mybutton" value=" Ficha de entrada " onClick="window.open('formulario.html')"><br/>
<INPUT type="button" style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"class="mybutton" value=" Ficha de Palete " onClick="window.open('palete.html')"><br/>
<INPUT type="button" style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"class="mybutton" value=" Ordem de espera " onClick="window.open('espera.html')"><br/>
<INPUT type="button" style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"class="mybutton" value=" Pequisar N.º Ordem " onClick="window.open('pesquisar.html')"><br/>
<INPUT type="button" style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"class="mybutton" value=" Pequisar N.º Palete " onClick="window.open('pesquisarpaletes.html')"><br/>
<INPUT type="button" style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"class="mybutton" value=" Pequisar Ordem de espera" onClick="window.open('pesquisacodprod.html')"><br/>
</FORM>
<br/><INPUT style="color:#000; padding: 2px 5px;font-family: arial;font-size: 14px;height: 30px;display: block; width: 200px;"type="button" value="Fechar" onClick="window.close()">
<input type="text" size="10" name="data" value="<?php mysql_connect("localhost", "root")or die("sem conecção ao servidor");
mysql_select_db("sermail")or die("Base de dados não foi encontrada");$username=$_POST['username'];
$result1="SELECT username FROM members where username = '" . mysql_real_escape_string($username) . "'";
$o1=mysql_query($result1)or die(mysql_error());
if ($row = mysql_fetch_array($o1)) {
echo $row['username'];
}
else {
echo 'No record found';
} ?>">
</div>
</body>
</html>
i can't get the $username in my menu.html page, why?
it's possible that i have one or more ginormouse errors in those pages.