PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have problem with session , anyone can help me to fixed it .
Am working package called Xampp for Windows Version 1.4.16 .
everything is good till i face this problem with session . When am trying to log in from admincp.php to student_list.php it redirect to same page admincp.php . I'm wrote code when that happen means user wrote user name and password wrong .
If someone have solve or face problem like this till me can do . Because that very important me to know , i don't want to get like that again .
Maybe problem with my php.ini or any setting of php . Ask me I'll check and tell what the value i have . Here my to page admincp.php and student_list.php
Please have a look at viewtopic.php?t=61184 it is a very similar script.. And we've annotated it with possible things the developer should be aware of...
(Your problem is probably solved by calling session_write_close before you call header ('Location'...)
session_register() is deprecated, never mix it with $_SESSION.
mysql_real_escape_string is important, please read the wikipedia article about sql injections.
ob_start();
session_start();
if(isset($_POST['submit']))
{
require 'includes/config.php';
$name = mysql_real_escape_string($_POST['user']);
$pws = mysql_real_escape_string($_POST['pws']);
$sql ="SELECT * FROM tbl_student WHERE name ='".$name."'and pws='".$pws."'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 1)
{
$_SESSION['sessref'] = $_POST['user'];
session_write_close();
header("Location: student_list.php"); // should be a absolute uri like http://xy.z/student_list.php
exit();
}
else
{
$_SESSION = array();
session_destroy();
header("Location: admincp.php"); // should be a absolute uri like http://xy.z/admincp.php
exit();
}
}
ob_end_flush();
and why we assign array to the session it already array , i have one idea any super variables is array , but here we assign array to it why what is the reason?
and when i need to print that value from session how can i do that ?
when i wanna this session is available or no its ok like this
But $_SESSION doesn't care about those characters that are escaped by mysql_real_escape_string. I believe it clouds the view for real problems when data is encoded, escaped or otherwise needlessly transformed at the "wrong" places without good reason.
thanx for everything god bless you . am still need this answer how can i print that value i assign to session ? i mean syntax to print user value . that all what i need .
thanx again
and when i need to print that value from session how can i do that ?