Multiplayer game using PHP and mysql

In summary, the conversation discusses the design of a map game using PHP and MYSQL. The main concern is how to allow players who sign-in to the website to see and chat with other players who are also connected to the site. The options discussed include using a database to store messages and using AJAX or other technologies such as Java applets or flash movies to retrieve and display these messages. A suggestion is made to start by creating a MySQL database and a PHP script to handle retrieving and displaying messages.
  • #1
fosh
2
0
I am designing a map game, using PHP and MYSQL. I don't know how to make the players who sign-in to the website to see other players who are also connected to the site and be able to chat with one another.

I want to design the game in such a way that 2 players can play with each other and be able to send messages during the game while others groups are playing at the same time.

I have designed the map game successfully, but the problem is making the player 1 who log-in to site to see the player 2 who will also log-in and both can get connected to play each other.

I will appreciate your responses.
 
Technology news on Phys.org
  • #2
You have many options. For example, for the chat feature you can store all messages in a database. On the client side you would then make AJAX requests every X seconds to a PHP script which checks the database for new, unread messages and returns them, if any.
You might be able to just store the messages in the application's memory space, rather than in a Database, using Application Scope variables or Session variables.
If you go with the AJAX option i recommend a "Reverse Ajax" approach to avoid lots of unnecessary traffic.

Besides a PHP/Ajax implementation you also have the option of using a Java applet or a flash movie. With either of these two you are able to use socket connections. You would make a socket connection to your PHP script (or possibly your own custom server) to obtain the unread messages

You are also able to use Javascript with IFrames instead of AJAX as well.
 
  • #3
Job thanks for the response,
please can you help with a sample code just for illustration.
 
  • #4
Sorry but i really don't have the time to write sample code for a 3 layer app.
Why don't you start by creating a MySQL database with a table for storing messages (i.e. the table will need fields for Message Body, Sender, Receiver, DateSent, HasBeenRead, etc).

Then create a PHP script which captures variables (from the QUERYSTRING or FORM collection). You'll use these variables to tell the PHP script what to do.
i.e. myscript.php?action=getUnreadMessages&user=fosh
Which would retrieve the unread messages for user fosh. The PHP script would connect to the database and do a select of all rows in the Messages table which have been sent to user Fosh and which have not yet been read.

Once you have that set up i can help you more closely with the (forward) AJAX portion. You'll use javascript's setTimeout to perform Ajax requests every x seconds to myscript.php with the necessary querystring variables.

The php script will return the messages, which are returned from the Ajax request and finally displayed to the user with Javascript.
 

1. What is a multiplayer game using PHP and MySQL?

A multiplayer game using PHP and MySQL is a type of online game that allows multiple users to play together in real-time. PHP is used as the programming language for the game's logic and interactions, while MySQL is used as the database to store game data and player information.

2. How does PHP and MySQL work together in a multiplayer game?

PHP and MySQL work together in a multiplayer game by using PHP to handle the game's logic and interactions, such as player movements and game events. MySQL is used to store and retrieve game data and player information, such as player scores and inventory.

3. What are the advantages of using PHP and MySQL in a multiplayer game?

Some advantages of using PHP and MySQL in a multiplayer game include: the ability to handle large amounts of data and multiple user interactions, the flexibility to create complex game mechanics, and the availability of resources and support for these technologies.

4. Are there any limitations to using PHP and MySQL in a multiplayer game?

One limitation of using PHP and MySQL in a multiplayer game is the need for a stable internet connection. If the connection is lost, it can disrupt the game and cause data to be lost. Additionally, PHP and MySQL may not be the best choice for creating highly complex and graphics-heavy games.

5. What are some popular multiplayer games that use PHP and MySQL?

Some popular multiplayer games that use PHP and MySQL include Runescape, Habbo Hotel, and Travian. These games vary in their complexity and mechanics, but all utilize PHP and MySQL to create a seamless multiplayer experience.

Similar threads

Replies
13
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
  • Quantum Interpretations and Foundations
Replies
2
Views
766
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
391
  • Programming and Computer Science
Replies
1
Views
4K
Replies
12
Views
905
  • Programming and Computer Science
Replies
33
Views
6K
Replies
9
Views
2K
  • General Math
6
Replies
195
Views
19K
  • Programming and Computer Science
Replies
7
Views
456
Back
Top