Simple PHP Mass Email System

2 01 2009

This project started out as an attempt to bring some of the people I have talked to, to my website. I exported an Outlook CSV file containing the 1639 different people I have talked to over the years from my Gmail Account. Now I can click a button and import all of those contacts names and emails from from te CSV file to the mysql database, then i run a script that sends out emails to the addresses 10-15 at a time, then it reloads the page using sessions to store the information that is to be sent via email and sends to another 10 or w/e until there are no more emails to send to. This mass email system only took about 30 minutes to write and finish, but I found it useful.

So anytime you want to import contacts from Google to send out mass emails, you know who hooked you up ;)

index.php

<?php
// start session
session_start();

//echo "Page has been disabled. Please remove the restriction.";
//die;

// set the default timezone
date_default_timezone_set('America/Los_Angeles');
/*
the time zone thing ^^^ this is completely not needed....but what the heck,
you just learned something new! Remember it next time your curl script changes your
time setting and you spend like 10 hours trying to figure out what the hell is going on
with your scheduling program... yeah! I just saved you!
*/

// connect to the database
include("config.php"); // connect to the database

// file name to open, change this as desired.
$file = "contacts.csv";

if(!empty($_SESSION['post'])){
$ce = mysql_query("SELECT * FROM emails");
$cce = mysql_num_rows($ce);
if($cce < 1){
session_destroy();
$echo = "There are no more email addresses left to send to!";
}
}

echo $echo;

include("msg_redirect.php"); // the only function that I need....

$reload = $_GET['reload'];

if($reload == "yes"){
echo "<h1>Contacts Being Reloaded</h1>";
//open file and read it retreive information and close the 'connection' to the file.
$fh = fopen($file, 'r');
$content = fread($fh, filesize($file));
fclose($fh);
$content = addslashes($content);
$line = explode("\n",$content);
foreach ($line as $k => $v){

$vs = explode(",",$v); 

$added = mysql_query("INSERT INTO emails (id,name,email) VALUES (id,'$vs[0]','$vs[1]')");
if($added){echo "Success ".$vs[1]."<br />";}else{echo "<b>Error ".$vs[1]."</b><br />";}
}

}elseif($reload == "truncate"){
$trun = mysql_query("TRUNCATE `emails`");
if($trun){echo "Truncaded<br />";}else{echo "<b>Error</b><br />".mysql_error();}

}

if(empty($_SESSION['post']) || !isset($_SESSION['post'])){

foreach ($_POST as $k=>$v){$post .= "$k=$v&";}
$_SESSION['post'] = $post;
}

//echo "Post Line: ".$post."<br />";
//echo "Session Line: ".$_SESSION['post']."<br />";

if(isset($_POST['submit'])){

extract($_POST);

$headers = "From: $fromemail\n";
$headers .= "Reply-To: $fromemail\n";
//$headers .= "BCC: dumidesign@gmail.com";
$headers .= "MIME-Version: 1.0\n";

// send email to all recipiants
$get_emails = mysql_query("SELECT * FROM emails LIMIT 5");
while($age = mysql_fetch_array($get_emails)){
extract($age);

$domail = mail($email, $subject, $message, $headers);
if($domail){
echo "Success Emailing $email! ";
// in the event that an email is sent, we then need to remove it from the database
// so that we don't send to it again in the event that the script times out.

$dodel = mysql_query("DELETE FROM emails WHERE id='$id'");
if($dodel){echo "$email Deleted.";}else{echo "<b>ERROR Deleting $email</b><br />";}
echo "<br />";

}else{echo "<b>ERROR Sending To $email.</b>";}

echo "<br />";

}

msg_redirect("Sending more....","index.php","0");

}elseif(!empty($_SESSION['post'])){
$post = $_SESSION['post'];
$ep = explode("&",$post);

foreach ($ep as $k=>$v){

$vals = explode("=",$v);

${$vals[0]} = $vals[1];
}

$headers = "From: $fromemail\n";
$headers .= "Reply-To: $fromemail\n";
//$headers .= "BCC: dumidesign@gmail.com";
$headers .= "MIME-Version: 1.0\n";

// send email to all recipiants
$get_emails = mysql_query("SELECT * FROM emails LIMIT 5");
while($age = mysql_fetch_array($get_emails)){
extract($age);

$domail = mail($email, $subject, $message, $headers);
if($domail){
echo "Success Emailing $email! ";
// in the event that an email is sent, we then need to remove it from the database
// so that we don't send to it again in the event that the script times out.

$dodel = mysql_query("DELETE FROM emails WHERE id='$id'");
if($dodel){echo "$email Deleted.";}else{echo "<b>ERROR Deleting $email</b><br />";}
echo "<br /><br />";

}else{echo "<b>ERROR Sending To $email.</b>";}

echo "<br />";

//echo "Subject: $subject<br /><br />Message: $message<br /><br />";

}

msg_redirect("Sending more....","index.php","0");

}else{
echo "<center>";
echo "Would you like to reload your contacts into the database? <a href=\"index.php?reload=yes\">YES</a><br /><br />";
echo "Would you like to  <a href=\"index.php?reload=truncate\">truncate</a> your contacts into the database?<br /><br />";
echo "<table width=\"400\" border=\"0\">";
echo "<form method=\"post\" action=\"index.php\">";
echo "<tr><td>Subjet</td><td><input type=\"text\" name=\"subject\" value=\"$subject\" /></td></tr>";
echo "<tr><td>Message</td><td><textarea name=\"message\" rows=\"20\" cols=\"50\"></textarea></td></tr>";
echo "<tr><td>From Name</td><td><input type=\"text\" name=\"fromname\" value=\"$fromname\" /></td></tr>";
echo "<tr><td>From Email</td><td><input type=\"text\" name=\"fromemail\" value=\"$fromemail\" /></td></tr>";
echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Send\" /></td></tr>";

echo "</form>";
echo "</table>";
echo "</center>";
}

?>

msg_redirect.php

<?php

function msg_redirect($msg,$url,$seconds){
echo "<meta http-equiv=\"Refresh\" content=\"$seconds; URL=$url\">
<center>
<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\" width=\"70%\">
<tr><td>Please Wait, redirected in $seconds seconds....</td></tr>
<tr><td align=\"center\">
<br /><br /><img src=\"working.gif\"> $msg<br /><br />
<a href=\"$url\">Click Here If Not Redirected...</a>
<br /><br />
</td></tr></table></center>
<br /><br /><br /><br />";
}

?>

config.php

<?php
$db_host = "localhost";
$db_user = "username";
$db_pass = "password";
$db_database = "emails";

$connect_to_db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_database) or die(mysql_error());

?>

contacts.csv

name,email
name,email
name,email
etc...</pre>
The CSV file name is referred to in the script, feel free to change it to match different files, etc. Be sure that the format, at minimum, is in the format I have above. Acceptable:
<pre>,email@domain.com
name,
name,email
name,email,blah,bla,asdfkjasdfjasdfkajsdf,anything after,
name,email,just make sure that there is a name before the first comma, and an email right after with no extra spaces
name,email, there has to be a newline at the end of each entry as well, ie \n

Just as long as the first entry is a name, or even nothing, then a comma, then an email address. The script itself doesn’t greet anyone by name or anything…I just include it for good measure….in case I want to in the future.

MySQL

-- phpMyAdmin SQL Dump
-- version 2.11.9.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 02, 2009 at 08:53 PM
-- Server version: 4.1.22
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `iluvjohn_test`
--

-- --------------------------------------------------------

--
-- Table structure for table `emails`
--

CREATE TABLE IF NOT EXISTS `emails` (
  `id` int(255) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

--
-- Dumping data for table `emails`
--

The table is pretty basic….nothing extra really.

The script in general is really fast though a lot of it’s speed depends on your servers, etc etc. It sent out 1,639 in just a few minutes…….then I procedded to post the script online. A lot of people have problems with large email lists because PHP times out after 60 seconds most of the time. That is a long time to wait anyways.

Questions and Comments show me I’m loved! Leave me something!

……wait a second, maybe that’s why I never get any comments……..damnit!

Written by: John Minton



Simple CMS - PHP MySQL

2 01 2009

After years of learning PHP I decided one day that I wanted a simple content management system that would allow me the flexibility of just having to set up the website through an administrative back end and a design. I started on this endeavor, but I got lazy. While I did finish most of the basics, I didn’t put together the Administrative back end yet, and I SUCK at design. The site is supposed to be XHTML compliant, you may want to check through index.php to make sure that everything is correct. I tried to do pretty URLS with my .htaccess file, but then the other $_GET variables would not work, and I kind of gave up on it. BUT the good news is that it is still an excellent system that is clean and runs fast.

The back end of the PHP system is completely run from mysql, down to the PHP in the website’s individual pages. To edit, update, or program a new page is effortless while the control and flexibility remains in tack. Below I will give you all you need to run this on your own server. Please send me any changes or modifications you do so that I may share them as well. Oh, also, If we could develop some sort of plugin system somewhere along the road, that would be excellent!

Index.php

<?php 

// Start our sessions
session_start();

// connect to the database
include("config.php");

// Set Static Variables
$set_vars = mysql_query("SELECT * FROM sitevars");
while($asv = mysql_fetch_array($set_vars)){
extract($asv);
${$k} = $v;
unset($k);
unset($v);
unset($whatitis);
}

// If debug equals true then tell user the debug is on...
if($debug == "true"){echo "<b>Debugging Enabled!</b><br />".__LINE__;}
if($function_debug == "true"){echo "<b>Function Debuging Enabled!</b><br /> Line ".__LINE__;}

// go through the database and pull out all the functions
// depending on if function_debug is on, we are gonne pull out the descriptions of each function and display them or not.
if($function_debug == "true"){$get_functions = mysql_query("SELECT * FROM functions");}else{$get_functions = mysql_query("SELECT content FROM functions");}

if($function_debug == "true"){echo "List Of Active Functions:<br /><br />Line ".__LINE__;}

while($agf = mysql_fetch_array($get_functions)){
if($function_debug == "true"){echo "<b>$name</b>: $description<br /><hr /><br />Line ".__LINE__;}
// name 	description 	content
extract($agf);
eval($content);
}
unset($content);

// get the page and set its vars
//$page = $_GET['page'];

$page = $_SERVER['REQUEST_URI'];
$page = stripslashes($page);
$page = str_replace("/","",$page);
$page = str_replace("\\","",$page);
if(empty($page)){$page = "home";}
if($page == "logout"){session_destroy();}

$get_page = mysql_query("SELECT * FROM pages WHERE page='$page' LIMIT 1");
$cgp = mysql_num_rows($get_page);
if($cgp > 0){
$agp = mysql_fetch_array($get_page);
// page 	title 	heading 	content 	meta_keys 	meta_description
extract($agp);

$page_content = $content;

}else{
// page 	title 	heading 	content 	meta_keys 	meta_description
$page = "Page Does Not Exsist!";
$title = "Page Does Not Exsist!";
$heading = "Page Does Not Exsist!";
$page_content = "echo \"<br /><br />Sorry, but this page doesn't exsist......It is imaginary. Please go back and try again. Broken links will be automatically reported very soon.<br /><br />\";";
$meta_keys = "Page Does Not Exsist!";
$meta_description = "Page Does Not Exsist!";
}

unset($content);

// Login is done here....if the user decides to log in.
if(isset($_POST['login'])){
$email = $_POST['email'];
$password = $_POST['password'];

// check user and pass from the db
$check_user = mysql_query("SELECT * FROM users WHERE email='$email' && password='$password' LIMIT 1");
$ccu = mysql_num_rows($check_user);
if($ccu > 0){
$acu = mysql_fetch_array($check_user);
extract($acu);
$_SESSION['userid'] = $userid;
$login_msg = "Your Login Was successful!";
}else{
$login_msg = "Sorry, but your login failed. Please try again.";
}
}

// if user is logged in, set user info
if(!empty($_SESSION['userid'])){

$userid = $_SESSION['userid'];
$gui = mysql_query("SELECT * FROM users WHERE userid='$userid' LIMIT 1");
$cui = mysql_num_rows($gui);

if($cui > 0){
$aui = mysql_fetch_array($gui);
extract($aui);
// userid firstname lastname email ip admin
$_SESSION['userid'] = $userid;
$_SESSION['admin'] = $admin;

}else{
session_destroy();
}
}

$user_messages = "$login_msg<br />";

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html><head>";
echo "<title>$site_title - $title</title>";
echo "<meta name=\"keywords\" content=\"$meta_keys\">
<meta name=\"description\" content=\"$meta_description\">
<meta name=\"author\" content=\"$author_name\">
<meta name=\"copyright\" content=\"$copyright_year\">
<meta name=\"contact\" content=\"$author_contact\">";

if($use_google_verification == "true"){echo "<meta name=\"$google_verification_name\" content=\"$google_verification_content\" />";}

echo "<style type=\"text/css\">";

// getting the style sheet, if it doesnt exist, then use default style sheet.

$get_style = mysql_query("SELECT * FROM styles WHERE style='$style' LIMIT 1");

if($debug == "true"){echo "Selected Style: <b>$style</b><br /><hr /><br />Line ".__LINE__;}
$cgs = mysql_num_rows($get_style);
if($cgs > 0){

$ags = mysql_fetch_array($get_style);

extract($ags);
echo $content;
}else{
if($debug == "true"){echo "<i>Selected Style Sheet does't exsist. Going to default.</i><br />Line ".__LINE__;}

$style = "default";

$get_style = mysql_query("SELECT * FROM styles WHERE style='$style' LIMIT 1");
if($debug == "true"){echo "Default Selected Style: <b>$style</b><br /><hr /><br />Line ".__LINE__;}
$cgs = mysql_num_rows($ge_style);
if($cgs > 0){

$ags = mysql_fetch_array($get_style);

extract($agf);
echo $content;
}else{
if($debug == "true"){echo "No style Sheet could be found, none selected! Line ".__LINE__;}
}
}

echo "</style>";
echo "</head><body>";

echo "<div id=\"wrap\">";

echo "<div id=\"header\">";
echo "<h1>$site_name</h1>";
echo "<h2>$subcap</h2>";
echo "</div>";

echo "<br class=\"clear\">";

if($show_ads == "true"){
echo "<div id=\"ads_sky\">";
// ads_ground
include("ad/index.php");
echo "</div>";
}

if($nav_menu == "true"){
echo "<div id=\"menu\">";
// put the menu here

$get_menu = mysql_query("SELECT * FROM menu ORDER BY mid ASC");
$cgm = mysql_num_rows($get_menu);
if($cgm > 0){
echo "<ul>";
while($agm = mysql_fetch_array($get_menu)){
extract($agm);
// mid text link target id class alt include_domain showup

if($showup == "b"){

echo "<li><a href=\"";
if($include_domain == "true"){echo $domain;}
echo "$link\" target=\"$target\" id=\"$id\" class=\"$class\" alt=\"$alt\">$text</a></li>";

}elseif($showup == "l" && !empty($_SESSION['userid'])){

echo "<li><a href=\"";
if($include_domain == "true"){echo $domain;}
echo "$link\" target=\"$target\" id=\"$id\" class=\"$class\" alt=\"$alt\">$text</a></li>";

}elseif($showup == "n" && empty($_SESSION['userid'])){

echo "<li><a href=\"";
if($include_domain == "true"){echo $domain;}
echo "$link\" target=\"$target\" id=\"$id\" class=\"$class\" alt=\"$alt\">$text</a></li>";

}
}
}
echo "</ul>";
echo "</div>";
}

echo "<div id=\"content\">";
if($display_page_titles == "true"){echo "<h2>".$heading."</h2>";}

// eval the page, $page_content
eval($page_content);

echo "</div>";

if($show_ads == "true"){
echo "<div id=\"ads_ground\">";
// ads_ground
include("ad/index.php");
echo "</div>";
}

echo "<br class=\"clear\">";

if(!empty($user_messages)){echo "<div id=\"messages\">$user_messages</div>";}

echo "<div id=\"footer\">";

$date_year = date("Y");

if($date_year > $copyright_year){$copyright_text = "$copyright_year - $date_year";}else{$copyright_text = "$copyright_year";}

echo "&copy; Copyright $copyright_text $copyright_name";
echo "<br />".$footer_text;

echo "</div>";

echo "</div>";

include("google_analytics.php");

echo "</body></html>";

?>

You can see how we dynamically pull out variables from the database to use as flags or basic text across the site. We also loop through the functions, pull out a set style, etc etc. The entire website can be set up through the mysql database. In this manner, we can write code and styles for the entire website through an administrative panel (coming some time in the future…). Very little actual files will be needed, as most everything is in the database. I personally find that things in the database are organized to an extent where as file structures are unorganized and quite irritating to manage. With all your pages in the database, for example, you can write a small php script to go through and change the format of your links, or what have you, faster and simpler than writing out script to read and write to files.

Config.php

<?php

if(strrpos($_SERVER['REQUEST_URI'],"config")){
echo "The string 'config' is not allowed in the url, ever.";
}else{

$host = "localhost";
$user = "scmsuser";
$pass = "scmspassword";
$database = "scms";

// save our retrieved variable info from the form to the database
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
//echo "Beta Mode! - Connected! ".$database;
}
?>

google_analytics.php

Essentially, you only want to put your Google analytics code into this file….it’s a spot of any analytics code really.

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-4535973-5");
pageTracker._trackPageview();
</script>

MySQL Tables

Here are the MySQL tables that you need. Feel free to replace what ever you need to fit your needs. Again, if anyone writes, or wants to write, an administrative back end, I would be happy to hear from you!

-- phpMyAdmin SQL Dump
-- version 2.11.9.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 25, 2008 at 11:10 PM
-- Server version: 4.1.22
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `iluvjohn_site`
--
CREATE DATABASE `scms` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `scms`;

-- --------------------------------------------------------

--
-- Table structure for table `actions`
--

CREATE TABLE IF NOT EXISTS `actions` (
  `action` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `system` varchar(255) NOT NULL default '',
  `do_action` text NOT NULL,
  PRIMARY KEY  (`action`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `actions`
--

INSERT INTO `actions` (`action`, `description`, `system`, `do_action`) VALUES
('newboard', 'This will create a new board for the Home / Communication Page.\r\n\r\n\r\nDisplays a form that posts info to the newboard action. This then inserts a new board into the database with the specs specified.', 'blog', 'if(!empty($_SESSION[''userid'']) && $_SESSION[''admin''] == "y"){\r\n\r\nfunction newboard_form(){\r\nglobal $name,$description,$page;\r\n// catid 	name 	description 	useri \r\necho "<form method=\\"post\\" action=\\"$page?action=newboard\\">";\r\necho "<label>Board Name:</label> <input type=\\"text\\" name=\\"name\\" value=\\"$name\\" /><br class=\\"clear\\">";\r\necho "<label>Content:</label> <textarea name=\\"description\\" style=\\"width:650px; height:300px;\\">$description</textarea><br class=\\"clear\\">";\r\necho "<label></label> <input type=\\"submit\\" name=\\"newboard_submit\\" value=\\"Create Board\\" /><br class=\\"clear\\">";\r\necho "</form>";\r\n}\r\n\r\n\r\nif(isset($_POST[''newboard_submit''])){\r\necho "here";\r\n$useri = $_SESSION[''stats_user''];\r\n// catid,name,description,useri\r\nextract($_POST);\r\n\r\n$add_newboard = mysql_query("INSERT INTO talk_cats (catid,name,description,useri) VALUES (catid,''$name'',''$description'',''$useri'')");\r\n\r\nif($add_newboard){\r\nmsg_redirect("Success!","$page","0");\r\n}else{\r\necho "An Unidentified Error has occured! Sorry for the inconvience, Please Try Again. Thanks.<br /><br />";\r\nnewboard_form();\r\n}\r\n\r\n}else{newboard_form();}\r\n\r\n}else{\r\nmsg_redirect("Sorry, only admins allowed here...","$page","0");\r\n}'),
('newcomment', 'This is used to reply to a post with a comment.\r\n\r\n', 'blog', '$cat = $_GET[''board_id''];\r\n\r\nfunction comment_form(){\r\nglobal $name,$description,$cat,$page;\r\n// id cat talk user date\r\necho "<form method=\\"post\\" action=\\"$page?action=newcomment&board_id=$cat\\">";\r\necho "<label>Comment:</label> <textarea name=\\"talk\\" style=\\"width:650px; height:300px;\\">$talk</textarea><br class=\\"clear\\">";\r\necho "<input type=\\"hidden\\" name=\\"cat\\" value=\\"$cat\\" /><br class=\\"clear\\">";\r\necho "<label></label> <input type=\\"submit\\" name=\\"comment_submit\\" value=\\"Post Comment\\" /><br class=\\"clear\\">";\r\necho "</form>";\r\n}\r\n\r\n\r\nif(isset($_POST[''comment_submit''])){\r\n$userid = $_SESSION[''userid''];\r\n// id cat talk user date\r\nextract($_POST);\r\n\r\n$add_newboard = mysql_query("INSERT INTO talks (id,cat,talk,user,date) VALUES (id,''$cat'',''$talk'',''$userid'',''$unix_date'')");\r\n\r\nif($add_newboard){\r\nmsg_redirect("Success!","$page","0");\r\n}else{\r\necho "An Unidentified Error has occured! Sorry for the inconvience, Please Try Again. Thanks.<br /><br />";\r\ncomment_form();\r\n}\r\n\r\n}else{\r\n\r\nif(empty($_SESSION[''userid''])){\r\necho "Please Login to post a comment!<br /><br />";\r\nlogin();\r\n}else{\r\ncomment_form();\r\n}\r\n}'),
('deletecomment', 'This will delete a comment off of the boards. You can only delete your own comments.', 'blog', '$confirm = $_GET[''confirm''];\r\n$comment_id = $_GET[''comment_id''];\r\n\r\nif(empty($comment_id)){\r\nmsg_redirect("Comment ID is empty.","$page","5");\r\n\r\n}else{\r\n\r\n$get_comment_info = mysql_query("SELECT * FROM talks WHERE id=''$comment_id'' LIMIT 1");\r\n$cgci = mysql_num_rows($get_comment_info);\r\nif($cgci > 0){\r\n$agci = mysql_fetch_array($get_comment_info);\r\nextract($agci);\r\n//id,cat,talk,user,date\r\nif($user == $_SESSION[''userid''] || $_SESSION[''admin''] == "y"){\r\n\r\nif(!empty($confirm)){\r\nif($confirm == "yes"){\r\n\r\n//delete the comment\r\n$do_del = mysql_query("DELETE FROM talks WHERE id=''$comment_id'' LIMIT 1");\r\n\r\nif($do_del){\r\nmsg_redirect("Comment Deleted!","$page","0");\r\n}else{\r\nmsg_redirect("ERROR! Sorry, there was an unidentified error. Please Try Again. Sorry, Thanks.","$page","5");\r\n}\r\n}else{\r\nmsg_redirect("Going Back...","$page","0");\r\n}\r\n\r\n}else{\r\necho "Are You Sure?";\r\necho "<table bgcolor=\\"eeeeee\\" width=\\"550\\"><tr><td>";\r\necho "<a href=\\"$page?action=deletecomment&comment_id=$id&confirm=yes\\">Yes</a><br /><br />";\r\necho "$talk</td></tr></table><br />";\r\n}\r\n}else{\r\nmsg_redirect("You can''t delete someone else''s comments.","$page","5");\r\n}\r\n\r\n\r\n}else{msg_redirect("Comment ID doesn''t exsist, Please Try Again.","$page","5");}\r\n\r\n}');

-- --------------------------------------------------------

--
-- Table structure for table `functions`
--

CREATE TABLE IF NOT EXISTS `functions` (
  `name` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `content` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `functions`
--

INSERT INTO `functions` (`name`, `description`, `content`) VALUES
('Message Redirect', 'User is shown a message and sent the the page specified. This uses the HTML meta refresh tag.\r\n\r\n\r\nUse: \r\n\r\n$seconds = 3;\r\n$url = "http://www.site.com/page.php";\r\n$msg = "You are being logged in!";\r\n\r\nmsg_redirect("$msg","$url","$seconds");\r\n', '\r\nfunction msg_redirect($msg,$url,$seconds){\r\necho "<meta http-equiv=\\"Refresh\\" content=\\"$seconds; URL=$url\\">\r\n<center>\r\n<table cellpadding=\\"1\\" cellspacing=\\"1\\" border=\\"1\\" width=\\"70%\\">\r\n<tr><td>Please Wait, redirected in $seconds seconds....</td></tr> \r\n<tr><td align=\\"center\\">\r\n<br /><br /><img src=\\"../working.gif\\"> $msg<br /><br />\r\n<a href=\\"$url\\">Click Here If Not Redirected...</a>\r\n<br /><br />\r\n</td></tr></table></center>\r\n<br /><br /><br /><br />";\r\n\r\n}'),
('Login', 'This is the form that users use to log in with.', 'function login(){\r\nglobal $page,$login_msg;\r\n\r\necho $login_msg."<br />";\r\n\r\necho "<form method=\\"post\\" action=\\"$page\\">\r\n<table style=\\"width: 300px;\\" width=\\"145\\" border=\\"0\\" bgcolor=\\"eeeeee\\">\r\n<tr bgcolor=\\"dddddd\\"><th colspan=\\"2\\" align=\\"left\\">LOGIN</th></tr>\r\n<tr bgcolor=\\"eeeeee\\"><td style=\\"width: 45px;\\">Email:</td><td style=\\"width: 100px;\\">\r\n<input type=\\"text\\" name=\\"email\\" value=\\"";\r\nif(!empty($_COOKIE[''user_email''])){echo $_COOKIE[''user_email''];}\r\necho "\\" class=\\"log\\" style=\\"width: 250px;\\" /></td></tr>\r\n<tr bgcolor=\\"eeeeee\\"><td>Pass:</td><td><input type=\\"password\\" name=\\"password\\" value=\\"\\" class=\\"log\\" style=\\"width: 250px;\\" /></td></tr>\r\n<tr bgcolor=\\"eeeeee\\"><td colspan=\\"2\\">\r\n<center><a href=\\"index.php?id=forgot_pwd\\"><img src=\\"images/forgot_pwd.gif\\" alt=\\"Forgot Password\\" /> Forgot Password</a></center><br />\r\n</a><input type=\\"submit\\" name=\\"login\\" value=\\"Login\\">\r\n</td></tr></table>\r\n</form>";\r\n\r\n\r\n}'),
('blog', 'This is the basic blog / post & comment function. Place this function once in a page.\r\n\r\nRequired Tables:\r\ntalk\r\ntalk_cats\r\nactions\r\n', 'function blog(){\r\nglobal $page,$userid;\r\n\r\n$action = $_GET[''action''];\r\n\r\n//$_SESSION[''userid''] = "1";\r\n//$_SESSION[''admin''] = "y";\r\necho "<h1>Action: $action</h1>";\r\n  \r\nif(!empty($action)){\r\n// go into action database and execute an actions\r\n$get_action = mysql_query("SELECT action,do_action FROM actions WHERE action=''$action'' && system=''blog''");\r\n$cga = mysql_num_rows($get_action);\r\nif($cga > 0){\r\necho "<h2>Actions > $action</h2>";\r\n$aga = mysql_fetch_array($get_action);\r\nextract($aga);\r\n// \r\neval($do_action);\r\n}else{msg_redirect("ERROR! Action Doesn''t Exsist. Please Try Again...","$page","5");}\r\n}else{\r\n\r\n\r\nif(!empty($_SESSION[''userid'']) && $_SESSION[''admin''] == "y"){\r\necho "<div align=\\"right\\"><h3><a href=\\"$page?action=newboard\\">New Post</a></h3></div>";\r\n}\r\n\r\n$get_ctalks = mysql_query("SELECT * FROM talk_cats ORDER BY name ASC");\r\nwhile($agct = mysql_fetch_array($get_ctalks)){\r\nextract($agct);\r\n// catid 	name 	description  useri\r\n\r\n$get_user = mysql_query("SELECT * FROM users WHERE userid=''$useri'' LIMIT 1");\r\n$agu = mysql_fetch_array($get_user);\r\nextract($agu);\r\n// userid	email	password firstname lastname\r\n$description = nl2br($description);\r\n\r\necho "<h3>$name</h3>";\r\necho "<strong>$firstname $lastname</strong> said:<br />$description";\r\n\r\n\r\n\r\n\r\n$get_talks = mysql_query("SELECT * FROM talks WHERE cat=''$catid'' ORDER BY date DESC");\r\n$cgt = mysql_num_rows($get_talks);\r\necho "<h3><b>$cgt</b> Comments</h3>";\r\n\r\n\r\necho "<hr /><div align=\\"right\\"><h3><a href=\\"$page?action=newcomment&board_id=".$catid."\\">New Comment</a></h3></div>";\r\n\r\n\r\nif($cgt > 0){\r\n\r\n  echo ''<div id="comments"><ol>'';\r\n\r\n    while($agt = mysql_fetch_array($get_talks)){\r\n      extract($agt);\r\n      $talk = nl2br($talk);\r\n      // id 	cat 	talk 	user \r\n      $get_user = mysql_query("SELECT * FROM users WHERE userid=''$user'' LIMIT 1");\r\n      $agu = mysql_fetch_array($get_user);\r\n      extract($agu);\r\n      // userid	email	password firstname lastname\r\n       \r\n      \r\n      echo "<li><label><strong>$firstname $lastname</strong> said:</label>";\r\n      echo $talk;\r\n      if($user == $_SESSION[''userid''] || $_SESSION[''admin''] == "y"){echo " &nbsp;[ <a href=\\"$page?action=deletecomment&comment_id=$id\\">Delete Your Comment</a> ]";}\r\n      echo ''<br class="clear" />'';\r\n      echo "</li>";\r\n    }\r\n    \r\n  echo "</ol></div><!--/comment-->";\r\n\r\n}else{echo "Nothing Said Yet...";}\r\necho "<br /><hr height=\\"2\\" color=\\"0000ff\\" /><br />";\r\n\r\n\r\n}\r\n}\r\n\r\n \r\n}');

-- --------------------------------------------------------

--
-- Table structure for table `menu`
--

CREATE TABLE IF NOT EXISTS `menu` (
  `mid` int(255) NOT NULL default '0',
  `text` varchar(255) NOT NULL default '',
  `link` text NOT NULL,
  `target` varchar(255) NOT NULL default '',
  `id` varchar(255) NOT NULL default '',
  `class` varchar(255) NOT NULL default '',
  `alt` varchar(255) NOT NULL default '',
  `include_domain` enum('true','false') NOT NULL default 'true',
  `showup` enum('l','n','b') NOT NULL default 'l'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `menu`
--

INSERT INTO `menu` (`mid`, `text`, `link`, `target`, `id`, `class`, `alt`, `include_domain`, `showup`) VALUES
(0, 'Home', 'home', '', '', '', 'Home', 'true', 'b'),
(10, 'PHP Archives', 'php-archives', '', '', '', 'PHP Archives', 'true', 'b'),
(20, 'Contact', 'contact', '', '', '', 'Contact Us', 'true', 'b'),
(30, 'Register', 'register', '', '', '', 'Register With Us', 'true', 'n'),
(40, 'Login', 'login', '', '', '', 'Login', 'true', 'n'),
(40, 'Logout', 'logout', '', '', '', 'Logout', 'true', 'l'),
(15, 'Blog', 'blog', '', '', '', 'Blog', 'true', 'b');

-- --------------------------------------------------------

--
-- Table structure for table `news`
--

CREATE TABLE IF NOT EXISTS `news` (
  `news_id` int(255) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `article` text NOT NULL,
  `author` varchar(255) NOT NULL default '',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  `visible` enum('yes','no') NOT NULL default 'no',
  `adminid` varchar(255) NOT NULL default '',
  `ip` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`news_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `news`
--

INSERT INTO `news` (`news_id`, `title`, `article`, `author`, `date`, `visible`, `adminid`, `ip`) VALUES
(1, 'Welcome To Simple CMS', 'Welcome! This is Simple CMS 1.0 by John Minton. You can find information on this release, and the original source code at http://www.iluvjohn.com.', 'ILuvJohn.Com', '2009-01-01 22:08:41', 'yes', '1', '0.0.0.0');

-- --------------------------------------------------------

--
-- Table structure for table `pages`
--

CREATE TABLE IF NOT EXISTS `pages` (
  `page` varchar(255) NOT NULL default '',
  `title` varchar(255) NOT NULL default '',
  `heading` varchar(255) NOT NULL default '',
  `content` text NOT NULL,
  `meta_keys` text NOT NULL,
  `meta_description` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `pages`
--

INSERT INTO `pages` (`page`, `title`, `heading`, `content`, `meta_keys`, `meta_description`) VALUES
('logout', 'Logout', 'Logout', 'msg_redirect("You are logged out!","home","3");', 'log, out, log out, logout, Log Out of ILJ, Logout of ILJ, byebye, bye, bye bye', 'Log out of ILuvJohn.Com.'),
('contact', 'Contact ILJ', 'Contact ILJ', 'echo "We''d probably take the time to put up a contact page, but were too fuckin lazy. HA! No, just haven''t gotten to it yet. In the mean time email me: <b>john [at] iluvjohn [dot] com</b>";', 'php, mysql, php contact form, download php code, free contact form, php mysql tutorials', 'We have free downloads and code samples from PHP expert John Minton. Learn how to code, or find the answer to the toughest of questions right here. COMPLETE PHP and MySQL CMS and PHP MySQL tutorials - download, modify and use right now!'),
('blog', 'Blog', 'Blog', 'blog();', 'blog, rant, rave, what I think, the way it is', 'This is my blog.'),
('login', 'Login', 'Login', 'if(!empty($_SESSION[''userid''])){\r\n\r\nmsg_redirect("You are logged in!","home","5");\r\n\r\n}else{\r\nlogin();\r\n}', 'log, in, log in, login, php, mysql, free login, php login, download login system', 'This is a complete free CMS for developers, to makes their life easier. Logins, blogs, content managements, profiles, etc All done from one nice page.'),
('home', 'Home', 'Welcome!', 'echo "Welcome To Simple CMS By John Minton!<br /><br />As of right now, you can edit the site from your database administration tool, such as PHPMyAdmin. Look at the users table for your administrative username and password, feel free to change any values there. The blog kind of works, but it is still kind of messed up / not finished. The links need to point to index.php?page=pagename, instead of just pagename, as they are now.\r\n\rAny changes, comments suggestions, etc can be sent to John Minton at ILuvJohn.Com. Credit will be given with your name, back links, articles on other sites, whatever you want.\r\n\rEdit the most basic and general settings for the wesite in the table, sitevars. Also edit your style sheet's in the style table.\r\n\rThanks for checkin it out. Peace.";\r\n\r\necho "Right now, we are under construction!! I am developing this website from the ground up in my spare time. I deleted nearly everything I had before and started over because I wanted something universally unique, fun, challenging and most of all, I wanted something that I could share with the world. That is the long term here.....<br /><br />";\r\n\r\necho "This website represents me in many ways. First and foremore this is where \r\nI share things I have learned. Coding tips to video games and moding to any \r\nmiscellaneous thoughts.<br /><br />";\r\n\r\necho "My primary goal here is one thing: <b>To keep the internet free</b>. Too \r\noften I may be surfing for some piece of information and am bombarded with \r\nonline stores and large amounts of advertisements. While I understand this, and \r\neven plan to have some ads of my own on this page, I find that there are more \r\nads than information. I counted that i saw 36 ads tonight before I found the piece \r\nof info I was looking for (regarding ps2 modifications)....that is kind of a \r\nlame price to pay.<br /><br />";\r\n\r\necho "This is my 2 cents worth, please enjoy every last piece of it!<br /><br />"; \r\n', 'ILJ, I Luv John, ILuvJohn, smart people', 'John''s blog, John''s ideas, John''s everything!');

-- --------------------------------------------------------

--
-- Table structure for table `sitevars`
--

CREATE TABLE IF NOT EXISTS `sitevars` (
  `k` varchar(255) NOT NULL default '',
  `v` text NOT NULL,
  `whatisit` text NOT NULL,
  PRIMARY KEY  (`k`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `sitevars`
--

INSERT INTO `sitevars` (`k`, `v`, `whatisit`) VALUES
('domain', 'http://domain.com/', 'Just type in your website''s domain, where this script will be hosted at, or run from.\r\n\r\nexample:\r\n(use full urls)\r\n\r\nhttp://www.google.com/\r\nhttp://www.iluvjohn.com/\r\n\r\netc\r\n\r\nDont forget to add the trailing slash!'),
('site_name', 'site_name', 'This will be in the H1 tags at the top of every page, this is what Google and other search Engines will see. Using CSS this can be moved out of view, but it is important for good search engine rankings.\r\n\r\nThis is the heading/title/name of your website.'),
('subcap', 'sub caption.', 'This is your websites "sub caption" this will go at the top of every page.\r\n\r\nIE:\r\n\r\n"\r\nWhere you find what you are looking for\r\n"\r\n\r\nsomething like that....'),
('debug', 'false', 'If set to\r\n\r\ntrue\r\n\r\nthen a lot of information will show on the screen to help you when debugging the website.\r\n\r\nOptions:\r\n\r\ntrue\r\nfalse\r\n'),
('disabled', 'false', 'This will ''disable'' the website, and only let people go to the first page. This will also disable the login. \r\n\r\nValues:\r\ntrue\r\nfalse\r\n\r\n\r\nYou can change the message that is shown on the front page with the variable "disabled_message".'),
('disabled_message', 'We apologize but the website has been disabled for maintainence. Please try again at a later date.', 'This is the message that will show on the front page when the "disabled" flag is set to true. Any valid XHTML can go here and will be printed on the screen.\r\n\r\nExample:\r\n"\r\nWe apologize but the website has been disabled for maintainence. Please try again at a later date.\r\n"'),
('nav_menu', 'true', 'If set to false, then navigation menu will disappear.'),
('login', 'true', 'If set to true the login box will show up on the website. I suggest making a login page with the login function on it....your call. Just use the Login function:\r\n\r\nlogin();\r\n\r\n\r\nThe rest of the validation, etc is done at the top of index.php'),
('show_ads', 'true', 'if set to true, any ads you may have will show up.'),
('site_title', 'site title', 'This is the title of the site, which goes in the blue bar at the top of the page....on the browsers title.\r\n\r\nThis will be put between the title tags before the specific pages title info:\r\n\r\n<title>Your Site Title Here - You are on the Home Page!</title>'),
('google_verification_content', '', 'If you use Google analytic''s or other system that uses meta tags to validate you are the owner of the website, the you will want to add your info here.\r\n\r\nIE\r\n\r\n<meta type=\\"verify-v1\\" content=\\"sdfkj23kjne2okfmdwsi0-d=f-3\\">'),
('copyright_year', '2007', 'This will show up on the footer of every page....its pretty self explanatory. If the year put here is less than the actual year, it will automatically be hyphenated.'),
('author_contact', 'email@domain.com', 'The email address of the Author of the website.'),
('author_name', 'Website Author Name', 'The name of the author of the website.'),
('style', 'default', 'This is the name of the style sheet you are going to use on the website. The styles you can choose from are located in the table called "styles". You can even add your own if you wish, or edit existing ones.\r\n\r\n'),
('function_debug', 'false', 'if function_debug is on, then you will get a list of all the functions and what they do....it will allow you to get more detailed information if an error occurs within a function.\r\n\r\noptions:\r\n\r\ntrue\r\nfalse\r\n\r\nnormal use: set to false'),
('copyright_name', 'copyright_name\r\n', 'This is the name at the bottom of the page that says \r\n\r\nCopyright NAME 2009\r\n\r\nor w/e.....the name is what we are modifying here'),
('footer_text', 'Other Projects: <a href="http://norcalbands.com" target="_blank">NorcalBands.Com</a> and <a href="http://iluvjohn.com" target="_blank">ILuvJohn.Com</a>', 'The text you type here will be echo;d on the page below the copyright info at the footer.\r\n\r\nany valid xhtml can go here\r\n\r\nie\r\n\r\n&copy; Copyright 2007 ILuvJohn\r\n<a href=\\"http://www.otherwebsite.com\\">Other website...</a>'),
('display_page_titles', 'true', 'If set to true, this will display the "heading" of each page right above the content in <h2></h2> tags. If set to false, you may have to add the heading in each page when writing the pages.'),
('use_google_verification', 'flase', 'If set to true, then a custom meta tag will be added.\r\n\r\nIE\r\nGoogle use a meta tag verification scheme to verify that you are the correct owner of your website. The meta tags I have used in the past look like:\r\n\r\n<b><meta name="verify-v1" content="nd_randomchars__" /></b>\r\n\r\nThe name and content values of this tag can be edited with the \r\n\r\ngoogle_verification_name\r\n\r\nand\r\n\r\ngoogle_verification_content\r\n\r\n\r\nThis var, $use_google_verification, must be set to true to enable it.'),
('google_verification_name', '', 'This is the name field of the google verification meta tag. use_google_verification must be set to true for this to work.');

-- --------------------------------------------------------

--
-- Table structure for table `styles`
--

CREATE TABLE IF NOT EXISTS `styles` (
  `style` varchar(255) NOT NULL default '',
  `content` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `styles`
--

INSERT INTO `styles` (`style`, `content`) VALUES
('default', '#wrap {\r\nbackground:#ffcccc;\r\n}\r\n\r\n#header {\r\nbackground:#ccccff;\r\n}\r\n\r\n#menu {\r\nbackground:#ffffcc;\r\n}\r\n\r\n#content {\r\nbackground:#ccffcc;\r\n}\r\n\r\n#ads_ground {\r\nbackground:#cccccc;\r\n}\r\n\r\n\r\n#ads_sky {\r\nbackground:#ffccff;\r\n}\r\n\r\n#messages {\r\nbackground:#999999;\r\n}\r\n\r\n#footer {\r\nbackground:#ccffff;\r\n}\r\n\r\n\r\n'),
('johns', 'body {\r\ndisplay: block;\r\nmargin: 0px auto;\r\nfont-family: verdana,arial;\r\nbackground: #111111 url(''http://iluvjohn.com/images/bg.gif''); \r\nfont-size: 11px;\r\n}\r\n\r\n\r\n#wrap {\r\n\r\n}\r\n\r\n\r\n#header {\r\n\r\n}\r\n\r\n\r\n#menu {\r\n\r\n}\r\n\r\n\r\n#content {\r\n\r\n}\r\n\r\n\r\n\r\n#footer {\r\n\r\n}\r\n');

-- --------------------------------------------------------

--
-- Table structure for table `talk_cats`
--

CREATE TABLE IF NOT EXISTS `talk_cats` (
  `catid` int(255) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `useri` int(255) NOT NULL default '0',
  PRIMARY KEY  (`catid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `talk_cats`
--

INSERT INTO `talk_cats` (`catid`, `name`, `description`, `useri`) VALUES
(1, 'This is the crappiest blog ever created.....', 1);

-- --------------------------------------------------------

--
-- Table structure for table `talks`
--

CREATE TABLE IF NOT EXISTS `talks` (
  `id` int(255) NOT NULL auto_increment,
  `cat` int(255) NOT NULL default '0',
  `talk` text NOT NULL,
  `user` int(255) NOT NULL default '0',
  `date` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

--
-- Dumping data for table `talks`
--

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `userid` int(255) NOT NULL auto_increment,
  `firstname` varchar(255) NOT NULL default '',
  `lastname` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `password` varchar(255) NOT NULL default '',
  `ip` varchar(255) NOT NULL default '',
  `admin` enum('y','n') NOT NULL default 'n',
  PRIMARY KEY  (`userid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`userid`, `firstname`, `lastname`, `email`, `password`, `ip`, `admin`) VALUES
(1, 'Admin', '', 'email@domain.com', 'password', '', 'y');

There a few things that are buggy with the blog, and stuff like that, due to the pretty urls, etc. All the links in the actions table and in the blog function (acctually, all the link across the whole site) need to be changed to the index.php?page=pagename format. To keep page code clean, I like to have an actions table that has all the extra actions pages can do. It makes things pretty nice for me when trying to find a piece of naughty code.

What you have here is the foundation for a Simple CMS that can accomidated nearly any need. The goal for it in the future is for each page to be coded into a function, and the pages in the database just pull out that function. This would making things extremely controlled as well. There are a lot of ideas that float around, too many actually.

Thanks for checkin it out and get back to me on it if you want! Thanks!

Written by: John Minton



Free Wireless Internet?

2 01 2009

I have neard many rumors lately regarding the DTV switch, and using the old Analog TV frequencies to distribute free internet across the nation. With such a huge number of applications that could potentially use this, I don’t see why we would not do it. Some potential applications could be free internet radio in your car, Text messaging and Cell Phone services cut down, smaller hand held computers used to make “online purchases” at the store…the list could go on forever. The service can be expect to have at least a 1 MB download speed.

With this new idea of technology at hand, and the possibilities for it to produce huge amounts of money, I want to get in on it before it starts to ensure my cut of the profits that are to be made. Initially I had an idea such as no longer having to pay to make a phone call, as essentially instant messaging someone is the same as making a call. My other ideas are to start an online radio station. People could listen to any music at any time for free from anywhere. Market new radio devices so that if your car breaks down you could technically use your radio to call for help. Having built in GPS technology to hand held devices could allow you to simple allow your friend to see your GPS location and use already available services like Google Maps to receive driving directions to the location.

So how can we get started with these ideas? Having capitol is of course the biggest road block. Leave your ideas and suggestions in the comments, I would love to chat with someone about the possible money making ideas we could develope.

Written by: John Minton