Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login Script Using PHP + mySQL fail

Status
Not open for further replies.

nbasar

IS-IT--Management
Aug 16, 2005
3
0
0
MY
hi,

I have created login script using PHP + mySQL and it works on my XP Development PC, but when I migrate it to my SuSe Linux OES server the PHP + MySQL script won't works.

Some one advice me to check on the Apache2 configuration, but i have no idea what to check. I shall paste my script here for you to advice me on what might be wrong.

 
are any other scripts running on that suse-server?

anyways, post your config!

__________________________________________
a programmer is a tool that converts coffee into code...
aschi666, sthcomputing.de
 
hi,

this is the php script

<?
$db="upentrg";
$table="login";

$userid=$_POST['userid'];
$password=$_POST['password'];

if($userid == '' || $password == '')
{
header('Location:login.php?refer='.urlencode($psRefer));
//echo "<script>alert('user n password x masuk');</script>";
}
else
{
$con=mysql_connect("localhost","root","");
mysql_select_db($db,$con);


$q="select id, MD5(UNIX_TIMESTAMP() + id + RAND(UNIX_TIMESTAMP())) GUID from $table where userid ='$userid' AND password='$password'";

$rslt=mysql_query($q,$con);
if(mysql_num_rows($rslt))
{
$prslt=mysql_fetch_row($rslt);

$q="update $table set GUID='$prslt[1]' WHERE id = $prslt[0]";
mysql_query($q,$con);

setcookie("session_id",$prslt[1]);

if(!$psRefer)
{
$psRefer='index1.php';
header('Location:'.$psRefer);
}
}
else
{
header('Location:login.php?refer='.urlencode($psRefer));
//echo "<script>alert('x select database');</script>";
}
}
?>

and

<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script>


function changeScrollbarColor(C){
if (document.all){
document.body.style.scrollbarBaseColor = C
}
}

</script>
<style>
body{
scrollbar-base-color:#F0D9A4
}
</style>
<link rel="stylesheet" href="_notes/tganuwebcss11" type="text/css">
<style type="text/css">
<!--
-->

body {
margin-top:100px;

}
</style>
</head>

<body bgcolor="#FAEDCF">
<form action= "dblogin.php" method="post">
<div align="center">
<table width="545" border="2" bgcolor="#FFFFFF">
<tr bgcolor="#F0D9A4">
<td colspan="2"><div align="center"><font color="#000000" size="4" face="Arial, Helvetica, sans-serif">
<strong>LOGIN</strong></font></div></td>
</tr>
<tr>
<td colspan="2">
<div align="right">
<table width="100%" border="0"bgcolor="#F8E3B8">
<tr>
<td colspan="2">
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="46%">&nbsp;</td>
<td width="54%"></td>
</tr>
<tr>
<td><div align="right"><strong><font size="2" face="Arial, Helvetica, sans-serif">User Name:</font></strong></div></td>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">
<input type="text" name="userid">
</font></strong></td>
</tr>
<tr>
<td><div align="right"><strong><font size="2" face="Arial, Helvetica, sans-serif">Password:</font></strong></div></td>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">
<input type="password" name="password">
</font></strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Login"> <input type="submit" name="reset" value="Batal"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="hidden" name="psRefer" value="<? echo($refer) ?>">
<font size="2" face="Arial, Helvetica, sans-serif"><strong></strong></font></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>

and

<?php
session_start();
// Check for a cookie, if none got to login page
if(!isset($user_name) | !isset($password)) {
header('Location:login.php');
//header('Location:/vo/servlet/portal?render=on');
//.urlencode($PHP_SELF.'?'.$HTTP_SERVER_VARS['QUERY_STRING']));
}

$expirationtime=time()-12000;

// Try to find a match in the database
$GUID = $HTTP_COOKIE_VARS['session_id'];
$hDB = mysql_connect("localhost","root","");
mysql_select_db('upentrg', $hDB);

$sQuery = "Select *From users where user_name='$user_name' and password='$password'";
$hResult = mysql_query($sQuery, $hDB);

if(!mysql_num_rows($hResult)) {
// No match for guid
header('Location:/login.php?refer=');
//header('Location:/vo/servlet/portal?render=on');
//.urlencode($PHP_SELF.'?'.$HTTP_SERVER_VARS['QUERY_STRING']));
//}
?>



I am using MySQl Ver 4.2 with PHP4 and Apache2.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top