Search
Left Quote    I have not failed. I've just found 10,000 ways that won't work.
- Thomas Alva Edison    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Need some help building a chat in PHP
  This user is offline  earth4x
  Subject: "Need some help building a chat in P..." Posted: @ 3:05 am on Feb 22 2007   
Member #: 283
Rank: User - (5)
Since: 02/22/07
Posts: 5

I'm trying to build a small chat in PHP, but i'm having some slight problems and need some help.

first off, I want to use emoticons, and I want to use the str replace code to make it work, but it doesn't...

$smile = str_replace(&qu ot;" , '<img src="c001. gif">', "$msg" ;

$msg being the $_POST of a text field (I use a txt file with fwrite to build the chat)


can anyone tell me what i'm doing wrong ?


also, I want to be able to see how many users are connected to the page, without using MySQL. Can anyone guide me on how I can do this? I already have each user login and it creates a $_SESSION['user name'] so i'm guessing I can make it work.. but I don't know how


thanks!


    Viewed: 12,050 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: Need some help building a chat ..." Posted: @ 10:05 am on Feb 22 2007    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

We'll need more than that to see the problem. What are you saving it as to the text file, try using $msg = str_replace... for the smile code




woohoo!

    Viewed: 12,038 Times | Reply to This | To top
  This user is offline  earth4x
  Subject: "re: Need some help building a chat ..." Posted: @ 5:12 pm on Feb 22 2007    
Member #: 283
Rank: User - (5)
Since: 02/22/07
Posts: 5

  ki said...

< i> We'll need more than that to see the problem. What are you saving it as to the text file, try using $msg = str_replace... for the smile code


Code:

<?
session_start() ;
$user = $_SESSION['use rname'];
$msg = "";
if (isset($_POST[ 'sendMsg'])){
$msg=$_POST[' message'];
$nomFic=" ;messages.txt& quot;;
$fic = fopen($nomFic, "a";
$txt = fwrite($fic,&q uot;<b>$u ser dit :</b> $msg<br> ";
fclose($fic);
}

$smile = array(":P "," " ;
$text = str_replace($sm ile, '<img src="c001 .gif"> ', "$msg&qu ot;
?>




Edited at 05:51:30 pm on 02/22/07


    Viewed: 12,029 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Need some help building a chat ..." Posted: @ 5:51 pm on Feb 22 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Why not use mySQL? That is going to be your best method.


I may have some coding to fix on disabling smilies on the edit page. Testing now :) :D 8-)




-bs0d | AllSyntax.com

    Viewed: 12,020 Times | Reply to This | To top
  This user is offline  earth4x
  Subject: "re: Need some help building a chat ..." Posted: @ 8:03 pm on Feb 22 2007    
Member #: 283
Rank: User - (5)
Since: 02/22/07
Posts: 5

I don't have access to a MySQL database on the server I will be uploading the website to. That's why




    Viewed: 12,015 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: Need some help building a chat ..." Posted: @ 10:05 pm on Feb 22 2007    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

okay try posting the smiles before you write the file




woohoo!

    Viewed: 12,010 Times | Reply to This | To top
  This user is offline  earth4x
  Subject: "re: Need some help building a chat ..." Posted: @ 10:18 pm on Feb 22 2007    
Member #: 283
Rank: User - (5)
Since: 02/22/07
Posts: 5

  ki said...

< i> okay try posting the smiles before you write the file

hey thanks alot!! that worked!!!




    Viewed: 12,007 Times | Reply to This | To top
  This user is offline  earth4x
  Subject: "re: Need some help building a chat ..." Posted: @ 9:09 pm on Feb 25 2007    
Member #: 283
Rank: User - (5)
Since: 02/22/07
Posts: 5

I still can't find a way to make the users work without a mysql database...

as of right now, I can display the users.. but everytime the page refreshes, they reappear!!!

if (isset($user)){ // user is $_SESSION['use rname']
$fileN=" users.php" ;;
$file = fopen($fileN,& quot;a";
$txt = fwrite($file,& quot;$user<b r>";
fclose($file);
}

what i'm trying to do is take each user, put them in an array, and after that, make a foreach so each user get displayed. I also want to remove a user from the list when he hasn't typed anything for the past 5 minutes.. but i'm stuck!!!

Any help would be appreciated!




    Viewed: 11,933 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank