PHP variables

  • Halo
  • Novice
  • Novice
  • User avatar
  • Posts: 19
  • Loc: Middle of nowhere

Post 3+ Months Ago

Hello everyone, i am working on a chat based on flash and php scripting. I already have one chat running and working perfectly. I really dont know much about php so i'm really lost in here.

This is the code I am using for my chat

Code: [ Select ]
<?php
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
header("Expires: ".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
<?php
$nickname = str_replace ("\n"," ", $nickname);
$nickname = str_replace ("<", " ", $nickname);
$nickname = str_replace (">", " ", $nickname);
$nickname = str_replace ("&", " ", $nickname);
$nickname = stripslashes ($nickname);
$location = str_replace ("\n"," ", $location);
$location = str_replace ("<", " ", $location);
$location = str_replace (">", " ", $location);
$location = str_replace ("&", " ", $location);
$location = stripslashes ($location);
$message = str_replace ("&"," ", $message);
$message = str_replace ("\n"," ", $message);
$message = stripslashes ($message);
$p=gmdate("d M H:i");
?>
&output=
<?php
$chat_file = "chat1.txt";
$chat_lenght = 200;
$max_single_msg_lenght = 100000;
$max_file_size = $chat_lenght * $max_single_msg_lenght;
$file_size= filesize($chat_file);
if ($file_size > $max_file_size) {
$lines = file($chat_file);
$a = count($lines);
$u = $a - $chat_lenght;
for($i = $a; $i >= $u ;$i--){
$msg_old =  $lines[$i] . $msg_old;
}
$deleted = unlink($chat_file);
$fp = fopen($chat_file, "a+");
$fw = fwrite($fp, $msg_old);
fclose($fp);
}
$msg = str_replace ("\n"," ", $message);
$msg = stripslashes ($msg);
if ($msg != ""){
$fp = fopen($chat_file, "a+");
$fw = fwrite($fp, "$nickname: $msg\n");
fclose($fp);}
$lines = file($chat_file);
$a = count($lines);
$u = $a - $chat_lenght;
for($i = $a; $i >= $u ;$i--){
echo $lines[$i];
}
  1. <?php
  2. extract($HTTP_GET_VARS);
  3. extract($HTTP_POST_VARS);
  4. header("Expires: ".gmdate("D, d M Y H:i:s")."GMT");
  5. header("Cache-Control: no-cache, must-revalidate");
  6. header("Pragma: no-cache");
  7. ?>
  8. <?php
  9. $nickname = str_replace ("\n"," ", $nickname);
  10. $nickname = str_replace ("<", " ", $nickname);
  11. $nickname = str_replace (">", " ", $nickname);
  12. $nickname = str_replace ("&", " ", $nickname);
  13. $nickname = stripslashes ($nickname);
  14. $location = str_replace ("\n"," ", $location);
  15. $location = str_replace ("<", " ", $location);
  16. $location = str_replace (">", " ", $location);
  17. $location = str_replace ("&", " ", $location);
  18. $location = stripslashes ($location);
  19. $message = str_replace ("&"," ", $message);
  20. $message = str_replace ("\n"," ", $message);
  21. $message = stripslashes ($message);
  22. $p=gmdate("d M H:i");
  23. ?>
  24. &output=
  25. <?php
  26. $chat_file = "chat1.txt";
  27. $chat_lenght = 200;
  28. $max_single_msg_lenght = 100000;
  29. $max_file_size = $chat_lenght * $max_single_msg_lenght;
  30. $file_size= filesize($chat_file);
  31. if ($file_size > $max_file_size) {
  32. $lines = file($chat_file);
  33. $a = count($lines);
  34. $u = $a - $chat_lenght;
  35. for($i = $a; $i >= $u ;$i--){
  36. $msg_old =  $lines[$i] . $msg_old;
  37. }
  38. $deleted = unlink($chat_file);
  39. $fp = fopen($chat_file, "a+");
  40. $fw = fwrite($fp, $msg_old);
  41. fclose($fp);
  42. }
  43. $msg = str_replace ("\n"," ", $message);
  44. $msg = stripslashes ($msg);
  45. if ($msg != ""){
  46. $fp = fopen($chat_file, "a+");
  47. $fw = fwrite($fp, "$nickname: $msg\n");
  48. fclose($fp);}
  49. $lines = file($chat_file);
  50. $a = count($lines);
  51. $u = $a - $chat_lenght;
  52. for($i = $a; $i >= $u ;$i--){
  53. echo $lines[$i];
  54. }


the code works perfectly but what i wanted to know is how can i create more "output" variables? I want to make multiple rooms and i want one flash file to load all the varialbes from this php script.

I tried copying the "output" and renamed it to &output2= but that doesnt seem to work.
Moderator Remark: Flash-specific reply split to http://www.ozzu.com/flash-forum/clearing-text-box-t95877.html
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

edit the second part of above code and adapt it as shown
Code: [ Select ]
 
<?php
function chat_sys($filename)
 {
 $chat_file = $filename;
 $chat_lenght = 200;
 $max_single_msg_lenght = 100000;
 $max_file_size = $chat_lenght * $max_single_msg_lenght;
 $file_size= filesize($chat_file);
 if ($file_size > $max_file_size) {
 $lines = file($chat_file);
 $a = count($lines);
 $u = $a - $chat_lenght;
 for($i = $a; $i >= $u ;$i--){
 $msg_old =  $lines[$i] . $msg_old;
 }
 $deleted = unlink($chat_file);
 $fp = fopen($chat_file, "a+");
 $fw = fwrite($fp, $msg_old);
 fclose($fp);
 }
 $msg = str_replace ("\n"," ", $message);
 $msg = stripslashes ($msg);
 if ($msg != ""){
 $fp = fopen($chat_file, "a+");
 $fw = fwrite($fp, "$nickname: $msg\n");
 fclose($fp);}
 $lines = file($chat_file);
 $a = count($lines);
 $u = $a - $chat_lenght;
 $ret = "";
 for($i = $a; $i >= $u ;$i--){
 $ret .= $lines[$i];
 }
 return $ret;
 }
?>
 
  1.  
  2. <?php
  3. function chat_sys($filename)
  4.  {
  5.  $chat_file = $filename;
  6.  $chat_lenght = 200;
  7.  $max_single_msg_lenght = 100000;
  8.  $max_file_size = $chat_lenght * $max_single_msg_lenght;
  9.  $file_size= filesize($chat_file);
  10.  if ($file_size > $max_file_size) {
  11.  $lines = file($chat_file);
  12.  $a = count($lines);
  13.  $u = $a - $chat_lenght;
  14.  for($i = $a; $i >= $u ;$i--){
  15.  $msg_old =  $lines[$i] . $msg_old;
  16.  }
  17.  $deleted = unlink($chat_file);
  18.  $fp = fopen($chat_file, "a+");
  19.  $fw = fwrite($fp, $msg_old);
  20.  fclose($fp);
  21.  }
  22.  $msg = str_replace ("\n"," ", $message);
  23.  $msg = stripslashes ($msg);
  24.  if ($msg != ""){
  25.  $fp = fopen($chat_file, "a+");
  26.  $fw = fwrite($fp, "$nickname: $msg\n");
  27.  fclose($fp);}
  28.  $lines = file($chat_file);
  29.  $a = count($lines);
  30.  $u = $a - $chat_lenght;
  31.  $ret = "";
  32.  for($i = $a; $i >= $u ;$i--){
  33.  $ret .= $lines[$i];
  34.  }
  35.  return $ret;
  36.  }
  37. ?>
  38.  

and then you call the function with different file name which will corresponds different chat room like shown below
Code: [ Select ]
 
&output= <?php echo chat_sys("chat1.txt");?>
&output2 = <?php echo chat_sys("chat2.txt");?>
&output3 = <?php echo chat_sys("chat3.txt");?>
etc.....
 
  1.  
  2. &output= <?php echo chat_sys("chat1.txt");?>
  3. &output2 = <?php echo chat_sys("chat2.txt");?>
  4. &output3 = <?php echo chat_sys("chat3.txt");?>
  5. etc.....
  6.  
  • Halo
  • Novice
  • Novice
  • User avatar
  • Posts: 19
  • Loc: Middle of nowhere

Post 3+ Months Ago

thanks a lot for the reply darklord, i will try doing that.

regards.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 134 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.