Deceptive-Logic



Which of the following is used as an icon of American nationalism?




Previous Poll

-Quantumstate
1030 Clicks-
-Pixel2life.com
1852 Clicks-
-Chipmunk PHP Scripts
816 Clicks-
View All - Become one

Copy this code, make the neccessary changes, save as a .php file, upload to your server, and use <? include('filename.php'); ?> where ever you want it to show up (change filename.php to the files actual name).
If you have any questions, just ask on the tutorial help forums.

This is the mySQL table you're gonna need to set up (copy/paste into phpmyadmin):

CREATE TABLE `shoutbox` ( `id` int(11) NOT NULL auto_increment, `message` text NOT NULL, `author` varchar(20) NOT NULL default '', `email` varchar(50) NOT NULL default '', `date` varchar(20) NOT NULL default '', `ip` varchar(20) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=0

This is the code used to display the shouts on whatever page you choose to put it on, name it shout.php

<?
/* database info, or include a config.php file
a config file would just contain the info from $db_host through the mysql_select_db ... )); */
$db_host 'localhost'#change to your host
$db_user 'username'#change to your username
$db_password 'password'#change to your password
$db_name 'database_name'#change to your database name

mysql_connect($db_host,$db_user,$db_password) or die(mysql_error()); 
mysql_select_db($db_name) or die(mysql_error());

/* Set the query and get the last 15 posts, change 15 to how ever many you want, or just remove LIMIT 15. */
$sql mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 15");
while(
$r=mysql_fetch_array($sql)){
    
/* this checks to see if the poster had an email address */
    
if(!$r['email']){
        
$mail "";
    }else{
        
$mail "<a href=\"mailto:$r[email]\">@</a>";
    }
    
/* this checsk to see if the user has a website */
    
if(!$r['site']){
        
$site $r['author'];
    }else{
        
$site "<a href=\"$r[site]\">$r[author]</a>";
    }
    
    
/* This stores the display in a variable for later use. To modify the way the shouts are displayed, edit this.
Date is formated by gmdate() (same as date()), so check php.net to change the way the date is displayed */
    
$shout_block .= "<tr>
    <td>
    <b>$mail $site</b> :"
.gmdate("m/j, g:i a"$r['date']).":
    <br>$r[message]
    <hr></td>
    </tr>"
;
}

/* This will be the table where everhthing's displayed */
echo "<table>
    $shout_block
</table>"
;
?>

This is the code in format everything and insert it into the database, name it shoutbox.php:

<?
/* these clean up the users post and help to prevent spam by removing the white space from the beginning and end of the string */
$author trim($_POST['author']);
$email trim($_POST['email']);
$site trim($_POST['site']);

/* The line below is a very specific matching tool that uses pearl regular expressions, not exactly easy to learn, so don't try to modify it unless you know what you're doing.
The last element of the function is the name of the array that will be filled with matches, easy to change, just change every $sit in this script and you'll be fine */
preg_match("#http://[(www.|)a-z0-9(-|_|)a-z0-9]*.[a-z]*#i"$site$sit);
$message str_replace("\n""<br>"ltrim(rtrim($_POST['message'])));

/* Sets the authors name, an array of "reserved" names, and an array of who can use those names, with what password.
   Then, uses http authentification to log the user in.  It should be simple enough to add more reserved names */
$author trim($_POST['author']);
$names = array('admin''mod''moderator''webmaster');

/* This is who can use the above names. If you need any more info as to how to what exactly this is, search php.net for "array" and you should get your answer */
$admin = array('Name' => 'md5 of users password');

/* This loops through the reserved names to match what the user put in */
foreach($names as $key => $name){
    if(
stristr($author$name)){
        
/* This is where the above array with the "md5 of users password" comes into play. */
        
if($admin[$_SERVER['PHP_AUTH_USER']] != md5($_SERVER['PHP_AUTH_PW'])){
            
header('WWW-Authenticate: Basic realm="Reserved Name"'); // do not edit
            
header('HTTP/1.0 401 Unauthorized'); // do not edit
            
die('Sorry, you need to be authorized to use that name, please try again.');
        }elseif(
$admin[$_SERVER['PHP_AUTH_USER']] == md5($_SERVER['PHP_AUTH_PW'])){
            
$logged true;
            
/* break is used to stop the loop from continuing uneccessarily */
            
break;
        }else{
            
$logged false;
            break;
        }
    }else{
        
$logged true;
    }
}

/* If you notice above, the var $logged is set if you either logged in successfully, or didn't need to log in, just a little more secuirty */
if(!$logged){
    die(
'Sorry, an error has occured during verification, please try again.');
}

/* the include() is for the database connection, if you don't have a config file copy and paste the database info for shout.php
remember to the whole include('config.php'); to the connection info */
include('config.php');

/* this will trim out any white space in the beginning and end of the post, and then make it so when the enter/return key was pressed, it will insert an acctual break */
$message str_replace("\n""<br />"ltrim(rtrim($_POST['message'])));

/* if the submit button was pressed (you need a button named "submit" or the whole thing won't work */
if($_POST['submit']){
    
/* The back link */ 
    
$back "<a href=\"javascript: history.back(-1)\">Back</a>";
    
    
/* simple spam check (very simple... lots of ways around it), !$author just checks to see if $author was filled */
    
if($author == 'Name' || $author == 'user' || $author == 'spam' || !$author){
        die(
"Error! No name entered.<br>$back");
    }
    if((
$site) && (!$sit)){
        die(
"Error! Enter a valid website with 'http://' or no site at all.<br>$back");
    }
    if(
$message == 'Message' || !$message){
        die(
"Error! No message entered<br>$back");
    }

/* strip html tag's, allow only <a>, <i>, and <b> tags
if you wish to add more tags simple add the tag right after <b> (make sure to use a space after <b>) */
$message strip_tags($message'<a> <i> <b>'); 
$email strip_tags($email); 
$author strip_tags($author); 

/* check message length, change "200" to change the limit (including spaces) */
    
$limit 200;
    
$message_length strlen(stripslashes($message));
    if(
$message_length $limit){
        die(
"Messages must be shorter then $limit characters. Your message is: $message_length characters");
    }

/* smilies! in the $smiles array you can probably get this, it goes somewhat like this
"THING_USER_TYPES_IN" => " IMG_LOCATION ",
"ANOTHER_THING" => " ANOTHER_IMAGE "
Don't forget commas. */
$smiles = array(":)" => ' <img src="/images/smilies/icon_smilie.gif" /> ',
                
":(" => ' <img src="/images/smilies/icon_sad.gif" /> ',
                
":D" => ' <img src="/images/smilies/icon_biggrin.gif" /> ');
$message strtr($message$smiles);

/* special date format that will insert a time stamp instead of a time, which allows you to change the way you display time freely */
$date date("U"); 

/* this inserts everything into the database then closes the connection to prevent hacking. */
mysql_query("INSERT INTO shoutbox (message, author, email, date, ip) 
VALUES ('$message','$author','$email','$date','$_SERVER[REMOTE_ADDR]')"
); 
mysql_close(); 

/* thank you page, redirects 5 seconds after the page is loaded. Change the <meta> tag's "content=5" to the number of seconds you want */
echo "<meta http-equiv=refresh content=5;URL=index.php>
Thanks for your post, you will be reditrected in 5 seconds<br><a href=\"/index.php\">Return Home</A> or <a href=\"/shoutbox.php\">View Shoutbox</A>"
;
}else{
    include(
'shout.php');

    
/*** Form to use w/ shoutbox, put this below where you display your shout.php file ***/
    
echo "<form method=POST name=shoutbox action=shoutbox.php>
    <input name=author type=text value=Name maxlength=15><br>
    <input name=email type=text value=E-mail><br>
    <input name=site type=text value=Website><br>
    <textarea name=message cols=18>Message</textarea><br>
    <input type=submit name=submit value=Submit> 
    </form>
    <a href=index.php>Return Home</a>"
;
}
?>