Jump to content

Database integration help.


nealec

Recommended Posts

I have set up u chat page on my site and would like to know how to make it use the logged in members user name from my database rather than assigning them a guest name, i think i have found the code that needs editing but i have no idea what needs to be done.

 

I think the editing needs to be done in this code somewhere but i could be wrong, Please help.

 

<?php

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname
$params['firstisadmin'] = true;
//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers 
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>phpFreeChat- Sources Index</title>
  <link rel="stylesheet" title="classic" type="text/css" href="style/generic.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/header.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/footer.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/menu.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/content.css" />  
</head>
<body>

<div class="header">
      <img alt="phpFreeChat" src="style/logo.gif" class="logo2" />
</div>

<div class="menu">
      <ul>
        <li class="sub title">General</li>
        <li>
          <ul class="sub">
            <li class="item">
              <a href="demo/">Demos</a>
            </li>
            <?php if (file_exists(dirname(__FILE__)."/checkmd5.php")) { ?>
            <li>
              <a href="checkmd5.php">Check md5</a>
            </li>
            <?php } ?>
            <!--
            <li class="item">
              <a href="admin/">Administration</a>
            </li>
            -->
          </ul>
        </li>
        <li class="sub title">Documentation</li>
        <li>
          <ul>
            <li class="item">
              <a href="http://www.phpfreechat.net/overview">Overview</a>
            </li>
            <li class="item">
              <a href="http://www.phpfreechat.net/quickstart">Quickstart</a>
            </li>
            <li class="item">
              <a href="http://www.phpfreechat.net/parameters">Parameters list</a>
            </li>
            <li class="item">
              <a href="http://www.phpfreechat.net/faq">FAQ</a>
            </li>
            <li class="item">
              <a href="http://www.phpfreechat.net/advanced-configuration">Advanced configuration</a>
            </li>
            <li class="item">
              <a href="http://www.phpfreechat.net/customize">Customize</a>
            </li>
          </ul>
        </li>
      </ul>
      <p class="partner">
        <a href="http://www.phpfreechat.net"><img alt="phpfreechat.net" src="style/logo_88x31.gif" /></a><br/>
      </p>
</div>

<div class="content">
  <?php $chat->printChat(); ?>
  <?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>
    <p style="color:red;font-weight:bold;">Warning: because of "isadmin" parameter, everybody is admin. Please modify this script before using it on production servers !</p>
  <?php } ?>
</div>

<div class="footer">
  <span class="partners">phpFreeChat partners:</span>
  <a href="http://www.jeu-gratuit.net">jeux gratuits</a> |
  <a href="http://jeux-flash.jeu-gratuit.net">jeux flash</a> |
  <a href="http://www.pronofun.com">pronofun</a> |
  <a href="http://areno.jeu-gratuit.net">areno</a> |
  <a href="http://www.micropolia.com">micropolia</a> |
  <a href="http://www.zeitoun.net">zeitoun</a> |
  <a href="http://federation.jeu-gratuit.net">federation</a>
</div>
    
</body></html>

Link to comment
Share on other sites

Im just guessing but i think this is controlling the name of the person using the chat

 

$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname

 

Now to get to the chat page they must have logged in already to my site, i need to edit the code to make it use their username rather than some guest number, can it be done and can you help me pls

 

Link to comment
Share on other sites

when you start a chat and you enter is your nickname guest(somenumber)?

you will need to include your database connection on this page

and then run a select query

If you have already logged in via your login form you should set a session like this

$_SESSION['nickname']=$result['name'];

 

This depends very much on your login script for the correct way to structure it

 

then

 

$params["nick"] =$_SESSION['nickname'];

 

you will also need session_start(); at the top of that page to use session variables

 

 

 

Link to comment
Share on other sites

Ok ive done it i think, but it still somehow gives me a guest name and number.

 

can you tell me if i have done it right.

 

<?php

session_start();

require_once 'database.php';

$_SESSION['nickname']=$result['username'];

?>

<?php

 

require_once dirname(__FILE__)."/src/phpfreechat.class.php";

$params = array();

$params["title"] = "Nealeweb Chat";

$params["nick"] =$_SESSION['nickname'];

$params['firstisadmin'] = false;

//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)

$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat

$params["debug"] = false;

$chat = new phpFreeChat( $params );

 

Link to comment
Share on other sites

hi i tried it but i seem to have destroyed one of my pages, is there any way i could give you access to my files an server and you do it for me pls, i would be very grateful and and give you full credit for all the coding on my pages. i know its not right to ask but im useless at all this and im doing more damage to what has already taken me ages to get done.

Link to comment
Share on other sites

This is the login page for my site

 

<?php
session_start();
require_once 'database.php';
$_SESSION['nickname']=$result['username'];
?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 6</title>
</head>

<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">

<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td width="566">
		<img border="0" src="nealewebpreviews/Design3/headimg.jpg" width="566" height="138"></td>
		<td valign="top"><a href="http://www.nealeweb.com/Index.php">
		<img border="0" src="nealewebpreviews/Design3/login1.jpg" width="116" height="33" align="top"></a><a href="http://www.nealeweb.com/reg.php"><img border="0" src="nealewebpreviews/Design3/reg2.jpg" width="136" height="38"></a><a href="http://www.nealeweb.com/logout.php"><img border="0" src="nealewebpreviews/Design3/logout3.jpg" width="118" height="33" align="top"></a></td>
		<td width="270">
		<img border="0" src="nealewebpreviews/Design3/clockdemo.jpg" width="264" height="138" align="right"></td>
	</tr>
</table>
</div>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#000000">
	<tr>
		<td width="40"> </td>
		<td valign="bottom"><?php if (isset($_SESSION['user'])){?>
<img border="0" src="nealewebpreviews/Design3/welcimg.jpg" width="531" height="222" align="left">
<?php
}

elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>

<br />
<?php

}else{
?>
<form name="login_form" method="post" action="login.php">
  <label>
  <input name="user" type="text" id="user"><font color="#FFFFFF"> Username</font></label><p>
<label>
  <br />
  <input name="pass" type="password" id="pass"><font color="#FFFFFF"> Password</font><br />
   </label></p>
<p>
<input type="image"  name="login" id="login" value="Login" src="nealewebpreviews/Design3/login.png" width="60" height="28">
   </label>
</p>
</p>
<br />
<?php
}
?></td>
		<td width="551">
		<img border="0" src="nealewebpreviews/Design3/midbarimgr.jpg" width="551" height="223" align="right"></td>
	</tr>
</table>
</div>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td background="nealewebpreviews/Design3/mbarbg.jpg" width="1283">
		<img border="0" src="nealewebpreviews/Design3/mbar.jpg" width="900" height="45"></td>
		<td background="nealewebpreviews/Design3/mbarbg.jpg">
		<img border="0" src="nealewebpreviews/Design3/Collapse.jpg" width="52" height="45"></td>
	</tr>
</table>
</div>

</body>

</html>

 

And this is the page with the chat:

 

<?php
session_start();
require_once 'database.php';
$_SESSION['nickname']=$result['username'];
?>
<?php

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Nealeweb Chat";
$params["nick"] =$_SESSION['nickname'];
$params['firstisadmin'] = true;
//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers 
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>phpFreeChat- Sources Index</title>
  <link rel="stylesheet" title="classic" type="text/css" href="style/generic.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/header.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/footer.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/menu.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/content.css" />  
</head>
<body>

<div class="menu">
      <p class="partner">
        <br/>
      </p>
</div>

<div class="content">
  <?php $chat->printChat(); ?>
  <?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>
    <p style="color:red;font-weight:bold;">Warning: because of "isadmin" parameter, everybody is admin. Please modify this script before using it on production servers !</p>
  <?php } ?>
</div>

<div class="footer">
  <font color="#FFFFFF">
  <span class="partners">phpFreeChat partners:</span>
  </font><font color="#FFFFFF">jeux gratuits |
  </font><font color="#FFFFFF">jeux flash |
  </font><font color="#FFFFFF">pronofun</font><font color="#FFFFFF"> |
  </font><font color="#FFFFFF">areno</font><font color="#FFFFFF"> |
  </font><font color="#FFFFFF">micropolia</font><font color="#FFFFFF"> |
  </font><font color="#FFFFFF">zeitoun</font><font color="#FFFFFF"> |
  </font>
  <a href="http://federation.jeu-gratuit.net"><font color="#FFFFFF">federation</font></a>
</div>
    
</body></html>

Link to comment
Share on other sites

This is the whole database.php file minus my password, username and database name

 

<?

$con = mysql_connect('localhost','Username','Password');

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db('Database name');

?>

Link to comment
Share on other sites

Like this?

 

<?php

session_start();

require_once 'database.php';

?>

<?php

 

require_once dirname(__FILE__)."/src/phpfreechat.class.php";

$params = array();

$params["title"] = "Nealeweb Chat";

$params["nick"] =$_SESSION['user'];

$params['firstisadmin'] = true;

//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)

$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat

$params["debug"] = false;

$chat = new phpFreeChat( $params );

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>

<head>

  <meta http-equiv="content-type" content="text/html; charset=utf-8" />

  <title>phpFreeChat- Sources Index</title>

  <link rel="stylesheet" title="classic" type="text/css" href="style/generic.css" />

  <link rel="stylesheet" title="classic" type="text/css" href="style/header.css" />

  <link rel="stylesheet" title="classic" type="text/css" href="style/footer.css" />

  <link rel="stylesheet" title="classic" type="text/css" href="style/menu.css" />

  <link rel="stylesheet" title="classic" type="text/css" href="style/content.css" /> 

</head>

<body>

 

<div class="menu">

      <p class="partner">

        <br/>

      </p>

</div>

 

<div class="content">

  <?php $chat->printChat(); ?>

  <?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>

    <p style="color:red;font-weight:bold;">Warning: because of "isadmin" parameter, everybody is admin. Please modify this script before using it on production servers !</p>

  <?php } ?>

</div>

 

<div class="footer">

  <font color="#FFFFFF">

  <span class="partners">phpFreeChat partners:</span>

  </font><font color="#FFFFFF">jeux gratuits |

  </font><font color="#FFFFFF">jeux flash |

  </font><font color="#FFFFFF">pronofun</font><font color="#FFFFFF"> |

  </font><font color="#FFFFFF">areno</font><font color="#FFFFFF"> |

  </font><font color="#FFFFFF">micropolia</font><font color="#FFFFFF"> |

  </font><font color="#FFFFFF">zeitoun</font><font color="#FFFFFF"> |

  </font>

  <a href="http://federation.jeu-gratuit.net"><font color="#FFFFFF">federation</font></a>

</div>

   

</body></html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.