I am trying to install freichat custom version for a php website i developed myself. I have a login page, a login action script, and then a members' area page. I have stated the url of the installation as the members' area page (mysite/members.php).
Where I ran into issues is the User Authentication guide. After following the necessary steps, and when I click the "click me once you have logged in to your website" button, I get the following error:
":( Could not authenticate user . Please verify your edited copy-paste code and make any required changes"
What am I doing wrong? Please help. Below are the codes I used:
Login Script:
<title>Mysite: Login</title><center>
<font face="arial">
Login to Mysite:</font></center>
<form name="login" action method="post">
Username:<br><input type="text" size="25" name="myusername"><br>
Password:<br><input type="password" size="25" name="mypassword"><br>
Enter Image Text:<br><input name="captcha" type="text"><img src="captcha.php"><br><input type="submit" value="Login"><br><a href="forgot.htm"><font size="2">Forgot Login details?</font></a>
<br><a href="index.php">Index</a>
Login Action Script:
<pre><code>ob_start();//Start buffer output ?>
<font face="arial">
<?php session_start();
if(isset($_POST["captcha"])&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
{
// echo "<font color='green'>Correct Code Entered</font>";
//Do my stuff
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="dbname"; // Database name
$tbl_name="tblname"; // Table name
$tbl_name2="tblname2"; // Table name 2
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$myusername=mysql_real_escape_string($_POST['myusername']);
$mypassword=mysql_real_escape_string($_POST['mypassword']);
// Validate the login
$sql2="SELECT * FROM $tbl_name2 WHERE username='$myusername' and password='$mypassword'";
$result2=mysql_query($sql2);
$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
session_start();
$_SESSION['myusername'] = "1";
header ("Location: members.php");
}
else {
echo "<center><font color="red">Invalid Login Details. Not Logged In.</font></center>";
echo "<br>";
echo "<center><font color="red">Please go back and try again.</font></center>";
echo "<br>";
echo "<center><a href="login.php">Back</a></center>";
}
}
?>
<?php // close connection
//mysql_close();
?> ob_flush();//Flush buffer output ?></code></pre>
Members Area Script:
<pre><code><?php ob_start; ?><?php session_start();
if (!(isset($_SESSION['myusername']) & $_SESSION['myusername'] != '')) {
header ("Location: login.php");
}
?><header><a href="logout.php">Logout</a></header><footer><!--===========================FreiChat=======START=========================--><!-- For uninstalling ME , first remove/comment all FreiChat related code i.e below code
Then remove FreiChat tables frei_session & frei_chat if necessary
The best/recommended way is using the module for installation --><?php $ses=null;
if(isset($_SESSION['myusername']))
{
if($_SESSION['myusername'] != null) // Here null is guest
{
$ses=$_SESSION['myusername']; //LOOK, now userid will be passed to FreiChat
}
}
if(!function_exists("freichatx_get_hash"))
{
function freichatx_get_hash($ses){
if(is_file("/home/user/public_html/freichat/hardcode.php")){
require "/home/user/public_html/freichat/hardcode.php";
$temp_id = $ses . $uid;
return md5($temp_id);
}
else
{
echo "<script>alert('module freichatx says: hardcode.php file not
found!');";
}
return 0;
}
}
?>
<script type="text/javascript" language="javascipt" src="http://mysite/freichat/client/main.php?id=<?php%20echo%20%24ses;?>&xhash=<?php%20echo%20freichatx_get_hash(%24ses);%20?>"></script><link rel="stylesheet" href="http://mysite/freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css"><!--===========================FreiChatX=======END=========================--></footer><center><font face="arial" size="22px" color="purple">Members' Area!</font></center>
<?php ob_flush; ?></code></pre>
</form>