Page 1 of 1

Insert username and open applet in new page

Posted: Sat Jan 21, 2006 2:45 pm
by spaceman33
Hi gang.

Been a while since I've been on here, but would appreciate a little help.

I am trying to install a Java applet onto a web page, PjIRC, and there's two things that I could do with help, if possible.

I will post the code I will be using before I amend it later, but what I'm trying to do is:

When the user clicks on the link to open the Java applet, it will take the username that they are logged into the board as. I think the variable from the board I am wanting to use is {L_USERNAME}, but I'm just guessing due to my lack of knowledge with PHP. Maybe if the user is anon, not allow access unless they are logged in.

Secondly, if it isn't already going to happen (not got this far yet), but when the person clicks on the link from a frame on the main page, it will open the Java applet in a new window.

Any help/guidance would be much appreciated.

Here is the code in all its glory, it will be amended a little bit more, but don't really want to go into it until I can get the above 2 sorted out.

PS. at the moment it asks for a username and password if applicable, but I will be getting rid of the textboxes and just assigning the logged in username to the username variable in the code, and the password is not applicable.

I will probably want to do something like, instead of

Code: Select all

if ( $nick == $null ) $nick = "Anon";
do....

Code: Select all

$nick=L_USERNAME
or something.
Cheers...

Code: Select all

<?php 

/************************************************************************/ 
/* PHP: PHP Login Page                                                  */ 
/* ===================                                                  */ 
/*  The following ensures that user input is collected whether POST,    */ 
/*  or GET is used.                                                     */ 
/*  Thema.  (thema@adnd.com)                                            */ 
/************************************************************************/ 
if ( isset($HTTP_GET_VARS['nick']) || isset($HTTP_POST_VARS['nick']) ) 
{ 
        $nick = ( isset($HTTP_GET_VARS['nick']) ) ? 
                $HTTP_GET_VARS['nick'] : $HTTP_POST_VARS['nick']; 
} 
if ( isset($HTTP_GET_VARS['chan']) || isset($HTTP_POST_VARS['chan']) ) 
{ 
        $chan = ( isset($HTTP_GET_VARS['chan']) ) ? 
                $HTTP_GET_VARS['chan'] : $HTTP_POST_VARS['chan']; 
} 
if ( isset($HTTP_GET_VARS['pass']) || isset($HTTP_POST_VARS['pass']) ) 
{ 
        $pass = ( isset($HTTP_GET_VARS['pass']) ) ? 
                $HTTP_GET_VARS['pass'] : $HTTP_POST_VARS['pass']; 
} 

if ( isset($HTTP_GET_VARS['bkgrnd']) || isset($HTTP_POST_VARS['bkgrnd']) ) 
{ 
        $bkgrnd = ( isset($HTTP_GET_VARS['bkgrnd']) ) ? 
                $HTTP_GET_VARS['bkgrnd'] : $HTTP_POST_VARS['bkgrnd']; 
} 
if ( isset($HTTP_GET_VARS['timestamp']) || isset($HTTP_POST_VARS['timestamp']) ) 
{ 
        $timestamp = ( isset($HTTP_GET_VARS['timestamp']) ) ? 
                $HTTP_GET_VARS['timestamp'] : $HTTP_POST_VARS['timestamp']; 
} 

if ( $chan == $null ) $chan = "TestRoom" ; 
if ( $nick == $null ) $nick = "Anon"; 
if ( $pass == $null ) 
{ 
   get_userpass ($nick, $chan); 
} 
else 
{ 
   chat_room($nick, $chan, $pass, $bkgrnd, $timestamp); 
} 

function get_userpass($nick, $chan) 
{ 

echo " 
      <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 
      'http://www.w3.org/TR/html4/loose.dtd'> 
   <html> 
   <head> 
   <title>Chat page</title> 
   </head> 

   <body> 
   <table align='center'> 
      <tr> 
      <td align=center >                               
        <form name='jform' id='jform' action='".$_SERVER['  PHP_SELF']."'target='_self'> 
         <table width='633' border='0' cellspacing='0'> 
           <tr> 
            <td valign='center' width='629' colspan='2' align='center'> 
                  <h2>Welcome to the <a href='http://www.pjirc.com'>PJirc</a> applet.</h2> 
       <p align='center'> 
       If you have a password type it into the box. Otherwise do not change it.<font colour=blue><br> 
               </font> 
            </td> 
           </tr> 
              <tr> 
            <td align='center'> 
               <font colour=blue> 
                    Type your Nick</font> 
            </td> 
              </tr> 
              <tr> 
            <td align='center'> 
               <font colour=blue> 
               <input name='nick' type=textbox value=$nick> 
               </font> 
            </td> 
              </tr> 
              <tr> 
            <td valign='center' width='629' colspan='2' align='center'> 
               add timestamp to posts <input type='checkbox' name='timestamp' value='off'> 
                  <br> 
            </td> 
              </tr> 
              <tr> 
            <td align='center'> 
               <font colour=blue> 
                    Type your Password</font> 
            </td> 
              </tr> 
              <tr> 
            <td align='center'> 
                    <font colour=blue><input name='pass' type=textbox value='N/A'> 
                    </font> 
            </td> 
              </tr> 
              <tr> 
            <td valign='center' width='629' colspan='2' align='center'> 
       If the fields are correct please just hit <font colour=blue> 
       <br> 
       <input name='submit' type=submit value='Let`s Chat'></font> 
            </td> 
              </tr> 
           </table> 
        </form> 
      </td> 
     </tr> 
   </table> 
   </body> 
   </html> 
  \n"; 

} 


function chat_room($nick, $chan, $pass, $bkgrnd, $timestamp) 
{ 
   if ($pass == 'N/A') $pass=''; 
   if ($bkgrnd=="" || $bkgrnd==null || $bkgrnd=="N/A") $img='false'; else $img='true'; 

echo " 
   <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 
      'http://www.w3.org/TR/html4/loose.dtd'> 
   <html> 
   <head> 
   <title>Chat page</title> 
   </head> 

   <body> 
      <applet alt='Loading PJirc applet please be patient' codebase='./' name='jchat' code=IRCApplet.class archive='irc.jar, pixx.jar' width=700 height=500 align='left'> 
         <param name='CABINETS' value='irc.cab,securedirc.cab,pixx.cab'> 
         <param name='nick' value='".$nick."'> 
         <param name='alternatenick' value='".$nick."???'> 
         <param name='name' value='A PJirc user'> 
         <param name='host' value='irc.gamesurge.net'> 
         <param name='alternateserver1' value='irc.eu.gamesurge.net'> 
         <param name='port' value='6667'> 
         <param name='asl' value='true'> 
         <param name='gui' value='pixx'> 
         <param name='pixx:helppage' value='http://www.myserver.com/chathelp.html'> 
         <param name='style:floatingasl' value='true'> 
         <param name='language' value='english'> 
         <param name='pixx:nickfield' value='true'> 
         <param name='pixx:styleselector' value='true'> 
         <param name='pixx:setfontonstyle' value='true'> 
         \n"; 
   if ($timestamp != '') 
      { 
      echo " 
      <param name='pixx:timestamp' value='true'> 

      \n"; 
      } 
   if ($pass != '') 
      { 
         echo " 
         <param name='command1' value='/msg nickserv identify ".$pass."'> 
         <param name='command2' value='join #xxx> 
         \n"; 
      } else 
      { 
         echo " 
         <param name='command1' value='join #xxx> 
         \n"; 
      } 
      </applet> 
   </body> 
</html> 
\n"; 
} 
?>