Page 1 of 1

Shoutbox , ridding SPAM, adding features, Syntax, explanatio

Posted: Wed Jul 26, 2006 6:24 pm
by kevinoneill
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Below is the code I use for my PHP shoutbox. I can read basic PHP fine, I can read and code basic VBA.
Here's what I need help on. Reply to any you know how to work.  

[b]1. If any word from a list is present in the message, do not send.[/b]

[b]2. If more than one URL exists within message, do not send.[/b]

Can I do this by creating a variable $msg and checking it with with a string of some sort and check the above?

[b]3. I'd like to submit the msg, without the page reloading.[/b]

Using something like this to reload the Div containing the shoutbox results (I use this for a real time clock I coded in JS). Very open to other ideas.

[syntax="javascript"]function realtimeclock() { insert code... }
function cycle()
	{
	if (document.all || document.getElementById)
	setInterval("realtimeclock()",1000)
	}

window.onload=cycle
I don't understand the while {} loop in my shoutbox results. Can someone explain the code?

ShoutBox Code[/syntax]

Code: Select all

<form action="<? echo $php_self ?>" method="post">
<input id="name" type='text' value='' name='name' />
<input type="submit" name="submit" value="Submit" />
<textarea rows="2" cols="35" name='message'></textarea>
</form>

<?
mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("xxxx");

if($submit)
{
putenv('TZ=America/New_York');
$time=date("F j, Y, g:i a", time());

$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
	  "VALUES ('NULL','$name', '$message','$time')");
}

$result = mysql_query("select * from shoutbox order by id desc limit 40");
while($r=mysql_fetch_array($result))
{		
	$time=$r["time"]; 
	$id=$r["id"];
	$message=$r["message"];
	$name=$r["name"];
?>

<? echo $name ?><br />
<? echo $time ?><br />
<? echo $message ?><br />

<? } ?>
4. I want to install PHP on my computer so I don't have to upload to my site and reload to test things. How can I go about doing this on my Apple.

Thanks Pixel Guys!!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: Shoutbox , ridding SPAM, adding features, Syntax, explan

Posted: Wed Jul 26, 2006 6:31 pm
by RobertGonzalez
kevinoneill wrote:Reply to any you know how to work. :D

1. If any word from a list is present in the message, do not send.
Regular expressions.
kevinoneill wrote:2. If more than one URL exists within message, do not send.
strstr(), substr() or Regular Expressions.
kevinoneill wrote:3. I'd like to submit the msg, without the page reloading.
JavaScript or AJAX if the submit hits a database.
kevinoneill wrote:4. I want to install PHP on my computer so I don't have to upload to my site and reload to test things. How can I go about doing this on my Apple.
PHPMac.com

Posted: Wed Jul 26, 2006 6:38 pm
by kevinoneill
Thanks appreciate the help. I think I need more detailed help though. Thanks.

Say for the above sentence I call it $result, I wan to count the number of times 'thanks' appears, x=2, then if x>1, do not submit.

How does the php code look like for that? I don't have much of a clue.

Posted: Wed Jul 26, 2006 7:34 pm
by kevinoneill
Here's where I'm at. I managed to write this much.

Code: Select all

$count = substr_count($message, 'href');

if ($count > 2) 
    die ();
Problem is... the die kills the rest of the php on the page, I also had to insert it in after the 'message' has been given the value $message, so the content is already shot to the database before it dies....

I need to know how to assign the text inside my text area named 'message' can be assigned as a variable before being sent to the db, and also preventing the info from being sent to the db with out killing all php on the page...

Posted: Wed Jul 26, 2006 7:58 pm
by kevinoneill
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok this works  next problem!!

Code: Select all

if($submit)
{
    putenv('TZ=America/New_York');
    $time=date("F j, Y, g:i a", time());

    $count = substr_count($message, 'href');
    if ($count < 2) {
      $result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
	  "VALUES ('NULL','$name', '$message','$time')");
    }

}
Maybe you can help me with my other big issue. When my user submits, then say wants to reload the page to see if someone else wrote anything, you get the pop-up box asking "do you want to submit this data again?". Is there a way around that? This stems from my question #3.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jul 26, 2006 10:54 pm
by RobertGonzalez
I would recommend using a splash page. Similar to the page on these forums that say that your post has been entered successfully, you know? That way when they get redirected to their posting (or some other page) it is not from a POST (hence getting rid of the repost notice).

Posted: Fri Jul 28, 2006 9:11 pm
by kevinoneill
Well I've made alot of progress (ok i lie someone made alot of progress for me) but I'm at a hault because i get the "can't write to db" error down in the code.

What's wrong? I can't find it....

Code: Select all

<?php 

     
    $badwordlist = array("addbadwirdsere","addbadwirdsere","addbadwirdsere","addbadwirdsere"); 

mysql_connect("xxxxx","xxxx","xxxxx");
mysql_select_db("xxxxxx"); 


    if ($_POST['submit']) { 
        putenv('TZ=America/New_York'); 
        $time = date("F j, Y, g:i a", time()); 


        if (substr_count($_POST['message'],'http') < 2) { 
            $tomanylinks = true; 

        }        



        foreach($badwordlist as $badword) { 
            if (strpos($_POST['message'],$badword)) { 
                $badwordfound = true; 
                break;   
            }        
        }        

        if (!$tomanylinks && !$badwordfound) { 
            $result = mysql_query(" 
                INSERT INTO shoutbox ( 
                    name, 
                    message, 
                    time 
                ) VALUES ( 
                    '{$_POST['name']}', 
                    '{$_POST['message']}', 
                    '$time' 
                )"); 
        }        

        if ($result) { 
            header("Location: {$_SERVER['PHP_SELF']}"); 
        } else { 
            die("FIRST There was an error adding to the shoutbox"); 
        }        
     
    } else { 
        echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">"; 
        echo "  <input id=\"name\" type=\"text\" name=\"name\" />"; 
        echo "  <input type=\"submit\" name=\"submit\" value=\"Submit\" />"; 
        echo "  <textarea rows=\"2\" cols=\"35\" name=\"message\"></textarea>"; 
        echo "</form>"; 
        if ($result = mysql_query("select * from shoutbox order by id desc limit 40")) { 
            while($r = mysql_fetch_array($result)) {     
?> 

<div class="weblog_comment"> 
<div class="weblog_comment_name"><?php echo $r['name'] ?></div> 
<div class="weblog_comment_time"><?php echo $r['time'] ?></div> 
<div class="weblog_comment_message"><?php echo $r['message'] ?><br /><br /></div> 
</div> 

<?php 
} 
        } else { 
            die("SECOND There was an error displaying the shoutbox"); 
        }        
    } 

?>