A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Question for experts only :: Chatroom in php3

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    122
    Hi guys. Thanks for looking. I really need help. I'm making a chatroom using html and php3. I have 5 files -- 2 html and 3 php3. Here is a list:
    messsages.html -- messagefile (reloads every 2 sec.)
    input.php3 -- Does the basic work of sending the messages to the message file.
    regester.php3 -- Allows you to regester
    index.html -- main page. Has links to two php3 files (regester.php3 and login.php3)

    this is the main problem filelogin.php3 -- Detects if you've regestered and if so allows you to login and enter the chatroom by dynamically allowing you to view the message file on the right and the input.php3 file on the left, by echoing HTML.

    The problem is that there is a variable called username which contains your username. The login.php3 file has that variable, yet the input.php3 file (this is the one that it needs to be in for processing onto the message file) dosen't have it. I can't think of a way that the input.php3 file can get it! Can you? Is it a bit confusing? Mail me then at matt.garmeson@btinternet.com or maybe to clarify it, visit the web page -- http://www.banana-net.co.uk/neochat


  2. #2
    Actkid
    Join Date
    Feb 2001
    Location
    Surat
    Posts
    764

    Post Hi

    when u r giveing the loadvariables action in flash file then use get method instead of post.


    Now tell me its work or not

  3. #3
    Senior Member
    Join Date
    Oct 2000
    Posts
    122
    It dosen't involve flash

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    put that user name into the cookie jar
    Ok, someone registers or logs into the chat room. You give him a cookie that expires when the browser is closed.
    Every request sent to the input.php will be accompanied by the cookie

    Musicman

  5. #5
    Senior Member
    Join Date
    Oct 2000
    Posts
    122
    That won't work, thx anyway, cos everyone is using this file for inputing data to the message file, and If that happens then everyone will have the same username. Know what I mean????

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Oops...

    you have a script login.php when people access your site. This script maintains a file or a database "users", which contains all users and their passes. It is this file that assigns different cookies to different people

    Code:
    <?
    $users = file("users.dat");	// read users file
    if($action == 'login')
    {	$match = 0;
    	for($n = 0 ; $n < count($users) ; $n++)
    	{	list($r_user,$r_pass,$r_email) = explode("\t", $users[$n]);
    		if($user == $r_user && $pass == $r_pass)
    		{	match = 1;
    			break;
    		}
    	}
    	if($match)
    	{	setcookie('user', $user);
    		// send real file or redirect user to it here
    	}
    	else
    	{	// login failed... tell user here
    	}
    }
    else if($action == 'register')
    {	$match = '';
    	for($n = 0 ; $n < count($users) ; $n++)
    	{	list($r_user,$r_pass,$r_email) = explode("\t", $users[$n]);
    		if($user == $r_user)
    		{	$match = 'user';
    			break;
    		}
    		else if($email == $r_email)
    		{	$match = 'email';
    			break;
    		}
    	}
    	if(!$match)
    	{	$fp = fopen("users.dat", "a");
    		fputs($fp, "$user	$pass	$email\n");
    		fclose($fp);
    		setcookie('user', $user);
    		// send real file or redirect user to it here
    	}
    	else
    	{ // either user or email already exist
    	  // tell about here
    	}
    }
    ?>
    The way this is written input should just refuse to work if no user cookie is set
    Also please note this is php4 - I think you have to refer to form variables in a different way in php3

    Musicman

  7. #7
    Senior Member
    Join Date
    Oct 2000
    Posts
    122
    Thanks for that Music man, but just let me ask you this please if you don't mind,
    I'm sending the $username variable from the login.php3 file all the way to the input.html file. When the user presses the subit button, it goes to the input.php3 file which then echoes some HTML to make the user thnk that nothing has really happenned. Th eonly thing is that, for some reasonthe $username data dosen't reach it!!! Honestly it is driving me bananas. Talking of bananas visit my web page -- http://www.banana-net.co.uk -- I did it all at my age 14. What do you think?

  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I tried to view your site but could not find the register function, so I entered the chatroom with my nick, posted some Hello message - and cancelled the connection after the browser had loaded 5 MB of date without showing anything...
    If you want, mail me these php files to musicman@f2s.com, and I will try to find out what goes wrong.
    BTW, would your server run PHP4 as well? and ... how come you sign up a uk domain with a german hosting company?

    Musicman

  9. #9
    Senior Member
    Join Date
    Oct 2000
    Posts
    122
    Thanks MusicMan 4 your cooperation, but I'll just instead put the whole chatroom into flash, that'll sort it out. Check it all out in a week time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center