Search Engine Optimization is an important process for any professional website. In this post I will explain why Search Engine Optimization is key to your business success and also how to improve upon it.
Showing posts with label Website Series. Show all posts
Showing posts with label Website Series. Show all posts
Sunday, April 29, 2012
Wednesday, April 18, 2012
How to Place Text Around Your ads
For those that are blogging and want to be able to put ads in their text. This is one of the many ways to get peoples eyes when they are reading your articles to see your ads so that you can make money. There are a few different ways of doing this.
Wednesday, November 16, 2011
Formatting Your Blog Articles - Part 1
Formatting is a very important thing when it comes to blogging and well any other type of writing. Not only does formatting help your viewers see important headlines, quotes, and many other things. Search engine bots look for different HTML tags and CSS to determine topics and how to index your posts.
Output
These give the viewer eye catching titles for your posts and also give bots titles for it instead of having to guess at what is and whats not.
use things like code tags so that you can format your posts. for instance if you want your code to always be your quotes to look like our code does on our blog you can just use this code in your css.
for linking text so that your user does not loss you remember to add target="_blank" to your links so that the link they click will open in a new tab.
will come out like this
local tech repair
if your wanting your paragraphs to auto intent so that you don't have to do it your self when writing you can make sure that they always do it with css.
This will make sure that it is always indented at ever new paragraph granted that there be a p tag
Well I hope you liked this first part of this post hope you read the next coming soon.
Local Tech Repair Admin
Part 1 HTML
Us header commands or bold commands
<h1> text </h1>
<h2> text </h2>
<b> text </b>
Output
text
text
text
These give the viewer eye catching titles for your posts and also give bots titles for it instead of having to guess at what is and whats not.
use things like code tags so that you can format your posts. for instance if you want your code to always be your quotes to look like our code does on our blog you can just use this code in your css.
code {background: #F3EFC3 url(http://img403.imageshack.us/img403/6029/backgroundcode.png) 0 7px;
background-image: url(http://img403.imageshack.us/img403/6029/backgroundcode.png);
background-repeat-x: initial;
background-repeat-y: initial;
background-attachment: initial;
background-position-x: 0px;
background-position-y: 7px;
background-origin: initial;
background-clip: initial;
background-color: #F3EFC3;
overflow-x: auto;
display: block;
width: 95%;
padding: 2% 2.5%;
padding-top: 2%;
padding-right: 2.5%;
padding-bottom: 2%;
padding-left: 2.5%;
margin: 30px 0;
margin-top: 30px;
margin-right: 0px;
margin-bottom: 30px;
margin-left: 0px;
clear: both;
color: #585535;
font-size: 85%;
line-height: 140%;
border: solid 1px #E8E3B8;
border-top-style: solid;
border-right-style: solid;
border-left-style: solid;
border-top-width: 1px;
border-right-width: 1px;
border-left-width: 1px;
border-top-color: #E8E3B8;
border-right-color: #E8E3B8;
border-left-color: #E8E3B8;
border-bottom: solid 1px #D9D4A8;
border-bottom-style: solid;
border-bottom-width: 1px;
border-bottom-color: #D9D4A8;
-moz-border-radius: 15px;
border-radius: 15px;
}
for linking text so that your user does not loss you remember to add target="_blank" to your links so that the link they click will open in a new tab.
<a href="http://localtechrepair.blogspot.com" target="_blank">local tech repair</a>
will come out like this
local tech repair
if your wanting your paragraphs to auto intent so that you don't have to do it your self when writing you can make sure that they always do it with css.
p
{
text-indent:50px;
}
This will make sure that it is always indented at ever new paragraph granted that there be a p tag
Well I hope you liked this first part of this post hope you read the next coming soon.
Local Tech Repair Admin
Saturday, January 29, 2011
Checking form submit with php
so one thing that took me a while to figure out is how to have php check the form submissions in the same page but only if the form was submitted. another thing was if something was wrong being able to have php give default values that where already submitted if there was a problem. so better than me talking let me show you code.
but let me explain what this form is in the first place. this is a medical history form for dogs. this shows when their last medical test for certain things where done on.
---------form.php-------------------
<?
include ("header.php");
include "../connect.php";
?>
<td class="left_content"><div align="center"><strong>Here are some Use full links</strong></div><br />
<?include ("../leftside.php");?>
</td>
<td class="body_content"><strong><h4 id="title"> Medical Record </h4></strong>
<?php
if ($_POST['submit'] == "Update") { // this checks to see if the submitted form name is Update
$name = $_POST['pName'];
$DHLPP = $_POST["DHLPP"];
$Rabies = $_POST["Rabies"];
$Bordatella = $_POST["Bordatella"];
$heartworm = $_POST["heartworm"];
$worming= $_POST["worming"];
$flea= $_POST["flea"];
$Fixed= $_POST["Fixed"];
$pinHips= $_POST["pinHips"];
$OFA= $_POST["OFA"];
$Eye= $_POST["Eye"];
$wellness= $_POST["wellness"];
$sql = "SELECT * FROM Medical where dogName = '$name'";
$results=mysql_query($sql) or die (mysql_error());
$row= mysql_fetch_array($results);
$numrow = mysql_num_rows($results);
while ($row= mysql_fetch_array($results)){
$id = $row['ID'];
}
if ($numrow == 1) {
$sql = "UPDATE Medical SET dogName = '$name', DHLPP = '$DHLPP', Rabies = '$Rabies',
Bordatella = '$Bordatella', heartworm = '$heartworm', worming = '$worming',
flea = '$flea', Fixed = '$Fixed', pinHips = '$pinHips', OFA = '$OFA', Eye = '$Eye',
wellness = '$wellness'
WHERE dogName = '$name'";
$result = mysql_query($sql) or die (mysql_error());
if ($result) { echo "updated"; }
$date = date('Y-m-d');
$sql="INSERT INTO MedicalHistory (dogName, DHLPP, Rabies, Bordatella, heartworm, worming, flea, Fixed, pinHips, OFA, Eye, wellness, dateadd)
VALUES ('$name','$DHLPP','$Rabies','$Bordatella','$heartworm','$worming','$flea','$Fixed','$pinHips','$OFA','$Eye','$wellness','$date')";
$result = mysql_query($sql) or die (mysql_error());
} else {
$name = $_POST['pName'];
$DHLPP = $_POST["DHLPP"];
$Rabies = $_POST["Rabies"];
$Bordatella = $_POST["Bordatella"];
$heartworm = $_POST["heartworm"];
$worming= $_POST["worming"];
$flea= $_POST["flea"];
$Fixed= $_POST["Fixed"];
$pinHips= $_POST["pinHips"];
$OFA= $_POST["OFA"];
$Eye= $_POST["Eye"];
$wellness= $_POST["wellness"];
$sql="INSERT INTO Medical (dogName, DHLPP, Rabies, Bordatella, heartworm, worming, flea, Fixed, pinHips, OFA, Eye, wellness)
VALUES ('$name','$DHLPP','$Rabies','$Bordatella','$heartworm','$worming','$flea','$Fixed','$pinHips','$OFA','$Eye','$wellness')";
$result = mysql_query($sql) or die (mysql_error());
if ($result) { echo "inserted"; }
$date = date('Y-m-d');
$sql="INSERT INTO MedicalHistory (dogName, DHLPP, Rabies, Bordatella, heartworm, worming, flea, Fixed, pinHips, OFA, Eye, wellness, dateadd)
VALUES ('$name','$DHLPP','$Rabies','$Bordatella','$heartworm','$worming','$flea','$Fixed','$pinHips','$OFA','$Eye','$wellness','$date')";
$result = mysql_query($sql) or die (mysql_error());
}
} else {if ($_POST['submit'] == "Delete Dog") {
$name = $_POST['pName'];
$sql = "DELETE FROM Medical WHERE dogName = '$name'";
$result = mysql_query($sql) or die (mysql_error());
if ($result) {echo "Deleted Dog";}
}
}
$name = $_POST['pName'];
$sql = "SELECT * FROM Medical where dogName = '$name'";
$results=mysql_query($sql) or die (mysql_error());
$row= mysql_fetch_array($results);
$DHLPP = $row["DHLPP"];
$Rabies = $row["Rabies"];
$Bordatella = $row["Bordatella"];
$heartworm = $row["heartworm"];
$worming= $row["worming"];
$flea= $row["flea"];
$Fixed= $row["Fixed"];
$pinHips= $row["pinHips"];
$OFA= $row["OFA"];
$Eye= $row["Eye"];
$wellness= $row["wellness"];
?>
<form method="POST" action="">
<?php
$query = "SELECT * FROM Dogs";
$arr = mysql_query($query);
echo "<select name='pName'>";
echo "<option value=" . $name . ">" . $name . "</option>";
while ($row = mysql_fetch_array($arr)) {
$title = $row["Name"];
if ($title != $name) {
echo "<option value=" . $title . ">" . $title . "</option>";
}
}
echo "</select>";
?>
<br />
<input type="submit" value="Change Dogs">
</form>
<form method="POST" action="">
<table>
<tr>
<td colspan="2">
<input type="hidden" name="pName" value="<?php print $name; ?>"/>
</td>
</tr>
<tr>
<td>DHLPP</td>
<td><input type="date" name="DHLPP" value="<?php if ($DHLPP != "0000-00-00"){print $DHLPP; } ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Rabies</td>
<td><input type="date" name="Rabies" value="<?php if ($Rabies != "0000-00-00"){print $Rabies;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Bordatella</td>
<td><input type="date" name="Bordatella" value="<?php if ($Bordatella != "0000-00-00"){ print $Bordatella;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>heartworm</td>
<td><input type="date" name="heartworm" value="<?php if ($heartworm != "0000-00-00"){ print $heartworm;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>worming</td>
<td><input type="date" name="worming" value="<?php if ($worming != "0000-00-00"){ print $worming;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>flea</td>
<td><input type="date" name="flea" value="<?php if ($flea != "0000-00-00"){ print $flea;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Fixed</td>
<td><input type="date" name ="Fixed" value="<?php if ($Fixed != "0000-00-00"){ print $Fixed; } ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>pinHips</td>
<td><input type="date" name="pinHips" value="<?php if ($pinHips != "0000-00-00"){ print $pinHips;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>OFA</td>
<td><input type="date" name="OFA" value="<?php if ($OFA != "0000-00-00"){ print $OFA;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Eye</td>
<td><input type="date" name="Eye" value="<?php if ($Eye != "0000-00-00"){ print $Eye; } ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Wellness</td>
<td><input type="date" name="wellness" value="<?php if ($wellness != "0000-00-00"){ print $wellness;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Update" />
<input type="submit" name="submit" value="Delete Dog" />
</td>
</tr>
</table>
</form>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$username = $_COOKIE['Username'];
$date = date('Y-m-d H:i:s');
$sql = "insert into loginHistory (ip, username, datetime) VALUES ('$ip','$username','$date')";
$result=mysql_query($sql);
?>
</td>
<?
include ("../footer.php");
?>
---------------------------------
let me explain this in more detail
when a form is either submitted or not it will run this
<tr>
<td>Wellness</td>
<td><input type="date" name="wellness" value="<?php if ($wellness != "0000-00-00"){ print $wellness;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
this is date input type which is a standard coming in html5 that makes sure that before someone submits a form it makes sure that it is a date. though if the browser is not html5 compatible then it will treat it like a text input.
the php in this is checking if the variable $wellness does not not equal 0000-00-00 which is a default input in a mysql database for a date type if the input is blank.
so basicly if it equals anything but 0000-00-00 it will print the variable $wellness in the value. so if $wellness = 2010-01-01 then the input in html will look more like
<td><input type="date" name="wellness" value="2010-01-01" />(Ex: YYYY-MM-DD)</td>
if your wanting to check each input then you can with in the
if ($_POST['submit'] == "Update") {
you can have separate if statements for each input
so if i wanted to check if the date was exactly 10 characters long then i would run a if statment like this
if (strlen($wellness) != 10 ) {
throw some kind of error
}
the possibilities are endless this is just one thing i have done when i was trying to make my input form more dynamic and not having to have multiple pages.
also if your using a GET statement you can do the same thing. the key is that the input needs to have a name of submit and the value can be checked that way.
i hope you enjoyed this little php and html from local tech repair
if you have comments or other ideas i would love to hear them.
thanks for reading,
josh (Local Tech Repair)
but let me explain what this form is in the first place. this is a medical history form for dogs. this shows when their last medical test for certain things where done on.
---------form.php-------------------
<?
include ("header.php");
include "../connect.php";
?>
<td class="left_content"><div align="center"><strong>Here are some Use full links</strong></div><br />
<?include ("../leftside.php");?>
</td>
<td class="body_content"><strong><h4 id="title"> Medical Record </h4></strong>
<?php
if ($_POST['submit'] == "Update") { // this checks to see if the submitted form name is Update
$name = $_POST['pName'];
$DHLPP = $_POST["DHLPP"];
$Rabies = $_POST["Rabies"];
$Bordatella = $_POST["Bordatella"];
$heartworm = $_POST["heartworm"];
$worming= $_POST["worming"];
$flea= $_POST["flea"];
$Fixed= $_POST["Fixed"];
$pinHips= $_POST["pinHips"];
$OFA= $_POST["OFA"];
$Eye= $_POST["Eye"];
$wellness= $_POST["wellness"];
$sql = "SELECT * FROM Medical where dogName = '$name'";
$results=mysql_query($sql) or die (mysql_error());
$row= mysql_fetch_array($results);
$numrow = mysql_num_rows($results);
while ($row= mysql_fetch_array($results)){
$id = $row['ID'];
}
if ($numrow == 1) {
$sql = "UPDATE Medical SET dogName = '$name', DHLPP = '$DHLPP', Rabies = '$Rabies',
Bordatella = '$Bordatella', heartworm = '$heartworm', worming = '$worming',
flea = '$flea', Fixed = '$Fixed', pinHips = '$pinHips', OFA = '$OFA', Eye = '$Eye',
wellness = '$wellness'
WHERE dogName = '$name'";
$result = mysql_query($sql) or die (mysql_error());
if ($result) { echo "updated"; }
$date = date('Y-m-d');
$sql="INSERT INTO MedicalHistory (dogName, DHLPP, Rabies, Bordatella, heartworm, worming, flea, Fixed, pinHips, OFA, Eye, wellness, dateadd)
VALUES ('$name','$DHLPP','$Rabies','$Bordatella','$heartworm','$worming','$flea','$Fixed','$pinHips','$OFA','$Eye','$wellness','$date')";
$result = mysql_query($sql) or die (mysql_error());
} else {
$name = $_POST['pName'];
$DHLPP = $_POST["DHLPP"];
$Rabies = $_POST["Rabies"];
$Bordatella = $_POST["Bordatella"];
$heartworm = $_POST["heartworm"];
$worming= $_POST["worming"];
$flea= $_POST["flea"];
$Fixed= $_POST["Fixed"];
$pinHips= $_POST["pinHips"];
$OFA= $_POST["OFA"];
$Eye= $_POST["Eye"];
$wellness= $_POST["wellness"];
$sql="INSERT INTO Medical (dogName, DHLPP, Rabies, Bordatella, heartworm, worming, flea, Fixed, pinHips, OFA, Eye, wellness)
VALUES ('$name','$DHLPP','$Rabies','$Bordatella','$heartworm','$worming','$flea','$Fixed','$pinHips','$OFA','$Eye','$wellness')";
$result = mysql_query($sql) or die (mysql_error());
if ($result) { echo "inserted"; }
$date = date('Y-m-d');
$sql="INSERT INTO MedicalHistory (dogName, DHLPP, Rabies, Bordatella, heartworm, worming, flea, Fixed, pinHips, OFA, Eye, wellness, dateadd)
VALUES ('$name','$DHLPP','$Rabies','$Bordatella','$heartworm','$worming','$flea','$Fixed','$pinHips','$OFA','$Eye','$wellness','$date')";
$result = mysql_query($sql) or die (mysql_error());
}
} else {if ($_POST['submit'] == "Delete Dog") {
$name = $_POST['pName'];
$sql = "DELETE FROM Medical WHERE dogName = '$name'";
$result = mysql_query($sql) or die (mysql_error());
if ($result) {echo "Deleted Dog";}
}
}
$name = $_POST['pName'];
$sql = "SELECT * FROM Medical where dogName = '$name'";
$results=mysql_query($sql) or die (mysql_error());
$row= mysql_fetch_array($results);
$DHLPP = $row["DHLPP"];
$Rabies = $row["Rabies"];
$Bordatella = $row["Bordatella"];
$heartworm = $row["heartworm"];
$worming= $row["worming"];
$flea= $row["flea"];
$Fixed= $row["Fixed"];
$pinHips= $row["pinHips"];
$OFA= $row["OFA"];
$Eye= $row["Eye"];
$wellness= $row["wellness"];
?>
<form method="POST" action="">
<?php
$query = "SELECT * FROM Dogs";
$arr = mysql_query($query);
echo "<select name='pName'>";
echo "<option value=" . $name . ">" . $name . "</option>";
while ($row = mysql_fetch_array($arr)) {
$title = $row["Name"];
if ($title != $name) {
echo "<option value=" . $title . ">" . $title . "</option>";
}
}
echo "</select>";
?>
<br />
<input type="submit" value="Change Dogs">
</form>
<form method="POST" action="">
<table>
<tr>
<td colspan="2">
<input type="hidden" name="pName" value="<?php print $name; ?>"/>
</td>
</tr>
<tr>
<td>DHLPP</td>
<td><input type="date" name="DHLPP" value="<?php if ($DHLPP != "0000-00-00"){print $DHLPP; } ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Rabies</td>
<td><input type="date" name="Rabies" value="<?php if ($Rabies != "0000-00-00"){print $Rabies;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Bordatella</td>
<td><input type="date" name="Bordatella" value="<?php if ($Bordatella != "0000-00-00"){ print $Bordatella;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>heartworm</td>
<td><input type="date" name="heartworm" value="<?php if ($heartworm != "0000-00-00"){ print $heartworm;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>worming</td>
<td><input type="date" name="worming" value="<?php if ($worming != "0000-00-00"){ print $worming;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>flea</td>
<td><input type="date" name="flea" value="<?php if ($flea != "0000-00-00"){ print $flea;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Fixed</td>
<td><input type="date" name ="Fixed" value="<?php if ($Fixed != "0000-00-00"){ print $Fixed; } ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>pinHips</td>
<td><input type="date" name="pinHips" value="<?php if ($pinHips != "0000-00-00"){ print $pinHips;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>OFA</td>
<td><input type="date" name="OFA" value="<?php if ($OFA != "0000-00-00"){ print $OFA;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Eye</td>
<td><input type="date" name="Eye" value="<?php if ($Eye != "0000-00-00"){ print $Eye; } ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td>Wellness</td>
<td><input type="date" name="wellness" value="<?php if ($wellness != "0000-00-00"){ print $wellness;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Update" />
<input type="submit" name="submit" value="Delete Dog" />
</td>
</tr>
</table>
</form>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$username = $_COOKIE['Username'];
$date = date('Y-m-d H:i:s');
$sql = "insert into loginHistory (ip, username, datetime) VALUES ('$ip','$username','$date')";
$result=mysql_query($sql);
?>
</td>
<?
include ("../footer.php");
?>
---------------------------------
let me explain this in more detail
when a form is either submitted or not it will run this
<tr>
<td>Wellness</td>
<td><input type="date" name="wellness" value="<?php if ($wellness != "0000-00-00"){ print $wellness;} ?>" />(Ex: YYYY-MM-DD)</td>
</tr>
this is date input type which is a standard coming in html5 that makes sure that before someone submits a form it makes sure that it is a date. though if the browser is not html5 compatible then it will treat it like a text input.
the php in this is checking if the variable $wellness does not not equal 0000-00-00 which is a default input in a mysql database for a date type if the input is blank.
so basicly if it equals anything but 0000-00-00 it will print the variable $wellness in the value. so if $wellness = 2010-01-01 then the input in html will look more like
<td><input type="date" name="wellness" value="2010-01-01" />(Ex: YYYY-MM-DD)</td>
if your wanting to check each input then you can with in the
if ($_POST['submit'] == "Update") {
you can have separate if statements for each input
so if i wanted to check if the date was exactly 10 characters long then i would run a if statment like this
if (strlen($wellness) != 10 ) {
throw some kind of error
}
the possibilities are endless this is just one thing i have done when i was trying to make my input form more dynamic and not having to have multiple pages.
also if your using a GET statement you can do the same thing. the key is that the input needs to have a name of submit and the value can be checked that way.
i hope you enjoyed this little php and html from local tech repair
if you have comments or other ideas i would love to hear them.
thanks for reading,
josh (Local Tech Repair)
Labels:
MySQL,
PHP,
Website,
Website Series
Wednesday, January 26, 2011
keep track of who access your site.
if you have a login based site and your wanting to keep track of who logs in and where they are login in from. here is a simple script that helps you do this.
you can also use this for users to be able to see where they have logged in from so they know if someone else is login in using their name.
------------script--------
<?php
include "../connect.php"; //brings in connection information
$ip = $_SERVER['REMOTE_ADDR']; // grabs the users IP address
$username = $_COOKIE['Username']; // checks for the username probably be smarter to use a session so the cookie does not get deleted
$date = date('Y-m-d H:i:s'); // grabes the server time
$sql = "insert into loginHistory (ip, username, datetime) VALUES ('$ip','$username','$date')"; // insert query
$result=mysql_query($sql); // finally inserts it.
?>
-------------------------------
from here if you wanted you display it in different manners how ever you want to.
for instance below you could do...
--------------script2------------------
include ("../connect.php");
// Build SQL Query
$sql = 'SELECT * FROM `loginHistory` ORDER BY `id` DESC LIMIT 0, 20 ';
$numresults=mysql_query($sql);
$count = 1 + $s ;
print " <table border='1' cellspacing='3' cellpadding='2'>";
// now you can display the results returned
print "<tr><td>Count</td><td>IP Address</td><td>User</td><td>Date and Time</td></tr>";
while ($row= mysql_fetch_array($numresults)) {
$title = $row["IP"];
$title2 = $row["username"];
$title3 = $row["datetime"];
print "<tr><td>";
echo "$count";
print "</td><td>";
echo "$title";
print "</td><td>";
echo " $title2" ;
print "</td><td>";
echo " $title3" ;
print "</td></tr>";
$count++ ;
}
print "</table>";
?>
--------------------------------------------------------
what this does is create a table and then fill it with a count, ip address, username, and date time that they last checked the page.
warning if you have a lot of members this script can put a lot of stress on your system because this will log each time the user loads a page or what ever page you put this on... if you put this on the login you will not have that problem though. it will only log once.
you can also use this for users to be able to see where they have logged in from so they know if someone else is login in using their name.
------------script--------
<?php
include "../connect.php"; //brings in connection information
$ip = $_SERVER['REMOTE_ADDR']; // grabs the users IP address
$username = $_COOKIE['Username']; // checks for the username probably be smarter to use a session so the cookie does not get deleted
$date = date('Y-m-d H:i:s'); // grabes the server time
$sql = "insert into loginHistory (ip, username, datetime) VALUES ('$ip','$username','$date')"; // insert query
$result=mysql_query($sql); // finally inserts it.
?>
-------------------------------
from here if you wanted you display it in different manners how ever you want to.
for instance below you could do...
--------------script2------------------
include ("../connect.php");
// Build SQL Query
$sql = 'SELECT * FROM `loginHistory` ORDER BY `id` DESC LIMIT 0, 20 ';
$numresults=mysql_query($sql);
$count = 1 + $s ;
print " <table border='1' cellspacing='3' cellpadding='2'>";
// now you can display the results returned
print "<tr><td>Count</td><td>IP Address</td><td>User</td><td>Date and Time</td></tr>";
while ($row= mysql_fetch_array($numresults)) {
$title = $row["IP"];
$title2 = $row["username"];
$title3 = $row["datetime"];
print "<tr><td>";
echo "$count";
print "</td><td>";
echo "$title";
print "</td><td>";
echo " $title2" ;
print "</td><td>";
echo " $title3" ;
print "</td></tr>";
$count++ ;
}
print "</table>";
?>
--------------------------------------------------------
what this does is create a table and then fill it with a count, ip address, username, and date time that they last checked the page.
warning if you have a lot of members this script can put a lot of stress on your system because this will log each time the user loads a page or what ever page you put this on... if you put this on the login you will not have that problem though. it will only log once.
Labels:
MySQL,
PHP,
Website,
Website Series
Creating a Login System Part 2
So i am going to continue the login system that i had started in the part one of this series.
and you can find that here
http://localtechrepair.blogspot.com/2011/01/creating-login-page-part-1-website.html
so now that we have added members to our database we can login as them
lets post some code to look at.
first we will start with the login screen and then from there what we use to check the login credentials. login will be our index page.
---------------index.php------------------
---------------------------------------------
-----------checklogin.php--------------
-------------------------------------------------
so i will explain a little bit what this does.
first the index page just is a normal form asking for your user name and password the user types that in then submits the form
it then goes to the checklogin.php from there it saves the username to a cookie for later use.
it then strips all the mysql escape characters and strips any slashes from both username and password that the user submitted. the password then is hashed in to a sha2 512 bit hash with a salt added at the beginning. you can also add a the random salt if you like. i do that on my own websites.
the database is then queried to see if their is a match for the username and passwords hash. if there is 1 then the script continues and checks to see if they are admin user or not and also continues to start a session for them and then direct them to the home page. if they fail and there is no user it will redirect them to the login page.
i hope these scripts help you start making your own pages. you can do a lot more with these scripts but this is a start.
and you can find that here
http://localtechrepair.blogspot.com/2011/01/creating-login-page-part-1-website.html
so now that we have added members to our database we can login as them
lets post some code to look at.
first we will start with the login screen and then from there what we use to check the login credentials. login will be our index page.
---------------index.php------------------
<?php
if( isset( $_COOKIE['Username'] ) )
{
if( isset( $_COOKIE['Passhash'] ) )
{
$user = $_COOKIE['Username'];
$pass = $_COOKIE['Passhash'];
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$user = ereg_replace("[^A-Za-z0-9]", "", $user );
$pass = ereg_replace("[^A-Za-z0-9]", "", $pass );
include_once "connect.php";
$sql="SELECT * FROM members WHERE username='$user' and password='$pass'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "Home.php"
session_register("myusername");
header("location:home.php");
}}}
$title = "local tech repair";
include ("header.php");
?>
<td class="left_content"><div align="center"><strong>Here are some useful links</strong></div><br />
<?include "leftside.php";?>
</td>
<td class="body_content"><strong><h4></h4></strong>
<form name="form1" method="post" action="./checklogin.php">
<td>
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<center><strong><h1></h1></strong></center>
<p>Study</p>
<tr>
<td colspan="2"><strong>Member Login </strong></td>
</tr>
<tr>
<td>Username:</td>
<td><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="mypassword" type=PASSWORD id="mypassword"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
<p>
Are you a corban student and want to join. <a href="register.php">click here and join</a>
</p>
<p>
<!-- Lost your password? click <a href="recovery.php">here</a> -->
</p>
</td>
</form>
</td>
<?
include ("footer.php");
?>
---------------------------------------------
-----------checklogin.php--------------
<?
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$date_of_expiry = time() + 86400 ;
setcookie( "Username", "$myusername", $date_of_expiry );
ob_start();
$tbl_name="members"; // Table name
include("connect.php"); //connect to database
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
// this only allows alpha numeric passwords.
$myusername = ereg_replace("[^A-Za-z0-9]", "", $myusername );
$mypassword = ereg_replace("[^A-Za-z0-9]", "", $mypassword );
// encrypts with sha512 bit + salt to help protect against rainbow table cracking.
$salt = "website";
$encrypted_mypassword=hash('sha512', $salt.$mypassword);
setcookie( "Passhash", "$encrypted_mypassword", $date_of_expiry);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
$query3 = "SELECT * FROM members WHERE username='$myusername' and password='$encrypted_mypassword' and privlege='Admin'";
$result3=mysql_query($query3);
$count2=mysql_num_rows($result3);
if ($count2==1){
setcookie('Admincookie', 'admin395', $date_of_expiry);
}
// Register $myusername, $mypassword and redirect to file "Home.php"
session_register("myusername");
header("location:home.php");
}
else {
// else if fales it will go back to the login page.
header("location:index.php");
}
ob_end_flush();
?>
-------------------------------------------------
so i will explain a little bit what this does.
first the index page just is a normal form asking for your user name and password the user types that in then submits the form
it then goes to the checklogin.php from there it saves the username to a cookie for later use.
it then strips all the mysql escape characters and strips any slashes from both username and password that the user submitted. the password then is hashed in to a sha2 512 bit hash with a salt added at the beginning. you can also add a the random salt if you like. i do that on my own websites.
the database is then queried to see if their is a match for the username and passwords hash. if there is 1 then the script continues and checks to see if they are admin user or not and also continues to start a session for them and then direct them to the home page. if they fail and there is no user it will redirect them to the login page.
i hope these scripts help you start making your own pages. you can do a lot more with these scripts but this is a start.
Labels:
MySQL,
PHP,
Website,
Website Series
Tuesday, January 4, 2011
Creating a Login System Part 1, Website Series Part 1
This is a first part of a series of releases on building a website using PHP and MySQL. I will be going through simple ways coding what can be done. i will try to explain everything that is going on with a script so that you can learn it and understand each part of it. This is for beginners to intermediate level programmers. If you are an expert please post in comments with corrections and other helpful hints and please use sources or code examples.
first we will need to create a database and table for member IDs, their passwords, and for their password salt, and for their privilege level. I will explain the later 2 later in this tutorial.
i will be using PHPmyadmin to create the database and table
so
steps
------------------------------------------------------------
Sense i am running out of time on this I will finish this in part 2
More Resources:
first we will need to create a database and table for member IDs, their passwords, and for their password salt, and for their privilege level. I will explain the later 2 later in this tutorial.
i will be using PHPmyadmin to create the database and table
so
steps
naming the database
Naming the table and how many rows. we need 5 rows
ID is just a number we associate them in the database. also ID is A_I which means auto increment and it is also our primary key.
We now have our database so we can now start working on the pages.
lets first make sure we can create a new member.
this is a simple form to add a member to the table
-----------addmember.php---------
----------------connect.php-----------------------
-------------checkaddmember.php-----------------------
this is a simple form to add a member to the table
-----------addmember.php---------
<?php
$title = "Add Member";
include('header.php');
?>
<td class="left_content">
<?include "leftside.php";?>
</td>
<td class="body_content"><div align="center"><strong>Add a new member for login</strong></div> <br />
<br />
<form method="post" action="checkaddmember.php">
<table>
<tr><td align="left">Username</td>
<td><input type="text" id="username" name="username" size="20"></td>
</tr>
<tr><td align="left">Password</td>
<td><input type="PASSWORD" id="password" name="password" size="20"></td>
</tr>
<tr>
<td align="left">
Email:
</td>
<td>
<input name="email" size="25">
</td>
</tr>
<tr><td align="left">Type</td>
<td><select name="privlege">
<option value="user">User</option>
<option value="Admin">Admin</option>
<option value="Moderator">Moderator</option>
</select></td>
</tr>
<tr><td colspan="2">
<p align="center">
<input type="submit" name="Submit" />
</tr>
</table>
</form>
</td>
<?
include('footer.php');
?>----------------connect.php-----------------------
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="blogspot_database"; // Database name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
-------------checkaddmember.php-----------------------
<?
$title = "check";
include ("header.php");
?>
<td class="left_content"><div align="center"><strong>Here are some Use full links</strong></div><br />
<?include ("leftside.php");?>
</td>
<td class="body_content"><strong><h4></h4></strong>
<?php
include('connect.php');
$mypassword=$_POST[password];
$salt = "website";
$encrypted_mypassword=hash('sha512', $salt.$mypassword);
$Name = $_POST[username];
$user = mysql_query("SELECT * FROM members WHERE (username='$Name')");
$exp = "^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
if ($_POST[username] != "") {
if ($_POST[password] != "") {
if ($_POST[email] != "") {
if (mysql_num_rows($user) == 0) {
if (preg_match('~@(corban.edu|)$~', $_POST['email'])) {
if (mysql_num_rows($email2) == 0) {
$sqlquery = "INSERT INTO members (username, password, privlege)
VALUES('$_POST[username]','$encrypted_mypassword','$_POST[privlege]')";
$results = mysql_query($sqlquery);
mysql_close();
print "<p><p>Thanks again for registering and i hope you have a wonderful time.</p>";
?>
<form name="form1" method="post" action="/checklogin.php">
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><strong>Member Login </strong></td>
</tr>
<tr>
<td>Username:</td>
<td><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="mypassword" type=PASSWORD id="mypassword"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</form>
<?
} else {
echo "Email already exists try using <a href='recovery.php'>recovery</a>";
}
} else {
echo "bad email address! Please use a corban.edu email address.";
}} else {
echo "<p> User Already Exists</p>";
}} else {
print "Please Put in an email";
}} else {
print "Please enter a Password";
}} else {
print "Need Please go back and put in an username";
}
?>
</td>
<?
include ("footer.php");
?>Sense i am running out of time on this I will finish this in part 2
More Resources:
Labels:
Linux,
MySQL,
PHP,
Website,
Website Series
Tuesday, August 10, 2010
Around The Web - Issue 1
Around The Web
Issue 1
Date: 07/27/2010
By: Joshua Millikan
Education:
For Those that are looking for For some educational things or just looking to make money off of your old text books the web has many different things for you to find these goodies. Lets start with making money off your old text books as we all like to make money. The Textbook revolt at www.textbookrevolt.com is starting up by some two guys that got tired of text book prices and having to pay a lot of the books. they have created a textbook rental serves where students can list their books that they want to rent out and they get paid to have them rent out. Though this service has not yet started and it is still being create but it will interesting to see where it will be going from there. the idea is good and it is always nice to see people trying to tackle the high prices of textbooks that students have to pay on top of already high tuitions
The next thing would be that of FREE textbooks. Yes you heard it free textbooks. nothing is sweeter to the ears of students than that of the word free. Bookboon is a site that has free textbooks. Not only do they have a website but also have a Facebook application. bookboon.com has a a few topics and looks like they are adding to them. but they have more than just textbooks but also travel guides and business books. Though there is a downside to this as many of the books on here are not many of them are used by professors. Though that may change if professors started reading them to compare them and if they start thinking about how the students don’t want to pay another $100 for another textbook. especially as growing trend of students reading less and less of their text books.
Computers:
Music:
For those that are looking for a program that feels a lot like the Itunes player but want more functionality on other operating systems and other devices and phones. Then they should look no further than that of Songbird. Songbird is a open source music player that gives you the nice feel of Itunes but with so much more. With the openness of the open source to it it brings integration for a web browser and extra plugins. The Web browser looks to be that of mozilla firefox build with the ability to have some of the firefox plugins installed like adblock plus and videodownload helper it sure makes it a wonderful feel to the program. With plugins like concerts that show the artists concert dates next to the artists in your library helps you keep on top of the things happening in your area. It also comes with extentions that bring up the lyrics of the song your listening to and also that of adding a wikipedia info on the artist your listening to. Songbird is something that will make you fall in love with.
Ubuntu:
Ubuntu Maverick is taking up the cause of speed in Ubuntu’s latest upcoming release. It does not add much off of the last release of Ubuntu 10.04 which added a lot to the Ubuntu experience. Though the release is still in its first alpha stage so it will be interesting to see what they have coming in the later releases.
Canonical, the parent of Ubuntu, has announced that they are working on creating out with a multi touch OS that will be made to be able to run on the new upcoming tablet pcs coming out when they do, probably not till mid next year. This will be interesting if they can take a little control of the open source tablet market. Though this will be hard for them to competitor against the likes of Android, Windows 7, and Apple.
Security:
This past year has been busy for Apple they have come out with many new software and new products. They also are not the underdog anymore as they are the surpassed microsoft in their market value. Though a sad note to their success comes with the glory, they have recently became the leader in the world in software insecurities. This does not mean that Apple is starting to become the worst software vender our there but it does show a sign that they are growing and they are having growing pains trying to keep up with the growth and with the fads. Lot of these insecurities do not come from apples operating system but from their software and third party software like flash or java. Third party software is starting to become a real problem for any operating system as it is where a lot of the flaws that compromise the computer come from. It is going to be interesting to see if they stay the leader and how fast they will fix the problems or even if they will omit that they have problems.
Subscribe to:
Posts (Atom)


