# Shoutbox in PHP and Flash

**URL:** https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474
**Category:** Uncategorized
**Created:** [November 13, 2003, 12:15am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474 "2003-11-13T00:15:04Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Yeldarb](https://avatars.discourse-cdn.com/v4/letter/y/51bf81/32.png) [@Yeldarb](https://forum.kirupa.com/u/Yeldarb)
#### Post date: [November 13, 2003, 12:15am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/1 "2003-11-13T00:15:04Z")

</div>

Ok, I’m trying to make a shout box using PHP and Flash, it’s not working though… You can see what I have so far at [www.barbdwyer.com/T6](http://www.barbdwyer.com/T6) . I don’t know PHP, so I had one of my friends write the script for me, but he doesn’t know Flash, so he couldn’t help me set it up.

in flash, i have the following code on my submit button:

```auto
on(press) { 
      getURL ("add.php", "_blank", "POST");
}

```

i also have this in a frame:

```auto
onEnterFrame = function () {
	Name = theName.text;
	Email = theContact.text;
	Comments = theMessage.text;
};

```

then here’s the PHP scripts.

one called add.php:

```php
<?php

$Name = ereg_replace("[^A-Za-z0-9\<\>]", "", $Name); 
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Email); 
$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Comments);

$Name = stripslashes($Name); 
$Email = stripslashes($Email); 
$Comments = stripslashes($Comments); 

if ($Submit == "Yes") { 
	$filename = "shoutbox.txt"; 
	$fp = fopen( $filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose( $fp );
	$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>.:::."; 
	$New = "$Input$OldData";
	$fp = fopen( $filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose( $fp );
	Header("Location: shoutbox.php"); 
} 

?>

```

one called forum.php:

```php
<?php

$Name = ereg_replace("[^A-Za-z0-9\<\>]", "", $Name); 
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Email); 
$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Comments);

$Name = stripslashes($Name); 
$Email = stripslashes($Email); 
$Comments = stripslashes($Comments); 

if ($Submit == "Yes") { 
	$filename = "shoutbox.txt"; 
	$fp = fopen( $filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose( $fp );
	$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>.:::."; 
	$New = "$Input$OldData";
	$fp = fopen( $filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose( $fp );
	Header("Location: index.php"); 
} 

?>
<form name="shoutbox" action="form.php" method="post">
<table align="center" border="0">
  <tr>
    <td>Name:</td>
    <td><input type="text" name="Name"></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input type="text" name="Email"></td>
  </tr>
  <tr>
    <td>Message:</td>
    <td colspan="2" align="right">
<textarea name="Comments"></textarea>
<input type="hidden" name="Submit" value="Yes">
    </td>
  </tr>
  <tr>
    <td colspan="2" align="right"><input type="submit" value="Submit"></td>
  </tr>
</table>
</form>

```

and finally, one called shoutbox.php:

```php
<?php

$filename = "shoutbox.txt"; 
$fp = fopen($filename,"r");
$Data = fread($fp, 80000);
fclose( $fp ); 

$DataArray = split (".:::.", $Data);

//Put in the starting tag and the ending tag number
for ($n = 0; $n < 20; $n++) {
print $DataArray[$n]; 
}

?>

```

then there is an empty text file called shoutbox.txt

I am completely confused, he told me to make the add.php from the php part of the forum.php, and I know that this worked when it was in HTML, but I got a headache trying to get it to work in flash. Can someone please help, thanks 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 14, 2003, 12:52am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/2 "2003-11-14T00:52:21Z")

</div>

can anyone else try to help, please? thanks again in advance

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 5:34pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/3 "2003-11-15T17:34:09Z")

</div>

That’s why I said, use loadVariablesNum and set it to send using POST. It’s not only for recieving. This method worked so many times for me when I had a shoutbox.

- Anyone know how I can make my chatroom faster? I need to learn how to refresh manually every 1 second.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 5:38pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/4 "2003-11-15T17:38:46Z")

</div>

if it’s every one second, it’s not manually, but you could use setInterval

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 5:40pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/5 "2003-11-15T17:40:15Z")

</div>

What do you mean it’s not manually? I’m weak at actionscript. Can you help me out?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 6:07pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/6 "2003-11-15T18:07:44Z")

</div>

if you refresh every one second, it would be automatic, to refresh manually you would need a button that says refresh on it that would refresh it. to do it every one second you could use setInterval, run a search for setInterval, you will find tons of stuff :thumb:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 7:07pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/7 "2003-11-15T19:07:20Z")

</div>

Ah ok. So let me change my words. I want it to refresh automatically without pressing a button.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 7:15pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/8 "2003-11-15T19:15:16Z")

</div>

see ur other thread, that’s how you do it is with setInterval

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 15, 2003, 8:01pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/9 "2003-11-15T20:01:57Z")

</div>

here r the php scripts. I can;t upload the fla file cuz its too big. Give me your email address and i’ll send it to u over there.

btw, i commented out the old sentences in the php scripts in case u needed them

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 16, 2003, 6:43pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/10 "2003-11-16T18:43:05Z")

</div>

well I got it to display it, but now it doesn’t show the name, is there any way to just take out the link for the name, and just have it say the name?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 16, 2003, 8:55pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/94474/11 "2003-11-16T20:55:57Z")

</div>

yea. in add.php, change this line:

```php

$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>";

```

to this:

```php

$Input = "$Name: $Comments<br><br>";

```
