Jump to content

Help with Login Script???


tuxbuddy

Recommended Posts

 

 

I have written a login script which when user logins is redirected to new page.Here are the codes:

File: login.php

<html><table width="300" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<p>
<body bgcolor="#d0d0d0">
<img src="helpcore.jpg" align="center">
</p>
<br><iframe src="http://free.timeanddate.com/clock/iz28p1x/n438/fc969/tccff/pcff9/ftb/bas2/bat6/bacf00/tt0/td1/tb3" frameborder="1" width="326" height="22"></iframe>
</br><br>
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
<td><br><a href="forget.php"><i>Forgot your password?</i></a><td><a href="register.php">Register</a></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</html>

File : checklogin.php

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password="mysql123"; // Mysql password
$db_name="helpcore"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string ($mypassword);

$sql="SELECT * FROM $tbl_name WHERE loginname='$myusername' and password='$mypassword'";
$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_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
//echo "You need to register to login.Go Back and click on "Register" button.";
}
?>

If the login is successful,then.he is redirected to:

 

File:login_sucess.php

<?
session_start();
if(session_is_registered(myusername)){
#header("location:http://10.14.2.36/HelpCORE/modules_helpcore_public");
echo "<meta http-equiv='refresh' content='0;url=http://10.14.2.36/HelpCORE'>";

}
?>

<html><body>
Login Successful.
</body></html>

Now the new page gets displayed where I want to display like say:

 

Welcome $username

 

And then the other content.How can I carry the variable to this new page.

 

Pls Help

Link to comment
https://forums.phpfreaks.com/topic/101014-help-with-login-script/
Share on other sites

Assuming that you use PHP 4.0.6 or higher, I would recommend to use $_SESSION['your_var_name'] = '...' instead of session_register(). Then use $_SESSION['your_var_name'] to refer to the session variables, like:

 

echo "Welcome ".$_SESSION['your_var_name'];

 

I would also recommend to integrate all login related operations into one script. There should be a number of examples available in the scripts section.

 

Lemme tel yu my problem in details:

File: login.php

 


<html><table width="300" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<p>
<body bgcolor="#d0d0d0">
<img src="helpcore.jpg" align="center">
</p>
<br><iframe src="http://free.timeanddate.com/clock/iz28p1x/n438/fc969/tccff/pcff9/ftb/bas2/bat6/bacf00/tt0/td1/tb3" frameborder="1" width="326" height="22"></iframe>
</br><br>
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
<td><br><a href="forget.php"><i>Forgot your password?</i></a><td><a href="register.php">Register</a></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</html>

File : checklogin.php

Code:

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password="mysql123"; // Mysql password
$db_name="helpcore"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string ($mypassword);

$sql="SELECT * FROM $tbl_name WHERE loginname='$myusername' and password='$mypassword'";
$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_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
//echo "You need to register to login.Go Back and click on "Register" button.";
}
?>

If the login is successful,then.he is redirected to new page index.php through login-success.php:

File:login_sucess.php

Code:

<?
session_start();
if(session_is_registered(myusername)){
#header("location:http://10.14.2.36/HelpCORE/modules_helpcore_public");
echo "<meta http-equiv='refresh' content='0;url=http://10.14.2.36/HelpCORE'>";

}
?>

<html><body>
Login Successful.
</body></html>


Now again I wrote a page which will again redirect back to original Position like this:

 


<?

session_start();

if(session_is_registered(myusername)){

#header("location:http://10.14.2.36/HelpCORE/modules_helpcore_public");

echo "<meta http-equiv='refresh' content='0;url=http://10.14.2.36/petp/askstatus.php'>";



}

?>



<html><body>

Successful.

</body></html>

 

Again I am out of my tool….now I wrote File : askstatus.php

 

 

<?php

Welcome <? $_SESSION[‘myusername’]; ?>



?>



It is not working just displaying Welcome;





Any error???

I tried modifying like this but its not working:

<?
session_start();
#echo "Welcome". $_SESSION['myusername'];
#if(session_is_registered(myusername)){
if(isset($_SESSION['myusername']){
#header("location:http://10.14.2.36/HelpCORE/modules_helpcore_public");
echo "<meta http-equiv='refresh' content='0;url=http://10.14.2.36/HelpCORE'>";

}
?>

<html><body>
Login Successful.

But if (session_is_regsitered(myusename)) is working.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.