Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008
    Location
    Scotland
    Posts
    151
    Tokens
    500

    Latest Awards:

    Default Help with php Shoutbox.

    Hey all. I'm using a php shoutbox script, but I need help to auto fill the user name field with the users forum username on phpbb3 (I'm already using a session from the forum which then displays the shoutbox to online users registered to the forum) I'm having trouble editing the code to auto-fill the user name field with their forum name.


    Here is the shoutbox code.
    PHP Code:
    <?php
        
    /******************************************************
         Shoutbox 1.0
         Written by Erik Holman at 24 May 2004
         ===================================
         Shoutbox somewhere in your page without frames but
         the shoutbox is able to scroll...

         Please do not remove the My-PHP links and headers...

         Visit www.my-php.tk for more free PHP scripts.
        ******************************************************/

        /////////////////////////////////////////////
        //Declare some variables
        //
        //Text file database
        
    $text_file     "db.txt";
      
        
    //Fill in the URL to the shoutbox.php from the root
        
    $shoutbox_url  "http://www.*******.com/shoutbox.php";
          
          
    //Where should the script go to after adding shout
        
    $referer_url   "http://www.*******.com/index.php";
        
    //
        /////////////////////////////////////////////    

        /////////////////////////////////////////////
        //Add the shout to the database
        //
        
    if( isset($_GET['action']) && $_GET['action'] == "add" )
        {
            if( 
    $_POST['email'] == "Email address" )
                
    $_POST['email'] = "";
            
    $new_line = (''.$user->data['username'].'!'); ."|".date("Y/m/d H:i")."|".stripslashes(htmlspecialchars($_POST['message'])) . "\n";
            if( ! 
    $fp fopen($text_file,"a") )
                echo 
    "Cannot open " $text_file "! Check the file rights."
            if( 
    flock$fpLOCK_EX ) )
            {
                
    fwrite$fp,$new_line );
                
    flock$fpLOCK_UN );
            } else {
                echo 
    "Couldn't lock the file " $text_file "!";
            }
            
    header("Location: " $referer_url );
        }
        
    //
        /////////////////////////////////////////////
        
        
        /////////////////////////////////////////////
        //Function show_shoutbox.
        //This function will print the complete shout
        //box.
        //
        
    function show_shoutbox($height 350,$width 120,$per_page 8$border="border:0px #DDDDDD solid;"$font_family="verdana",$font_size=11 )
        {
            
    //When there is requested a certain page
            
    if( isset( $_GET['shoutbox_page'] ) )
                
    $shoutbox_page $_GET['shoutbox_page'];
                
            
    //If there is no page then the default page is 1
            
    if( empty( $_GET['shoutbox_page'] ) )
                
    $shoutbox_page 1;

            
    //The database (a little shorter)
            
    $file $GLOBALS['text_file'];
            
            
    //Open the file and return error when fail
            
    if( ! $fp = @fopen$file"r" ) )
            {
                echo 
    "Cannot open database file for the shoutbox!";
                exit; 
            }
            
            
    //Init the output_buffer (string) and the shouts (array)
            
    $output_buffer "";
            
    $shouts = array();
            
            
    //When the filesize is greater then null (file contains info)
            
    if( filesize($file) )
            {
                
    //Read the file
                
    $fp            fread$fpfilesize$file ) );
                
    //all the shouts per line
                
    $shouts        explode("\n",$fp);
                
    //total of shouts
                
    $total_shouts  count($shouts);
                
    //total number of pages
                
    $total_pages   ceil($total_shouts/$per_page);
                
    //set the shout_pointer from where the shouts must be shown
                
    $shout_pointer = (($total_shouts  - ($shoutbox_page $per_page))+$per_page)-1;

                
    //when the requested page is greater then the total_pages, set the page to 1
                
    if( $shoutbox_page $total_pages )
                    
    $shoutbox_page 1;

                
    //create the page_numbers (the select box)
                
    $output_buffer .= page_numbers$total_pages $shoutbox_page );
            }
            
    //Else use the default values... (empty shoutbox)
            
    else
            {
                
    $shouts         0;
                
    $total_shouts   0;
                
    $shout_pointer  0;
                
    $output_buffer .= page_numbers);
            }

            
    //Loop through the shouts. descending (Z to A)
            
    for( $i $shout_pointer $i > ($shout_pointer-$per_page); $i-- )
            {
                
    //if the value is greater then -1
                
    if( $i > -)
                {
                    
    //if the shouts exists
                    
    if( $shouts[$i] )
                        list( 
    $name$email$date$shout ) = explode("|",$shouts[$i]);
                        
                    
    //if the name is not empty
                    
    if( !empty( $name ) )
                    {
                        
    //empty the email_start and end
                        
    $email_start "";
                        
    $email_end   "";
                        
    //if the email is not empty
                        
    if( ! empty( $email ) )
                        {
                            
    $email_start "<a href=\"mailto:" $email "\">";
                            
    $email_end   "</a>";
                        }
                        
    //add to output buffer
                        
    $output_buffer  .= "<strong>" $email_start $name $email_end "</strong>\n<br />" $shout "<br /><br />";
                    }
                }
            }
            
    ?>
                <table style="width:<?=$width;?>;">
                    <form method="post" action="<?=$GLOBALS['shoutbox_url'];?>?action=add">
                    <tr><td align="center" style="font-family:<?=$font_family;?>; font-size:<?=$font_size;?>px;"><strong>Shoutbox</strong></td></tr>
                    <tr>
                        <td>
                            <div style="<?=$border;?> font-family:<?=$font_family;?>; font-size:<?=$font_size;?>px; height:<?=$height;?>; overflow:auto; padding:3px; width:100%;">
                                <?=$output_buffer;?>
                            </div>
                        </td>
                    </tr>
                    
                               
                    <tr>
                        <td>
                            <div id="form">
                            <input type="text" name="name" value="Name" class="input" style="<?=$border;?> font-family:<?=$font_family;?>; font-size:<?=$font_size;?>px; width:100%;" onfocus="this.select();">
                            <input type="text" name="message" value="Message" class="input" style="<?=$border;?> font-family:<?=$font_family;?>; font-size:<?=$font_size;?>px;    width:100%;" onfocus="this.select();"><br />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            <input type="submit" value="Submit" class="submit" style="<?=$border;?> font-family:<?=$font_family;?>; font-size:<?=$font_size;?>px;"><br /></td>
                    </tr>           
                   </form> 
                </table>
            <?php
        
    }
        
    //
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        //Function page_numbers
        //This function will create the select box
        //with page numbers to change the page
        //
        
    function page_numbers($total_pages,$current 1)
        {
            
    //Get the URL from the address bar
            
    $url_bar $_SERVER['PHP_SELF']. "?" $_SERVER['QUERY_STRING'];
            
            
    //Remove the shoutbox_page=XX from the URL bar
            
    $url_bar preg_replace"/(&shoutbox_page=[1-9]+)/",""$url_bar );
            
            
    //Create a buffer to output this later.
            
    $buffer  "<div align=\"center\">Page: <select onchange=\"javascript: location.href='" $url_bar "&amp;shoutbox_page='+this.value;\" style=\"font-family: verdana; font-size: 10px;\">\n";
            
            
    //Loop through the number of pages.
            
    for( $i $i <=    $total_pages $i++ )
            {
                
    //None selected
                
    $selected "";
                
    //If the current page is $i, select this option
                
    if( $current == $i )
                    
    $selected "selected=\"selected\"";
                
    //Add output to the buffer
                
    $buffer .= "<option value=\"".$i."\"" $selected ">".$i."</option>\n";
            }
            
    //Close the output buffer
            
    $buffer .= "</select></div><hr size=\"1\">\n";
            
            
    //Return the buffer
            
    return $buffer;
        }
        
    //
        /////////////////////////////////////////////
        
        
    show_shoutbox();
    ?>
    Session code from my forum.
    PHP Code:
    <?php
    // Begin PHPBB Session Integration
    define('IN_PHPBB'true);
    $phpbb_root_path 'forum/';
    $phpEx substr(strrchr(__FILE__'.'), 1);
    include(
    $phpbb_root_path 'common.' $phpEx);
    //include($phpbb_root_path . 'includes/functions.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup('viewforum');

    ?>
    When using it I just use php include to on everypage.

    PHP Code:
    <?php
                
    if($user->data['is_registered'])
                { 
                    include(
    "shoutbox.php");
                }
                else
                {
                    include(
    "shoutbox2.php");
                }
                
    ?>
    I'm guessing this can come in handy also?

    any help would be brilliant thanks!
    Last edited by WeeGiE; 03-11-2008 at 08:33 PM.

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Hi,

    Sorry the information you have provided does not tell us any information about the phpbb3 session information (how the username stored, etc), so I am unable to help you with your issue I'm afraid.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •