View Single Post
  #13  
Old 05-22-2011, 10:32 PM
asdfadrian asdfadrian is offline
 
Join Date: May 2011
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Line 7 would be:
PHP Code:
session_start(); 

To be more specific on the current chat.php I have shown you the coding below:
PHP Code:
<?php

// Start a session and get/generate a random user_id
// We'll use this user_id to create pseudo-uniquely colored chat lines later
// Close the session (a session can only be accessed by one process at a time)
error_reporting(-1)
session_start();
header('Cache-control: private'); // IE6 fix
header("Content-Type: text/html; charset=utf-8");

require_once(
'./global.php');

//if (!isset($_SESSION['USER_ID'])) $_SESSION['USER_ID'] = rand(1, 24);
//$USER_ID = $_SESSION['USER_ID'];

$con mysql_connect ("localhost","xxxxxx""xxxxxxx");
 
mysql_select_db ("xxxxxx");
 
$sql mysql_query("SELECT username FROM user WHERE userid=$userid");

                while (
$row mysql_fetch_array($sql)){
                
$name $row['username'];
                
$icon $row['icon'];
                
$color $row['color'];
            }
if(
$color == 0)
            {
                
$color "#989579";
            }

if (
$icon == '')
            {
                
$icon 'http://www.hiveworkshop.com/forums/images_all/chat_ranks/new/user.png';
            }
            

if (
$userid == ''){
            
                
$username 'Guest';    
            }  
            
session_write_close();
ob_flush();
flush();

// Path to the text files holding the chat window content
$fn 'chat.txt';

// Did the browser request the chat content?
// If so, it provided this script with its last known line number
$read = &$_GET['r'];
if (isset(
$read)) {
  
// Create the chat file if neccessary
  
if (!file_exists($fn)) {
    
touch($fn);
    
chmod($fn0644);
  }
  if (
$read == 0chat_write('<E>');
  
// The script will not exit on its own on user disconnect
  // this way we can later add a "user left chat" message
  
ignore_user_abort(true);
  
$i 0;
  while (
true) {
    
// Open the chat file and get the current line number
    
$f fopen($fn'r');
    
flock($f2);
    
$offset 0;
    
$offset trim(fgets($f));
    
// Break the loop if the browser is not up to date
    
if ($offset $read) break;
    
// If the browser is up to date, wait
    
flock($f3);
    
fclose($f);
    @
set_time_limit(0);
    
// By default we wait 3 seconds between each check
    // However, after one minute of complete silence in the chat we step
    // back to 10 second periods to save server resources
    
if ($i 20sleep(10);
    else 
sleep(3);
    
// To check for user disconnection we have to output at least one byte
    // We'll echo a line break since this does no harm to our JavaScript
    
echo "\n";
    
ob_flush();
    
flush();
    if (
connection_status() != 0) {
      
// This is where a user disconnection is detected
      // You could add stuff to display "user left chat" messages here
      
chat_write('<L>');
      exit();
    }
    
$i++;
  }
  
// If the loop was exited, we end up here
  // Now, echo all missing lines
  
while ($s fgets($f)) {
    echo 
utf8_encode($s);
    if (
$offset <= ++$read) break;
  }
  
// Close the file, exit
  
flock($f3);
  
fclose($f);
  exit();
}

// This function writes one line into the chat file
// For easiest accessibility newer lines are on top!
function chat_write($write) {
  global 
$USER_ID$fn;
  
// Maximum line count
  
$maxlines 35;
  if (
trim($write) == '') return;
  
// Create the chat file if neccessary
  
if (!file_exists($fn)) {
    
touch($fn);
    
chmod($fn0644);
  }
  
// Open the chat file and get the current line number
  
$f fopen($fn'r+');
  
flock($f2);
  
$offset 0;
  
fscanf($f"%s\n"$offset);
  
// Increase by one as we're adding a new line now
  
$offset++;
  
$i 0;
  
$chat '';
  
// First we have to read the whole file
  // Lines are being read one by one until we're at the end or until we reach $maxlines
  
while (($i $maxlines) && ($s fgets($f))) {
    
$chat .= $s;
    
$i++;
  }
  
// This is the actual line we're adding
  // You see: The chat file contains JavaScript calls
  // This way no parsing of the lines is neccessary
  // We'll just need to eval() them in our JavaScript
  
$time date('H:i:s');
  
$js "cs($offset,$USER_ID,'$time','User','$write','');\n";
  
// Go to the top
  
fseek($f0);
  
// Empty the file
  
ftruncate($f0);
  
// Write the new offset
  
fwrite($f"$offset\n");
  
// Write the new line
  
fwrite($f$js);
  
// And then the rest
  
fwrite($f$chat);
  
// Close the file
  
flock($f3);
  
fclose($f);
  
// We'll return the last added line to the calling
  
return $js;
}

function 
chat_delete($delete) {
  global 
$fn;
  if (
$delete == '') exit();
  if (!
file_exists($fn)) {
    
touch($fn);
    
chmod($fn0644);
  }
  
$f fopen($fn'r+');
  
flock($f2);
  
$offset 0;
  
fscanf($f"%s\n"$offset);
  
$chat '';
  
$i 0;
  while (
$s fgets($f)) {
    
$s str_replace("'$delete'""''"$s);
    
$chat .= $s;
    
$i++;
  }
  
fseek($f0);
  
ftruncate($f0);
  
fwrite($f"$offset\n");
  
fwrite($f$chat);
  
flock($f3);
  
fclose($f);
}

// Did the browser send a new chat line?
$write = &$_POST['w'];
if (isset(
$write)) {
  if (
$write == '') exit();
  
// Remove the slashes that were added to the form contents by PHP automatically
  
$write stripslashes($write);
  
// Transform characters like < and > into their HTML representations
  
$write htmlspecialchars($writeENT_QUOTES);
  
$write addslashes($write);
  if (
strpos($write'/del ') === 0) {
    
$delete str_replace('/del '''$write);
    
chat_delete($delete);
    exit();
  }
  
// Wordwrap after 100 characters and add the new lines to the chat file
  
$lines wordwrap($write100"\n"true);
  
$lines explode("\n"$lines);
  foreach (
$lines as &$line) {
    
// The function returns the added line
    // We'll output this so the users can read their own texts without delay right after sending
    
echo utf8_encode(chat_write($line));
  }
  exit();
}
?>
var lines    = 35;
var title    = '';
var offset   = 0;
var messages = new Array();
var message  = document.getElementById('message');
var chat     = document.getElementById('chat');
var tmrRead = setTimeout('chat_read();', 300);

function request_write(url, post) {
  r = false;
  if (window.XMLHttpRequest) {
    r = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      r = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        r = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
      }
    }
  }
  if (!r) return false;
  r.onreadystatechange = alert_write;
  if (post == null) {
    r.open('GET', url, true);
    r.send(null);
  } else {
    r.open('POST', url, true);
    r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    r.send(post);
  }
}

function alert_write() {
  try {
    if ((r.readyState == 4) && (r.status == 200)) parse(r.responseText);
  } catch(e) {
  }
}

function request_read(url, post) {
  r2 = false;
  if (window.XMLHttpRequest) {
    r2 = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      r2 = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        r2 = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
      }
    }
  }
  if (!r2) return false;
  r2.abort();
  r2.onreadystatechange = alert_read;
  if (post == null) {
    r2.open('GET', url, true);
    r2.send(null);
  } else {
    r2.open('POST', url, true);
    r2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    r2.send(post);
  }
}

function alert_read() {
  clearTimeout(tmrRead);
  try {
    if ((r2.readyState == 4) && (r2.status == 200)) {
      parse(r2.responseText);
      tmrRead = setTimeout('chat_read();', 30);
    }
  } catch(e) {
    tmrRead = setTimeout('chat_read();', 3000);
  }
}

function chat_read() {
  clearTimeout(tmrRead);
  request_read('chat.php?r='+offset, null);
}

function keyup(e) {
  if (window.event) k = window.event.keyCode;
  else if (e) k = e.which;
  else return true;
  if (k == 13) chat_write();
}

function chat_display() {
  html = '';
  i = 0;
  while ((i < lines) && (i < offset)) {
    h = offset-i;
    if (messages[h]) html = messages[h] + html;
    i++;
  }
  chat.innerHTML = html;
  if (title != '') {
    title = title.replace(/&amp;/g, '&');
    title = title.replace(/&quot;/g, '"');
    title = title.replace(/'/g, '\'');
    title = title.replace(/&lt;/g, '<');
    title = title.replace(/&gt;/g, '>');
    document.title = title;
  }
}

function chat_write() {
  request_write('chat.php', 'w='+escape(message.value));
  message.value = '';
}

function cs(o, i, t, u, m, c) {
  if (m == '<E>') {
    if (u != '') messages[o] = '<span id="C'+i+'">['+t+'] <b>* '+u+' has entered the chat *</b></span><br />';
  } else if (m == '<L>') {
    if (u != '') messages[o] = '<span id="C'+i+'">['+t+'] <b>* '+u+' has left the chat *</b></span><br />';
  } else {
    if (u != '') {
      u += ':';
      spaces = 5 - u.length;
      for (j = 0; j < spaces; j++) u += "&nbsp;";
      u += ' ';
    }
    title = m;
    m = m.replace(/ /g, '&nbsp;');
    messages[o] = '<span id="C'+i+'">['+t+'] '+u+''+m+'</span><br />';
  }
  if (o > offset) {
    offset = o;
    window.focus();
    message.focus();
  }
}

function parse(s) {
  if (s != '') {
    s = unescape(s);
    eval(s);
    chat_display();
  }
}
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01331 seconds
  • Memory Usage 1,920KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete