Reputation: 628
<?php
session_start();
$_SESSION['id']='face';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="check.php" method="post">
Admin: <input type="text" name="uname" value="<?php if(isset($_SESSION['id']) && !empty($_SESSION['id'])) { echo $_SESSION['id']; } ?>" /><br />
Password: <input type="password" name="pword" /><br />
<input type="hidden" name="login" value="1" />
<input type="submit" value="Login" />
</form>
</body>
</html>
I am working in a php language . i have made session[id] in which i have stored the the value ie face . Now in the form , ADMIN textbox , i am checking for the session[id] , if isset or not empty *echo* session[id] but if not isset or empty echo the textbox value instead of this its showing me tha number . please can any one explain me why its showing me the number .......instead of value
Upvotes: 2
Views: 192
Reputation: 143
There is no <input type="textbox"
in html!
Use <input type="text"
or <textarea> </textarea>
(content goes in between)
EDIT: Session ID
If you really want to overwrite the Session ID, use the function session_id(sid). Either way, you can only set the session ID before you start the session, so your code should look like this:
session_id("face");
session_start();
Upvotes: 1
Reputation: 1001
First, correct your html as follows:
<input type="text" name="uname" value="<?php if(isset($_SESSION['id']) && !empty($_SESSION['id'])) { echo $_SESSION['id']; } ?>" />
if you get the same error you need to check your session value before displaying the form. You can use:
var_dump($_SESSION);
to make sure if your session is not overwritten somewhere else.
Upvotes: 2