Engaged...................
if(isset($_POST['registration']))
{
//process form
}
if(isset($_POST['registration']))
{
//process form
}
else
{
//business as usual
}
if(isset($_POST['registration']))
{
//process form
}
elseif(!empty($_POST['registration']))
{
//process form
}
elseif(isset($_POST))
{
//do more stuff
}
switch ($_GET['food']) {
case 'apple':
echo $_GET['food'], ' is apple';
break;
case 'bar':
echo $_GET['food'], ' is sandwich';
break;
case 'cake':
echo $_GET['food'], ' is cake';
break;
}
//$variable = 'true' ? 'yes' : no;
echo $_GET['food'] = 'apple' ? 'apple' : 'no';
if(isset($_POST['registration']))
{
echo '<pre>', print_r($_POST), '</pre>';
}
if(isset($_POST['registration']))
{
/* We use the line below for debugging.
we can always add to forward slashes to
the bebugging line to deactivate it */
echo '<pre>', print_r($_POST), '</pre>';
//What comes next is Form Validation
}

print_r();
if(isset($_POST['register']))
{
$_POST['name'] = preg_replace('[\s\s+]', '', $_POST['name']); //Removes excess white space
echo '<pre>', print_r($_POST), '</pre>';
}
if(isset($_POST['register']))
{
$_POST['name'] = preg_replace('[\s\s+]', '', $_POST['name']);
$_POST['email'] = preg_replace('[\s\s+]', '', $_POST['email']);
$_POST['password'] = preg_replace('[\s\s+]', '', $_POST['password']);
echo '<pre>', print_r($_POST), '</pre>';
}
//The Pattern
$pattern[] = '[\s\s+]'; //No excess white space
$pattern[] = '[<(.*?)>(.*?)</(.*?)>]'; //Remove tags and everything in between
$pattern[] = '[<(.*?)>]'; //Remove stray open tags
$pattern[] = '[</(.*?)>]'; //Remove stray closing tags
$_POST['name'] = preg_replace($pattern, '', $_POST['name']);
$_POST['email'] = preg_replace($pattern, '', $_POST['email']);
$_POST['password'] = preg_replace($pattern, '', $_POST['password']);
echo '<pre>', print_r($_POST), '</pre>';
$_POST['name'] = preg_replace($pattern, '', $_POST['name']);
$_POST['name'] = htmlentities($_POST['name']);
$_POST['email'] = preg_replace($pattern, '', $_POST['email']);
$_POST['email'] = htmlentities($_POST['email']);
$_POST['password'] = preg_replace($pattern, '', $_POST['password']);
$_POST['password'] = htmlentities($_POST['password']);
$str = "A 'quote' is <b>bold</b>";
echo htmlentities($str); // Outputs: A 'quote' is <b>bold</b>
mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.
$_POST['name'] = preg_replace($pattern, '', $_POST['name']);
$_POST['name'] = mysql_real_escape_string($_POST['name']);
$_POST['name'] = htmlentities($_POST['name']);
$_POST['email'] = preg_replace($pattern, '', $_POST['email']);
$_POST['email'] = mysql_real_escape_string($_POST['email']);
$_POST['email'] = htmlentities($_POST['email']);
$_POST['password'] = preg_replace($pattern, '', $_POST['password']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
$_POST['password'] = htmlentities($_POST['password']);
for($i = 1; 100 >= $i; $i++)
{
echo 'The number is: ', $i;
}
$arr = array('red', 'green', 'blue', 'yellow');
foreach($arr as $colors)
{
echo $colors, ' ';
}
$arr = array('red', 'green', 'blue', 'yellow');
$arr = count($arr);
for($i = 0; $arr >= $i; $i++)
{
echo $arr[$i], ' ';
}
$pattern[] = '[\s\s+]'; //No excess white space
$pattern[] = '[<(.*?)>(.*?)</(.*?)>]'; //Remove tags and everything in between
$pattern[] = '[<(.*?)>]'; //Remove stray open tags
$pattern[] = '[</(.*?)>]'; //Remove stray closing tags
$_POST['name'] = preg_replace($pattern, '', $_POST['name']);
$_POST['name'] = htmlentities($_POST['name']);
$_POST['email'] = preg_replace($pattern, '', $_POST['email']);
$_POST['email'] = htmlentities($_POST['email']);
$_POST['password'] = preg_replace($pattern, '', $_POST['password']);
$_POST['password'] = htmlentities($_POST['password']);
function clean_reg(&$array) {
//Let's place our patterns in a neat array
$pattern = array('[\s\s+]','[<(.*?)>(.*?)</(.*?)>]','[<(.*?)>]','[</(.*?)>]');
foreach ($array as &$input){ //Let's loop through the post array
if (!is_array($input)){ //if it's not an array, let's wash it...
$input = stripslashes($input);
$input = preg_replace($pattern, '', $input);
$input = mysql_real_escape_string($input);
$input = htmlentities($input, ENT_QUOTES);
}
else { //if it is an array, for example a multidimensional array, let repeat the function to was deeper inside the $_POST array
clean_reg($input);
}
}
}
if(isset($_POST['register']))
{
$pattern[] = '[\s\s+]'; //No excess white space
$pattern[] = '[<(.*?)>(.*?)</(.*?)>]'; //Remove tags and everything in between
$pattern[] = '[<(.*?)>]'; //Remove stray open tags
$pattern[] = '[</(.*?)>]'; //Remove stray closing tags
$_POST['name'] = preg_replace($pattern, '', $_POST['name']);
$_POST['name'] = htmlentities($_POST['name']);
$_POST['email'] = preg_replace($pattern, '', $_POST['email']);
$_POST['email'] = htmlentities($_POST['email']);
$_POST['password'] = preg_replace($pattern, '', $_POST['password']);
$_POST['password'] = htmlentities($_POST['password']);
echo '<pre>', print_r($_POST), '</pre>';
}
if(isset($_POST['register']))
{
clean_reg($_POST);
echo '<pre>', print_r($_POST), '</pre>';
}
$errors = array();
function warnings($errors, $class = '')
{
if(!empty($errors))
{
echo '<div class="' . $class . '">';
foreach($errors as $error)
{
echo $error, '<br />';
}
echo '</div>';
}
}
if(isset($_POST['register']))
{
clean_reg($_POST);
$submit = $_POST; //Good security practice to copy the $_POST variable
if(empty($submit['name'])){ // Checks if name field is empty
$errors[] = 'Please enter your name.';
}
if(empty($submit['email'])){ //Checks is email field is empty
$errors[] = 'Please enter your email address.';
}
if(!empty($submit['email'])){ //If the email field is not empty, let's make sure they have entered a legit email address
if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $submit['email'])) { //We are using regex again to make sure the email address matches the given pattern
$errors[] = 'Please enter a valid email address';
}
}
if(empty($submit['password'])){ //make sure the password field is not empty
$errors[] = 'Please enter your password.';
}
}
.errors
{
color: black;
text-align: center;
font-size: 2em;
width: 600px;
padding: 10px;
margin: 0 auto 20px auto;
border: 20px dashed red;
-moz-border-radius: 70px;
-webkit-border-radius: 70px;
}
<div id="copy">',
warnings($errors, 'errors'), '
<form method="post" action="">
<?php
$_SESSION['register'] = array(
'name' => (!empty($_POST['name']) ? $_POST['name'] : ''),
'email' => (!empty($_POST['email']) ? $_POST['email'] : ''),
'password' => (!empty($_POST['name']) ? $_POST['password'] : ''),
);
?>
include_once('Engine/Sessions.php');
<?php
echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="', $theme['default']['style'], '" media="screen" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>PHP & MySQL Tutorial</title>
</head>
<body>
<div id="header">
<div>BGOL <span>PHP & MySQL Tutorial</span></div>
</div>
<div id="content">
<div id="copy">',
warnings($errors, 'errors'), '
<form method="post" action="">
<fieldset><legend>Register</legend>
<label for="name">Name</label><input type="text" name="name" id="name" value="', (!empty($_SESSION['register']['name']) ? $_SESSION['register']['name'] : ''), '" />
<br />
<label for="email">Email</label><input type="text" name="email" id="email" value="', (!empty($_SESSION['register']['email']) ? $_SESSION['register']['email'] : ''), '" />
<br />
<label for="password">Password</label><input type="password" name="password" id="password" value="', (!empty($_SESSION['register']['password']) ? $_SESSION['register']['password'] : ''), '" />
<br /><br />
<input type="submit" name="register" value="Submit" />
</fieldset>
</form>
</div>
<div style="clear: both;"></div>
</div>
<div id="footer">by <span>JD Walker<span></div>
</body>
</html>';
?>
It is also becoming more and more obvious that there are a slew of fraudulent ass clowns disseminating piss poor information about web development, such as writing half assed code, relying soley on GUIs and having you spend money on hacks from India. Janitor type niggas passing themselves off as web authorities. Vegas hookers workin' in Best Buy trying to get you hooked on GUIs. Black ass niggas who thinks building computers makes them experts on all things code.









Array
(
[name] => Quaid
[email] => quaid@bgol.com
[password] => bgol2010
[register] => Submit
)
1
$submit['password'] = hash('sha512', $submit['password']);
Array
(
[name] => Quaid
[email] => quaid@bgol.com
[password] => 13861b1955e10ec0ea9ebfa5d665cf71679ce83bccce44d527fa39679eef0ca49f293d06cc07a458aaeeed9a445f18cb90b820eae5f7fa94adc51541862f6483
[register] => Submit
)
1
$salt = 'UnH@cK@b13';
$submit['password'] = $submit['password'] . $salt;
$submit['password'] = hash('sha512', $submit['password']);
Array
(
[name] => Quaid
[email] => quaid@bgol.com
[password] => fb6e12853f30af31fdb6b7f300013e808387db9e47c9d0162c30f38a4240dfea936054a49061e2d486e020c2f30a7be0ee67ffbad5451212be34abf7255abc69
[register] => Submit
)
1
if(empty($submit['name']))
{
$errors[] = 'Please enter your name.';
}
if(!empty($submit['name']))
{
if(strlen($submit['name']) > $reg_len){
$errors[] = 'Your username is too long.';
}
}
if(empty($submit['email']))
{
$errors[] = 'Please enter your email address.';
}
if(!empty($submit['email']))
{
if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $submit['email'])) {
$errors[] = 'Please enter a valid email address';
}
if(strlen($submit['email']) > $reg_len){
$errors[] = 'Your email is too long.';
}
}
if(empty($submit['password']))
{
$errors[] = 'Please enter your password.';
}
if(!empty($submit['password']))
{
if(strlen($submit['password']) > $reg_len){
$errors[] = 'Your password is too long.';
}
}
CREATE TABLE `test`.`site_users` (
`id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 256 ) NOT NULL ,
`email` VARCHAR( 256 ) NOT NULL ,
`password` TEXT NOT NULL ,
`date` VARCHAR( 10 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;
//MySQL
$dbname = 'your_database_name';
$dbuser = 'your_database_username';
$dbpass = 'your_database_password';
$dbhost = '127.0.0.1'; //either 127.0.0.1 or localhost
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(isset($_POST['register']))
{
clean_reg($_POST);
$submit = $_POST;
if(empty($submit['name']))
{
$errors[] = 'Please enter your name.';
}
if(!empty($submit['name']))
{
if(strlen($submit['name']) > $reg_len){
$errors[] = 'Your username is too long.';
}
}
if(empty($submit['email']))
{
$errors[] = 'Please enter your email address.';
}
if(!empty($submit['email']))
{
if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $submit['email'])) {
$errors[] = 'Please enter a valid email address';
}
if(strlen($submit['email']) > $reg_len){
$errors[] = 'Your email is too long.';
}
}
if(empty($submit['password']))
{
$errors[] = 'Please enter your password.';
}
if(!empty($submit['password']))
{
if(strlen($submit['password']) > $reg_len){
$errors[] = 'Your password is too long.';
}
}
if(empty($errors))
{
$submit['password'] = $submit['password'] . $salt;
$submit['password'] = hash('sha512', $submit['password']);
$submit['date'] = time();
//This block submits the data in to the database using a combination of PHP and MySQL language...
$query ="INSERT INTO `site_users` (`id`, `name`, `email`, `password`, `date`)
VALUES ('', '{$submit['name']}', '{$submit['email']}', '{$submit['password']}', '{$submit['date']}');";
$result = mysql_query($query) or die(mysql_error());
$_SESSION['register'] = array(); //We'll clear the Session data since we don't need it anymore
header('Location: ' . url . '/index.php?action=home'); //This generates a dynamic page after submission that takes to user to where ever you want them to go. This will be covered in a later tutorial.
}
}
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
$iPad = preg_match('[ipad]', strtolower($_SERVER["HTTP_USER_AGENT"]));
if($iPad){
//Display iPad stuff
}else{
//Business as usual
}
$path = gallery;
function folders($path)
{
$forbidden = array('.', '..', '.DS_Store', '.htaccess', 'index.php'); //Let's make an array of things we don't want returned while looping through the folders
$the_array = array(); //Now let's initialize the variable that will hold our folder values...
if ($handle = opendir($path)){ //Let's open the main directory...
while(false !== ($file = readdir($handle))){//Now let's loop through these folders...
if (!in_array($file, $forbidden)){//Let's make sure the forbidden files aren't returned...
if(!is_dir("$path/$file")){//If it's not a directory, return the value in order to avoid duplicate values in the array...
$the_array[] = $file;
}
if(is_dir("$path/$file")){//If it is an array, let's make a key out of it...
$the_array[$file] = folders("$path/$file");//If there are more folders inside folders, let's display their contents by reusing the function
}
}
}
}
closedir($handle); //Let's close the folder
return $the_array; //return the array to get ready for use...
}
$gallery = folders($path); //let's assign the "$gallery" variable to the function..
echo '<pre>', print_r($gallery), '</pre>';
foreach($gallery as $folder => $files){//We want the folder names first to use as titles...
echo'
<div>
<h1>', str_replace('_', ' ', $folder), '</h1>';
$i = 0;
foreach($files as $pix){//Now we loop through the images and use HTML to display them properly...
$i++; //Let's set our counter...
echo '<div style="float: left; border: 4px double black; margin: 7px;"><img src="', url, '/Gallery/', $folder, '/', $pix, '" alt="" width="200"/></div>';
if($i == 4){//Since there are 12 images per folder, I want the loop to create a new row after every 4th image...
echo '<br style="clear: both;" />';
$i = 0; //reset the counter after 4 images are displayed per row
}
}
echo ' <br style="clear: both;" />
</div><br /><br />';
}
// $number is mandatory, the "$style" is optional
function phone($number, $style = '')
{ //If there's no style, or if the style is set to "1", let's use a default format
if(empty($style) || $style === 1)
{ //Let's make sure $number is set...
if(isset($number))
{//Let's count the length of the number character by character, and loop through it...
for($i = 0; strlen($number) > $i; $i++)
{
echo $number[$i]; //Let's echo the number character by character...
if($i === 2 || $i === 5){ //If the loop loops past the 3rd character of the area code (remember, the count starts at 0, not 1) and the 5th character (between the prefix and suffix) let's add a dash...
echo '-';
}
}
}
}
elseif($style === 2)
{//If style 2 is selected...
if(isset($number))
{
for($i = 0; strlen($number) > $i; $i++)
{
if($i === 0){ //Let's open a Parenthesis at the beginning of the area code...
echo '(';
}
if($i === 3){ //Let's close the parenthesis at the end of the area code...
echo ') ';
}
if($i === 6){ //And let's add a dash between the dash between the prefix and suffix
echo '-';
}
echo $number[$i];
}
}
}
}
$myNumber = 3214567890;
phone($myNumber); // Ouputs 321-456-7890
phone($myNumber, 2); // Ouputs (321) 456-7890
JD, I'm following little by little, but I have a question. I want to do a website where users can submit information, and it automatically gets posted to the website.
I've set the site up in Wordpress, but it lacks the customization that I want. Would PHP be a good route?
Should I try to customize the Wordpress code, or build the site from the ground up?
Here are a few of the things that I want to have included in the site:
- decent interface
- user submissions
- email alerts
- easy way to edit / delete submissions
- submission printed directy to website and time stamped
- polling system, where reader can be vote on submission
Any info would help, I just need to know where to focus my efforts as far as building the site. I would prefer to be able to get it done quickly, using something like wordpress or joomla but if I have to learn to do it from scratch, i don't mind doing that.
//Let's start with IE since that browser causes the most problems
$browser= array(
'ie' => preg_match('[msie]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'ie6' => preg_match('[msie 6.0]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'ie7' => preg_match('[msie 7.0]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'ie8' => preg_match('[msie 8.0]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'opera' => preg_match('[opera]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'safari' => preg_match('[safari]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'iphone' => preg_match('[iphone]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'ipod' => preg_match('[ipod]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'ipad' => preg_match('[ipad]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'firefox' => preg_match('[firefox]', strtolower($_SERVER["HTTP_USER_AGENT"])),
'chrome' => preg_match('[chrome]', strtolower($_SERVER["HTTP_USER_AGENT"])),
);
if($browser['ie'])
{
//apply ie fixes
}
home.html
about.html
new.html
contact.html
http://yourwebsite.com/index.php?page=about
if(isset($_GET['page'])){ //if the variable "page" exists in the query string...
$page = $_GET['page']; //assign a variable to "page"
}else{
$page = NULL; //if page doesn't exist in the query string, set it to null
}
http://yourwebsite.com/index.php?page=about;DROP TABLE users;
switch($page)
{
case 'about':
//Show About stuff
break;
case 'news':
//Show News stuff
break;
case 'faq':
//Show FAQ stuff
break;
case 'contact':
//Show Contact stuff
break;
}