hi ..
i am working on chat system ..there are two types of user one are register and other are guest and i have to add guest user..in to database as temporary so they can chat with each other the problem i am facing is with there names i want name like this (Guest1,Guest2,Guest3,Guest4,...so on..)..i am trying but it is not working on live server .. i have tested it on my local server using xampp server.. it worked but not on live server...

here is the code which i am using

if(isset($_SESSION['Guest']))
	{
		$_SESSION['Guest']=$_SESSION['Guest']+1;
	}
	else
	{
		$_SESSION['Guest']=1;
	}

and one more thing how i can delete Guest users who are not online..

and one more thing how i can delete Guest users who are not online..

You should use cookies that expire after a certain time limit is reached. For example, everytime a user updates something in the chat, update the time on the cookie. If the user attempts to update something and a certain time limit has been reached (subtract the last updated time from the current time to get the elapsed time), make the user re-login.

Edit: whoops, forgot you were doing this for guests. You'd have to run a process that updates the database every minute or everytime someone accesses the page. Either way, the idea is the same. Check the last time each guest accessed the page, update the db.

Instead of relying on a guest's cookies to determine a guest's name (whether it be Guest1 or Guest34582), I would turn to PHP when the guest enters the room.
Each time a guest navigates to a room I would add them to your users table, assign them a unique ID and session key for authentication, making sure to flag their account as a guest not a registered user. The flagging can be done with a MySQL ENUM or a simple short int (for example: 0 for guest, 1 for user). To determine a guest's username, simply query MySQL for the last user flagged as a guest. If there is one, the guest's username should be set to "Guest1". Otherwise, all you need is a simple str_replace() to isolate the last guest number. From there, you can then easily calculate the new guest's name and add it to the database.
Along with this, you might want to check for a guest user's inactivity. Have a Cron job purge all the guest accounts that haven't posted a message in a set amount of time.
Let me know if you would like some sample PHP for any of this.
Best of Luck,
PhpMyCoder

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.