FreiChat related discussions
Freichat Custom Install: "Could not authenticate user"

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 ?&gt;


&lt;font face="arial"&gt;

&lt;?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 "&lt;center&gt;&lt;font color="red"&gt;Invalid Login Details. Not Logged In.&lt;/font&gt;&lt;/center&gt;";
echo "&lt;br&gt;";
echo "&lt;center&gt;&lt;font color="red"&gt;Please go back and try again.&lt;/font&gt;&lt;/center&gt;";
echo "&lt;br&gt;";

echo "&lt;center&gt;&lt;a href="login.php"&gt;Back&lt;/a&gt;&lt;/center&gt;";
}


}



?&gt;


&lt;?php // close connection
//mysql_close();
?&gt; ob_flush();//Flush buffer output ?&gt;</code></pre>

Members Area Script:

<pre><code>&lt;?php ob_start; ?&gt;&lt;?php session_start();

if (!(isset($_SESSION['myusername']) & $_SESSION['myusername'] != '')) {

header ("Location: login.php");

}

?&gt;&lt;header&gt;&lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/header&gt;&lt;footer&gt;&lt;!--===========================FreiChat=======START=========================--&gt;&lt;!-- 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 "&lt;script&gt;alert('module freichatx says: hardcode.php file not
found!');";
}

return 0;
}
}
?&gt;
&lt;script type="text/javascript" language="javascipt" src="http://mysite/freichat/client/main.php?id=&lt;?php%20echo%20%24ses;?&gt;&amp;xhash=&lt;?php%20echo%20freichatx_get_hash(%24ses);%20?&gt;"&gt;&lt;/script&gt;&lt;link rel="stylesheet" href="http://mysite/freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css"&gt;&lt;!--===========================FreiChatX=======END=========================--&gt;&lt;/footer&gt;&lt;center&gt;&lt;font face="arial" size="22px" color="purple"&gt;Members' Area!&lt;/font&gt;&lt;/center&gt;

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

Your Members Area Script: code is not correct . Looks like you referred the code from the Documentation in our website .
The Docs for custom installation is not yet updated for the latest version so do not use them .

You should use the code given your Custom installation page itself .

We have edited the code for you :

First of all, the the session variable $_SESSION['myusername'] does not contain the userid of the user according to your Login Action Script:

You can do it this way :

Replace in Login Action Script
<?php session_start();
$_SESSION['myusername'] = "1";

?>

with

<?php //session_start(); why are you starting session again ?
$_SESSION['userid'] = $result2[YOUR_USERID_COLUMN_NAME];

?>

Then , in Members Area Script:

Replace

<?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
}
}

?>


With



<?php if(isset($_SESSION['userid']))
{
$ses = $_SESSION['userid'] //tell freichat the userid of the current user

setcookie("freichat_user", "LOGGED_IN", time()+3600, "/"); // *do not change -> freichat code
}
else {
$ses = null; //tell freichat that the current user is a guest

setcookie("freichat_user", null, time()+3600, "/"); // *do not change -> freichat code
}

?>
Your &amp;lt;em&amp;gt;Members Area Script:&amp;lt;/em&amp;gt; code is not correct . Looks like you referred the code from the Documentation in our website . The Docs for custom installation is not yet updated for the latest version so do not use them . You should use the code given your Custom installation page itself . We have edited the code for you : First of all, the the session variable $_SESSION[&#039;myusername&#039;] does not contain the userid of the user according to your &amp;lt;em&amp;gt;Login Action Script:&amp;lt;/em&amp;gt; You can do it this way : Replace in Login Action Script &amp;lt;?php session_start(); $_SESSION[&#039;myusername&#039;] = &quot;1&quot;; ?&amp;gt; with &amp;lt;?php //session_start(); why are you starting session again ? $_SESSION[&#039;userid&#039;] = $result2[YOUR_USERID_COLUMN_NAME]; ?&amp;gt; Then , in &amp;lt;em&amp;gt;Members Area Script:&amp;lt;/em&amp;gt; Replace &amp;lt;?php $ses=null; if(isset($_SESSION[&#039;myusername&#039;])) { if($_SESSION[&#039;myusername&#039;] != null) // Here null is guest { $ses=$_SESSION[&#039;myusername&#039;]; //LOOK, now userid will be passed to FreiChat } } ?&amp;gt; &amp;lt;h4&amp;gt; With &amp;lt;/h4&amp;gt; &amp;lt;?php if(isset($_SESSION[&#039;userid&#039;])) { $ses = $_SESSION[&#039;userid&#039;] //tell freichat the userid of the current user setcookie(&quot;freichat_user&quot;, &quot;LOGGED_IN&quot;, time()+3600, &quot;/&quot;); // *do not change -&amp;gt; freichat code } else { $ses = null; //tell freichat that the current user is a guest setcookie(&quot;freichat_user&quot;, null, time()+3600, &quot;/&quot;); // *do not change -&amp;gt; freichat code } ?&amp;gt;
Necessity is the mother of all inventions!

Even I'am facing the same problem

if(!isset($_SESSION['SESS_MEMBER_ID']))
{
$ses = $_SESSION['SESS_MEMBER_ID']; //tell freichat the userid of the current user

setcookie("freichat_user", "LOGGED_IN", time()+3600, "/"); // *do not change -> freichat code
}

I have put my code so but it is giving me the error :( Could not authenticate user . Please verify your edited copy-paste code and make any required changes.

Even if i hard code it so

$ses = 1; //tell freichat the userid of the current user

setcookie("freichat_user", "LOGGED_IN", time()+3600, "/"); // *do not change -> freichat code
}
if(!function_exists("freichatx_get_hash")){
function freichatx_get_hash($ses){

if(is_file("/home/priva134/public_html/chat/hardcode.php")){

require "/home/priva134/public_html/chat/hardcode.php";

$temp_id = $ses . $uid;

return md5($temp_id);
.
.
.

}

return 0;
}
}

I still get the same error.

In order to verify that $_SESSION['SESS_MEMBER_ID'] has the member id in it. I printed in my website using echo $_SESSION['SESS_MEMBER_ID'];
It gave the member id i.e. 1 as the output.

I dont know why this is giving me such error.

Even I&#039;am facing the same problem if(!isset($_SESSION[&#039;SESS_MEMBER_ID&#039;])) { $ses = $_SESSION[&#039;SESS_MEMBER_ID&#039;]; //tell freichat the userid of the current user setcookie(&quot;freichat_user&quot;, &quot;LOGGED_IN&quot;, time()+3600, &quot;/&quot;); // *do not change -&amp;gt; freichat code } I have put my code so but it is giving me the error :( Could not authenticate user . Please verify your edited copy-paste code and make any required changes. Even if i hard code it so $ses = 1; //tell freichat the userid of the current user setcookie(&quot;freichat_user&quot;, &quot;LOGGED_IN&quot;, time()+3600, &quot;/&quot;); // *do not change -&amp;gt; freichat code } if(!function_exists(&quot;freichatx_get_hash&quot;)){ function freichatx_get_hash($ses){ if(is_file(&quot;/home/priva134/public_html/chat/hardcode.php&quot;)){ require &quot;/home/priva134/public_html/chat/hardcode.php&quot;; $temp_id = $ses . $uid; return md5($temp_id); . . . } return 0; } } I still get the same error. In order to verify that $_SESSION[&#039;SESS_MEMBER_ID&#039;] has the member id in it. I printed in my website using echo $_SESSION[&#039;SESS_MEMBER_ID&#039;]; It gave the member id i.e. 1 as the output. I dont know why this is giving me such error.

That is pretty strange .

Can you try deleting your browser cookies . If it still does not work , please provide us with the install url , we would like to have a check .

Also please create a new post and if required only post a link to this post for reference , because it creates confusion .

That is pretty strange . Can you try deleting your browser cookies . If it still does not work , please provide us with the install url , we would like to have a check . Also please create a new post and if required only post a link to this post for reference , because it creates confusion .
Necessity is the mother of all inventions!
284
4
0
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft