Jump to content

generating a un-registered user a random guest number when accessing chat room


adt2007

Recommended Posts

hi there

 

my social community is begging that i enable guests to login to the chat room. i want to do it but im not entirely sure how, this is how it works:

 

when my REGISTERED user access chat the jscript parameter loads their username:

 

<APPLET NAME="DigiChat"

CODEBASE="http://www.yourserver.com/DigiChat/DigiClasses/"

CODE="com.diginet.digichat.client.DigiChatApplet"

WIDTH="200" HEIGHT="100" ALIGN="MIDDLE"

ARCHIVE="CLIENT.JAR"

<PARAM NAME="siteID" VALUE="1000">

<PARAM NAME="cabbase" VALUE="Client.cab">

<PARAM NAME="background" VALUE="FFFFFF">

<PARAM NAME="textcolor" VALUE="000000">

<PARAM NAME="nickname" VALUE="$user->user_info.user_username">

<APPLET>

 

"$user->user_info.user_username" obviously places the user's username in and it automatically connects...

 

but i want to allow guests, so i need something that literally "if "$user->user_info.user_username" doesnt exist, create guestname" in the param field.

 

and guest names would be "Guest" with random numbers after it such as Guest7957, Guest8377, Guest9255... any ideas?

 

cheers

andy

What value does $user->user_info.user_username have when it doesn't "exist"?

 

Assuming "not existing" means empty, one could do something like this:

 

$nickname = empty($user->user_info.user_username) ? "Guest".mt_rand(1000, 9999) : $user->user_info.user_username;

This is how it works mate

 


<?php

$username="";

if(empty($username)){

$username='Guest'.rand(000000,999999).$username;
}else{

$username=$username;
}

echo $username;

?>

 

how is that going to go into my applet though?

 

<APPLET NAME="DigiChat"

CODEBASE="http://www.yourserver.com/DigiChat/DigiClasses/"

CODE="com.diginet.digichat.client.DigiChatApplet"

WIDTH="200" HEIGHT="100" ALIGN="MIDDLE"

ARCHIVE="CLIENT.JAR"

<PARAM NAME="siteID" VALUE="1000">

<PARAM NAME="cabbase" VALUE="Client.cab">

<PARAM NAME="background" VALUE="FFFFFF">

<PARAM NAME="textcolor" VALUE="000000">

<PARAM NAME="nickname" VALUE="$user->user_info.user_username">

<APPLET>

<?php
$username=$user->user_info.user_username;
if(empty($username)){
$username='Guest'.rand(000000,999999).$username;
}else{
$username=$username;
}
?>
<APPLET NAME="DigiChat"
CODEBASE="http://www.yourserver.com/DigiChat/DigiClasses/"
CODE="com.diginet.digichat.client.DigiChatApplet"
WIDTH="200" HEIGHT="100" ALIGN="MIDDLE"
ARCHIVE="CLIENT.JAR"
<PARAM NAME="siteID" VALUE="1000">
<PARAM NAME="cabbase" VALUE="Client.cab">
<PARAM NAME="background" VALUE="FFFFFF">
<PARAM NAME="textcolor" VALUE="000000">
<PARAM NAME="nickname" VALUE="<?php echo $username;?>">
<APPLET>

session example

 

<?php session_start();
$_SESSION['username']=$user->user_info.user_username;
if(empty($_SESSION['username'])){
$_SESSION['username']='Guest'.rand(000000,999999).$_SESSION['username'];
}else{
$_SESSION['username']=$_SESSION['username'];
}
?>


<APPLET NAME="DigiChat"
CODEBASE="http://www.yourserver.com/DigiChat/DigiClasses/"
CODE="com.diginet.digichat.client.DigiChatApplet"
WIDTH="200" HEIGHT="100" ALIGN="MIDDLE"
ARCHIVE="CLIENT.JAR"
<PARAM NAME="siteID" VALUE="1000">
<PARAM NAME="cabbase" VALUE="Client.cab">
<PARAM NAME="background" VALUE="FFFFFF">
<PARAM NAME="textcolor" VALUE="000000">
<PARAM NAME="nickname" VALUE="<?php session_start(); echo $_SESSION['username'];?>">
<APPLET>

ive just realised, my applet code isnt in the page source, its actually in a .js file that is loaded <script> onto the page. will it still work?

 

not unless your server parses .js files as PHP (highly unlikely). you'll need to copy/paste the contents of the .js file into the PHP file to use PHP.

Archived

This topic is now archived and is closed to further replies.

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