adt2007 Posted March 22, 2008 Share Posted March 22, 2008 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 Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/ Share on other sites More sharing options...
Kieran Menor Posted March 22, 2008 Share Posted March 22, 2008 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; Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498172 Share on other sites More sharing options...
redarrow Posted March 22, 2008 Share Posted March 22, 2008 But that provided code means anyone get's in hope you no that.... Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498182 Share on other sites More sharing options...
redarrow Posted March 22, 2008 Share Posted March 22, 2008 This is how it works mate <?php $username=""; if(empty($username)){ $username='Guest'.rand(000000,999999).$username; }else{ $username=$username; } echo $username; ?> Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498189 Share on other sites More sharing options...
adt2007 Posted March 22, 2008 Author Share Posted March 22, 2008 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> Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498218 Share on other sites More sharing options...
redarrow Posted March 22, 2008 Share Posted March 22, 2008 <?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> Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498220 Share on other sites More sharing options...
adt2007 Posted March 22, 2008 Author Share Posted March 22, 2008 Ahh i see now! thank you very much! Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498221 Share on other sites More sharing options...
adt2007 Posted March 22, 2008 Author Share Posted March 22, 2008 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? Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498223 Share on other sites More sharing options...
redarrow Posted March 22, 2008 Share Posted March 22, 2008 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> Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498229 Share on other sites More sharing options...
BlueSkyIS Posted March 22, 2008 Share Posted March 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/97357-generating-a-un-registered-user-a-random-guest-number-when-accessing-chat-room/#findComment-498234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.