Jump to content

How to increment username in php/mysql


waqas87

Recommended Posts

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

Link to comment
Share on other sites

I think you mis-understand how sessions work. Every new visitor to this script has the session variable $_SESSION['Guest'] set to 1 and $_SESSION['Guest'] is only incremented when the script is executed by someone who has already visited the page

 

<?php
session_start();
if(isset($_SESSION['Guest']))
{
  //This code is only executed by the already visited guest
  $_SESSION['Guest']=$_SESSION['Guest']+1;
  echo "\$_SESSION['Guest'] now equals: " . $_SESSION['Guest'];
}
else
{
  //every new visitor gets the $_SESSION['Guest'] = 1
  $_SESSION['Guest']=1;
} 
?>

 

It would be better to keep track of the number of guests using a database...

 

8)

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.