homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
live php chat can`t code rtl language
Astyak




msg:4584216
 1:14 pm on Jun 14, 2013 (gmt 0)

hi
i have this chat live code and i want type right to left language but it shows digit and sign in output in HTML page. please advise how I can do this.
thanks


<?php
# ABSOLUTELY NOTHING can come before the
# line above, NOT EVEN BLANK LINES, or the
# script WILL NOT WORK.

# Settings have been moved to another file, so you shouldn't
# have to modify this file at all.
require "server-settings.php";

# we will do our own error handling to keep warning messages
# from junking up our XML
error_reporting(0);
$old_error_handler = set_error_handler("userErrorHandler");
$id = $_POST['id'];
$id = cleanId($id);
$namereg = '/^[a-zA-Z_ ()0-9]+$/';
$issupport = (substr($id,0,7) == 'support');
$ssl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE);
//$adminpath = "$dataDir" . "/" . "support";
if ($id == '') {
timeOut();
Header("Content-type: text/xml", 1);
$isad = count(getUsers('/^support/'))>0;
echo("<boutellchat>\n<ad isad=\"$isad\" />\n</boutellchat>\n");
# No valid id to check messages for, or polling for admin.
return;
}
$password = $_POST['password'];
$path = $dataDir . "/" . $id;
if ($_POST['login']) {
timeOut();
login();
return;
}
if ($_POST['logout']) {
logout();
return;
}
if (!validate()) {
# Ignore attempts to
# masquerade as another user
return;
}
# Check for idle users on every access. For
# better performance we should do this only
# perhaps once a minute.
timeOut();
$message = $_POST['message'];
if ($message != '') {
# Groan: PHP automatically escapes ' and " with a \,
# by default... but not on every site. So we have
# to test for this and manually undo it. If we
# were using a database instead of a flat file,
# we might want it, but it's not ALWAYS on, so
# we'd STILL have to adjust for that here. Isn't
# PHP fun?
if (get_magic_quotes_gpc()) {
$message = stripslashes($message);
}
$message = preg_replace('#([a-z]+://([^\s\w/]?[\w/])*)#is', '<a href="\\1" target="_blank">\\1</a>', $message);
$message = preg_replace('#(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '<a href="mailto:\\1">\\1</a>', $message);
// mine $message = preg_replace('#(([a-z0-9._+\-]+)@[a-z0-9_\-.]+([^.,]+|$))#is', '<a href="mailto:\\1">\\1</a>', $message);
# Escape anything that can be mistaken
# for the start of a new XML element.
# Conveniently, the client would otherwise
# have to do this anyway.
$message = preg_replace('/&/', '&amp;', $message);
$message = preg_replace('/</', '&lt;', $message);
$message = preg_replace('/>/', '&gt;', $message);
$to = $_POST['to'];
$to = cleanId($to);
# Anyone but support can only talk to support.
if (!$issupport and substr($to,0,7) != 'support') {
return;
}
# Echo back to the sender so they
# know they are getting through
# (at least to the server...)
//appendMessage($id, $id, $message, false);
if ($to != '') {
# send to all support people, and to "to"
/*
if (substr($to,0,7) == "support") {
$users = getUsers(false);
foreach ($users as $u) {
if (substr($u,0,7) == 'support') {
appendMessage($id, $u, $message, false);
}
}
} else {
appendMessage($id, $to, $message, false);
}
*/
$users = getUsers($namereg);
foreach ($users as $u) {
if (substr($u,0,7) == "support" or $u == $to or $u == $id) {
appendMessage($id, $u, $message, false,$ssl);
}
}
}
}
lock($id);
$fp = null;
if (file_exists($path)) {
$fp = fopen($path, 'r');
}
$messages = "";
if ($fp) {
$size = filesize($path);
if ($size) {
$messages = fread($fp, filesize($path));
}
fclose($fp);
}
# Truncate the file to show we got everything,
# and that we are logged in.
$fp = fopen($path, 'w');
if ($fp) {
fclose($fp);
}
Header("Content-type: text/xml", 1);
echo("<boutellchat>\n" .
$messages .
"\n</boutellchat>\n");
unlock($id);

# You can replace this with a call to a database
# if you want to integrate this with a real account system
function validate() {
global $id, $password, $supportPassword, $issupport;
if ($issupport) {
if ($password != $supportPassword) {
return false;
}
}
return true;
}

function login() {
global $id, $password, $supportPassword, $path, $issupport, $namereg, $ssl;
$success = 1;
$message = "Successful login";
if (!validate()) {
$success = 0;
$message = "Incorrect username or password";
}
Header("Content-type: text/xml", 1);
echo(<<<EOXML
<boutellchat>
<login success="$success" message="$message" e="$ssl"/>
</boutellchat>
EOXML
);
if ($success) {
$users = getUsers($namereg);
touch($path);
$online = 0;
foreach ($users as $u) {
if ($issupport or (substr($u,0,7) == 'support')) {
appendMessage($u, $id, "$u is currently logged in.", false,false);
appendMessage($id, $u, "$id has just logged in.", false,$ssl);
$online++;
}
}

if (!$online) {
if ($issupport) {
appendMessage('support', $id, "There are no customers currently logged in.", false,false);
} else {
appendMessage('support', $id, "There are no support people logged in.", false,false);
}
}
postusers();
}
}
function logout() {
global $id, $password, $supportPassword, $path, $issupport, $namereg,$ssl;
$success = 1;
$message = "Successful logout";
if (!validate()) {
$success = 0;
$message = "Incorrect username or password";
}
Header("Content-type: text/xml", 1);
echo(<<<EOXML
<boutellchat>
<login success="$success" message="$message"/>
</boutellchat>
EOXML
);
# If support logs out, tell everybody.
# If someone else logs out, tell support.
if ($success == 1) {
unlink("$path");
mylog("$id has chosen to log out");
$message = "$id has logged out.";
$users = getUsers($namereg);
foreach ($users as $u) {
if ($issupport or substr($u,0,7) == 'support') {
appendMessage($id, $u, $message, false,$ssl);
}
}
postusers();
}
}
function postusers() {
// posted to message data stream
global $namereg;
global $dataDir;
$users = getUsers($namereg);
foreach ($users as $u) {
if (substr($u,0,7) == 'support') {
lock($u);
$path = $dataDir . "/" . $u;
$fp = fopen($path, 'a');
if ($fp) {
foreach ($users as $v) {
fwrite($fp, <<<EOXML
<online u="$v" />
EOXML
);
}
fclose($fp);
}
unlock($u);
}
}
}

# File locking to prevent problems when two
# users talk to the server at once. This will
# do the job unless your files are accessed
# over NFS. In that case, you need to recode
# this to use a database instead. Probably
# a good idea in the long run anyway.
function lock($id)
{
global $dataDir;
for ($i = 0; ($i < 20); $i++) {
if (mkdir("$dataDir/$id.lock", 0700)) {
return;
}
sleep(1);
}
# After 20 seconds break the lock -- it is
# probably a stale lock left over by a
# script that was interrupted.
unlink("$dataDir/$id.lock");
if (!mkdir("$dataDir/$id.lock", 0700)) {
exit("couldn't get lock");
}
}
function unlock($id)
{
global $dataDir;
rmdir("$dataDir/$id.lock");
}
function getUsers($reg)
{
//global $namereg;
//$match = ($sup ? '/^support/' : $namereg);
global $dataDir;
$dh = opendir($dataDir);
$users = array();
while (false != ($filename = readdir($dh))) {
if (preg_match($reg, $filename)) {
$users[] = $filename;
}
}
closedir($dh);
return $users;
}
function timeOut()
{
global $dataDir, $idleTimeLimit,$namereg;
$dh = opendir($dataDir);
$now = time();
$deadUsers = array();
while (false != ($filename = readdir($dh))) {
if (preg_match($namereg, $filename)) {
$mtime = filemtime("$dataDir/$filename");
if ($now - $mtime > $idleTimeLimit) {
$deadUsers[] = $filename;
}
}
}
closedir($dh);
foreach ($deadUsers as $u) {
mylog("Timed out $u");
lock($u);
unlink("$dataDir/$u");
unlock($u);
}
}
function appendMessage($from, $t, $message, $recursive,$ssl)
{
global $dataDir, $to;
lock($t);
$path = $dataDir . "/" . $t;
if (file_exists($path)) {
$fp = fopen($path, 'a');
if ($fp) {
$time = "(" . date("h:i:s") . ")";
$result = fwrite($fp, <<<EOXML
<speak id="$from" d="$to" t="$time" e="$ssl">$message</speak>
EOXML
);
fclose($fp);
}
# INCREDIBLY, PHP 'helpfully' caches the
# original size of the file when we call
# file_exists, so code elsewhere in this
# script will get the wrong answer for
# filesize. and they have refused to treat
# this obvious, maddening breakage as
# a bug. This alleged "feature" is so
# plainly not worth the pain and confusion.
#
# http://bugs.php.net/bug.php?id=28790&edit=3
#
# ... One wasted day. OK I'm done now.

clearstatcache();
} else {
if ((!$recursive) && ($from != $t)) {
appendMessage($t, $from,
"$t is not logged in.", true,false);
}
}
unlock($t);
}
function cleanId($id)
{
# a-zA-Z_0-9 only in ids. Absolutely
# crucial since we are using the
# file system!
#
# For readability, spaces become _
//$id = preg_replace('/ +/', '_', $id);
//$id = preg_replace('/[\W]/', '', $id);
$id = preg_replace('/[^a-zA-Z_ ()0-9]+/', '', $id);
return $id;
}
function mylog($msg)
{
global $dataDir;
$fp = fopen("$dataDir/log.txt", "a");
fwrite($fp, date("F j, Y, g:i a") . ": " . $msg . "\n");
fclose($fp);
}
// Log errors and warnings instead of screwing up XML messages
// with them. From the PHP documentation for error_reporting()
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
// define an assoc array of error string
// in reality the only entries we should
// consider are E_WARNING, E_NOTICE, E_USER_ERROR,
// E_USER_WARNING and E_USER_NOTICE
$errortype = array (
E_ERROR => "Error",
E_WARNING => "Warning",
E_PARSE => "Parsing Error",
E_NOTICE => "Notice",
E_CORE_ERROR => "Core Error",
E_CORE_WARNING => "Core Warning",
E_COMPILE_ERROR => "Compile Error",
E_COMPILE_WARNING => "Compile Warning",
E_USER_ERROR => "User Error",
E_USER_WARNING => "User Warning",
E_USER_NOTICE => "User Notice",
E_STRICT => "Runtime Notice"
);

if ($errno == E_NOTICE) {
# Not interesting, don't spam the log file
return;
}

// set of errors for which a var trace will be saved
$user_errors = array(
E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

$err = "<errorentry>\n";
$err .= "\t<datetime>" . $dt . "</datetime>\n";
$err .= "\t<errornum>" . $errno . "</errornum>\n";
$err .= "\t<errortype>" . $errortype[$errno] . "</errortype>\n";
$err .= "\t<errormsg>" . $errmsg . "</errormsg>\n";
$err .= "\t<scriptname>" . $filename . "</scriptname>\n";
$err .= "\t<scriptlinenum>" . $linenum . "</scriptlinenum>\n";

if (in_array($errno, $user_errors)) {
$err .= "\t<vartrace>" .
wddx_serialize_value($vars, "Variables") .
"</vartrace>\n";
}
$err .= "</errorentry>\n\n";

mylog($err);
}
function basePath()
{
$src = __FILE__;
$path = preg_replace('/\/[^\/]+$/', '', $src);
return $path;
}
?>

 

DrDoc




msg:4586141
 4:07 pm on Jun 20, 2013 (gmt 0)

Welcome to WebmasterWorld!

What character encoding are you using? The entry page should probably use UTF-8, and same when you display them back to the user.

Astyak




msg:4586362
 9:15 am on Jun 21, 2013 (gmt 0)

sorry for late replay
Header("Content-type: text/xml; charset=UTF-8"); for server.php page and <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http&#8206;://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> for html page
thanks

DrDoc




msg:4586473
 4:34 pm on Jun 21, 2013 (gmt 0)

<html xmlns="http&#8206;://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


Is that a typo?

Astyak




msg:4586501
 6:54 pm on Jun 21, 2013 (gmt 0)

yes

Astyak




msg:4586502
 6:54 pm on Jun 21, 2013 (gmt 0)

<html xmlns="http&#8206;://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa">

Astyak




msg:4586503
 6:57 pm on Jun 21, 2013 (gmt 0)

i don`t type this number.

lucy24




msg:4586529
 8:38 pm on Jun 21, 2013 (gmt 0)

:: detour to converter ::

8206 = 200E = left-to-right mark

How did it get into the middle of an URL?

To screen out any possible variables: Does your code work as intended if you use a language written in a non-ascii ltr script?

Astyak




msg:4586532
 8:54 pm on Jun 21, 2013 (gmt 0)

just ascii ltr work. please check this url: [takcake.com...]
thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved