Hello every1,
i'm building a site that requires logging in before accessing other pages(like facebook or any mail system).
At first(in index) i create an object of my sessions class, say $session. The constructor of sessions class calls session_start() php function.
$session checks if user logged in or not(maybe he was remembered in cookies) and if not, $session directs him to login page. So, how can I use $session object(which is constructed in index page)in login page???

Thnx

Member Avatar for diafol

sessions allow you to pass objects in addition to variables. Just include the class in all the relevant pages. If you have methods in your class, they need to be available for the object.

*Need more info*

Yes, but $session object itself object that handles sessions, how can i pass it through session?

Member Avatar for diafol


session_start();

i have some issue on logincheck page....
when i use md5 for my password its not working...
its always go to login failed page
pls help me ....


code
-------


<?php
session_start();
$host="192.168.200.100";
$username="emt_dev";
$password="ready2go#";
$db_name="emtd101";
$tbl_name="M_USER";


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$myusername=$_POST;
$mypassword=$_POST;


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$encrypted_mypassword=$mypassword;

$sql="SELECT * FROM $tbl_name WHERE MUSE_NAME='$myusername' and MUSE_PWD='$encrypted_mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);


if($count==1)
{

session_register("txtusername");
session_register("txtpassword");
header("location:Main_Dashboard.php");
}
else

header("location:loginfailed.php")

?>

When you register a new user, you save the password in db with md5($password), right?
Here I don't see where you use md5() before comparing two passwords...

maybe

$encrypted_mypassword=md5($mypassword);

i save a new user in db with md5 password.
here i use the md5() just before the query


$encrypted_mypassword=$mypassword;// this is md5 which i use to encrypt

$sql="SELECT * FROM $tbl_name WHERE MUSE_NAME='$myusername' and MUSE_PWD='$encrypted_mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

sorry man

his was the code


<?php
session_start();
$host="192.168.200.100";
$username="emt_dev";
$password="ready2go#";
$db_name="emtd101";
$tbl_name="M_USER";


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$myusername=$_POST;
$mypassword=$_POST;


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$encrypted_mypassword=md5($mypassword);

$sql="SELECT * FROM $tbl_name WHERE MUSE_NAME='$myusername' and MUSE_PWD='$encrypted_mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);


if($count==1)
{

session_register("txtusername");
session_register("txtpassword");
header("location:Main_Dashboard.php");
}
else

header("location:loginfailed.php")

?>

the last one was my code and its not yet working...

hello every1,
i'm building a site that requires logging in before accessing other pages(like facebook or any mail system).
At first(in index) i create an object of my sessions class, say $session. The constructor of sessions class calls session_start() php function.
$session checks if user logged in or not(maybe he was remembered in cookies) and if not, $session directs him to login page. So, how can i use $session object(which is constructed in index page)in login page???

Thnx

checkout my if statment thread soloved then send me a message for mor files like logout member pages

Member Avatar for diafol

How the hell did this thread get hijacked??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.