Why promote someone else's blog?

30 April 2009

Why re-invent the wheel?

If a blog entry has all already been written why go out there and re-write the same information but in your own words?

Surely linking to the blog that's already been written would be a lot quicker and a lot less hassle.

Plus linking to someone else's blog entry will show blog readers that you do take the time to go out there and read other people's blog entries, rather than just concerntrating on your own.

Linking to someone else's blog gives you credibility for linking to a good source. This doesn't mean that you never need to write another blog entry again, but if the hard work has already been done surely you can just write a few lines summarising the blog and then link to the actual article?

Avoid duplication on the Internet - the worst thing is reading the same blog over and over but written in a different way by a different person.

If you don't want to lose your blog reader altogether then you can add a target of "_blank" which will open the link in a new window. Also, check the blog that you're linking to, and if it has the functionality is there then send it a trackback to show that you're linking to their blog.

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

PHP server variable

29 April 2009

The PHP server variable is a preset variable in PHP.

As the title, server variable, says - it does exactly that, holds an array of data about the server.

Using the server variable in PHP can be handy if you want to find out:

  • Where the user came from (the server referrer)
  • What the current URI is
  • The filename of the executing script
  • The server's IP address
  • The server's name
  • The current query string
  • What web browser (or user agent) is being used to view the website

The list goes on... And you can find the full list at: http://uk3.php.net/manual/en/reserved.variables.server.php

A server variable can be called upon by using $_SERVER['array_item'] where array_item is one of the items held in the server variable array.

For example, to display the name of the user agent (web browser) that is currently being used to display a website you can do this with the server variable by using:

<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

Ok, so it won't often be shown to you what user agent you're using - but it may be used in a "if" statement - If they're using Internet Explorer 6 or below do this, else do something else for example?

You will also want to do a little bit of testing when using this - like Internet Explorer for example is called MSIE (followed by the version number) when being referred to as the user agent.

The server variable is a very useful variable array and can be used in all kinds of ways - have a play and see what you come up with.

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

PHP login example using MySQL and Cookies

28 April 2009

Here I'm going to display a PHP login example.

If your website has any community based activities such as a forum, networking website, some blogging websites, websites that need to hold data on users and websites that need to stop certain users from accessing certain areas of the website then you will need a login script.

In this login example I am going to show you very basically using PHP, MySQL and Cookies. If you're using ASP then this login example will not work on your web server.

Firstly you will need to setup a table on an online database. The table should be called something like "users" or "logins".

For a very basic login example the online database table will only need 3 fields - id, username and password.

Seperate from this login example you will need to create a register page which will populate your online database table with the relevant values, and also be sure to encrypt the passwords when they're being saved using the md5() function.

On our login example page we're going to display 2 text boxes, username and password, and then a submit button.

<form action="login.php" method="post" name="login">
<p><label for="username">Username:</label><br />
<input name="username" id="username" value="" type="text" /></p>
<p><label for="password">Password:</label><br />
<input name="password" id="password" value="" type="password" /></p>
<input type="submit" name="submit" value="Login" />
</form>

Once the form is submitted it will go to the page login.php which is the page we're currently on.

Above the login form on the same login example page we're going to add some PHP which will check the login.

<?php
if (isset($_POST['submit'])) //If the form has been submitted
{
//Connect to database
$query = "SELECT password FROM logins WHERE username = '" . $_POST['username'] . "'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
mysql_close();
if ($row['password'] == md5($_POST['password'])) //Remember to encrypt our value
{
//Login success
header ("Location: login_success.php"); //Redirect the user to a logged in page
exit; //Do not display any more script for this page
}
else
{
//Login area, display the login form as before
}

This login example is very simple and will need to carry out some error checking and also you'll want to addslashes in order to stop anyone from carrying out a MySQL injection. A MySQL injection is a way of hacking the login script to log anyone in. They even have the power to delete everything on your database table!

Also you will notice in the login example above that I have a PHP comment saying "//Connect to database" - here you will need to either include a file that connects to your database, or add in the database connection string.

Like I say this is a very basic PHP login example, please make sure you play with this code to make the script more secure.

Permalink     Comments (1)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

PHP from, or PHP form?

27 April 2009

When first starting to learn PHP from online tutorials it, to me, was epic!

I started learning PHP from a site called www.tizag.com/phpT/ and found this really helpful.

Now, though, when I get an error or problem the tutorials aren't that much help and so I find my answers to my issues in PHP from forums.

PHP from is a very common misspelling of a PHP form.

If you did type "PHP from" instead of "PHP form" then you're in the right place...

PHP forms can have either a "post" or "get" method - which will depend on how the values can be received at the next page.

The "post" method will send the values, but hidden to the page's URL, whereas the "get" method will send the values in the URL using page.php?variable1=value1&variable2=value2 etc.

To decide which page the website directs the user to once they've clicked "submit" you will need to also define this at the top of the form using the "action" attribute.

An example of the top of a PHP form would be:
<form method="post" action="target_page" name="myform">

The only other attribute you may need to use when setting up the form would be "enctype", which defaults as "plain/text", but can also be used to send "multipart/form-data" or "application/x-www-form-urlencoded".

I've never personally used "application/x-www-form-urlencoded", but the "multipart/form-data" will be needed if you're uploading files when using the form.

Now building the form you will need <input> tags and maybe a <textarea> tag if you want to use some open text areas. Then close the form using </form>

On the target page you will need to use PHP to retrieve the values sent via the form on the previous page.

If it was a "post" method then use:
$variable1 = $_POST['variable1'];

Or if it was a "get" method then use:
$variable1 = $_GET['variable1'];

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

CSS with...

26 April 2009

CSS stands for Cascading Style Sheet - and is the area where we style the rest of the website by tag, class or id.

On a HTML document it will link to the CSS with a link tag at the top:
<link rel="stylesheet" href="/style_sheet_path/style_sheet_file.css" type="text/css" />

This tag will load the CSS with the styling for all the page elements by tag, class or id.

If you're writing a website in PHP then the styling can be added by CSS with the same code as above, however if it's within the PHP area then the line will need to be echoed like:
<?php
echo "<link rel="stylesheet" href="/style_sheet_path/style_sheet_file.css" type="text/css" />";
?>

Editing CSS with JavaScript is also common on websites, like having an area of text held in a <div> being hidden, but then showing the <div> area when a link is clicked.

Another common use of CSS with websites is when using sub navigation on drop downs. The way this will work is to use <ul> tags for the navigation and then embedding <ul> tags within the first <ul> for the sub navigation and setting the second <ul> to "display:none" until the hover or focus on the <li> tag within the first <ul> area will show the second <ul> area.

If you can't use CSS with a website then you may need to keep the CSS within the same HTML document by using the <style> tag at the top of the page and declaring the element's styles here.

It is always better to define your CSS with an external file though as this will mean only editting one file and it will effect every page linked to the CSS file.

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

_request php variable

24 April 2009

When writing in php you can set a lot of variables, and also there are a lot of pre-defined variables - such as the $_REQUEST php variable.

The $_REQUEST php variable is used to pick up any $_POST or $_GET variables. It doesn't matter whether the form has posted or sent a query string and the $_REQUEST php variable will be able to read this.

The $_REQUEST php variable, similar to the $_POST and $_GET php variables, holds an array of values that have been passed to the current page you're on.

The $_POST php variable will hold an array of all posted values to the page, the $GET php variable will hold an array of all the query string variables passed to the page and the $_REQUEST php variable will hold an array containing both $_POST and $_GET variables.

Say a form has been filled out and one of the fields is called "name". On the page where the form data has been posted to you can display this variable's value by using either $_POST['name'] or $_REQUEST['name'].

If you're submitting a form and are sending posted data and it's going to a page with a query string then it's best to use the $_REQUEST php variable as this can put all the values into one array.

When calling from the $_REQUEST php array you will need to use the same value given to the original variable name, e.g from a form it will be the name given to the <input> tag, or if it's from a query string it will be the part before the "=" symbol.

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

Facebook analysis

23 April 2009

If we want to do a Facebook analysis to see how it is benefitting your website's traffic then you can use an analytics program on your website.

Google analytics for instance will tell you which website referred the traffic to you and so you can find out if it was Facebook or not that referred the traffic.

If you're using Facebook as an online business presence then in order to do some Facebook analysis you will need to have set up your business presence as a page, as apose to a profile or a group.

Facebook page's can provide, the administrator of the page, insights which will allow the user to carry out some Facebook analysis.

From Facebook insights you can find out how many people visited your page and how many fans your page has - and on top of this find out how many videos or pictures have been viewed, whether the visitor is male or female and also the person's age.

A lot of analysis can be carried out using a Facebook page which will help your business presence on Facebook target your key customers more directly.

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

How long before website changes take effect?

22 April 2009

Google has said that it can take up to 3 months to crawl a website, meaning that when you change your website it may take these 3 months in order to notice the effects take place in search engines.

If it's a new website that you're putting live then to get best results you will need to:

  • Submit your website to Google and the other main search engines
  • Submit a sitemap to Google
  • Link to your website from another high quality website - so that when the other website gets crawled Google will pick up your website and add it to their list of websites to crawl

If the website has been running for a while then there's not a lot more you can do - but re-submitting your sitemap can't hurt (as long as it's not too often).

If it's a blogging website then it's an idea to ping Google with your latest blog entry as and when they become live.

If you still notice no changes after a while then it may mean that the change's you've made were not significant enough to have effected Google's ranking for your page.

To keep tracks on what Google crawls and what they've already crawled it's worth setting up Google Webmaster Tools which will help you keep tracks of what Google has crawled, any errors and how many websites are linking to you.

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

Displaying a directory's files using PHP

21 April 2009

I was approached by a client recently who wanted a lot of files placed on their website for users to either view or download.

When I looked into this further there was over 70MB worth of files and so I uploaded them all to a directory within their own category directory.

Now that they were uploaded I didn't want to mess around trying to add them to a database and display them this way so instead I used the opendir() and readdir() functions in php.

The opendir() function first opens a directory, and then the readdir() function can be used in a while loop to display them.

When displaying the files they will seem to be in quite a random order and the list will also include ".", "..", and sub directory names.

Firstly I wanted to strip out the "." and ".." file names as these were just a way of navigating up one level, and then I wanted to display the sub directories as links which would show/hide the directories contents.

The code I came up with for this is:

<?php
$base_dir = "documents";
$handle = opendir($base_dir);
$file_counter = 0;

while (($file = readdir($handle))!==false)
{
    if ($file == "." || $file == "..")
    {
    }
    else
    {
        if (strstr($file,".") === false)
        {
            $file_counter = $file_counter + 1;
            $handle2 = opendir($base_dir . "/" . $file);
            echo "<div style="margin-left:20px;">
            <h2><a href="#" onclick="show_hide('area_" . $file_counter . "'); return false;">" . $file . "</a></h2><div id="area_" . $file_counter . "" class="insurances_tree">";
            while (($file2 = readdir($handle2))!==false)
            {
                if ($file2 == "." || $file2 == "..")
                {
                }
                else
                {
                    if (strstr($file2,".") === false)
                    {
                        $file_counter = $file_counter + 1;
                        $handle3 = opendir($base_dir . "/" . $file . "/" . $file2);
                        echo "<h3><a href="#" onclick="show_hide('area_" . $file_counter . "'); return false;">" . $file2 . "</a></h3><div id="area_" . $file_counter . "" class="insurances_tree">";
                       
                        while (($file3 = readdir($handle3))!==false)
                        {
                            if ($file3 == "." || $file3 == "..")
                            {
                            }
                            else
                            {
                                if (strstr($file3,".") === false)
                                {
                                    echo "<strong>" . $file3 . "</strong>";
                                }
                                else
                                {
                                    echo "<a href="/" . $base_dir . "/" . $file . "/" . $file2 . "/" . $file3 . "" target="_blank">" . $file3 . "</a><br />";
                                }
                            }
                        }
                        echo "</div>";
                        closedir($handle3);
                    }
                    else
                    {
                        echo "<a href="/" . $base_dir . "/" . $file . "/" . $file2 . "" target="_blank">" . $file2 . "</a><br />";
                    }
                }
            }
            echo "</div>";
            closedir($handle2);
        }
        else
        {
            echo "<a href="/" . $base_dir . "/" . $file . "" target="_blank">" . $file . "</a><br />";
        }
        echo "</div>";
    }
}
closedir($handle);
?>

The only addition to this code that you will need is to hide the div's containing the sub directory files and also add a javascript function called show_hide which will look something like this:

function show_hide(id)
{
    if (document.getElementById)
    {
        obj = document.getElementById(id);
        if (obj.style.display == "block")
        {
            obj.style.display = "none";
        }
        else
        {
            obj.style.display = "block";
        }
    }
}

Permalink     Comments (0)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us

Best ways of link building

20 April 2009

The best way of getting links back to your website is to help others and give them content that they're going to want to link to.

If this fails then you'll have to find other ways of getting those priceless links back to your website.

A lot of websites these days have a "nofollow" tag in the link and so these are no good for search engines - only for driving traffic to your website, so for starters let's avoid a website that has a "nofollow" link attribute.

Blog
When leaving a comment on a blog you will often find a "website url" field - this turns your name (who's leaving the comment) into a hyperlink back to teh website url that you entered.

Again if other comments have a nofollow then they're not going to help with search engines - but if you have something to say then you might as well!

Forums
When signing up to forums you'll quite often have a control panel where you can change your password, chose a different avatar, edit your signature, etc... Your forum signature is the key here as you can write what you want down there.

In my signature I'd always include my website link as on a forum it is a way of getting your website link all over the website really quickly - just contribute lots! Again if they're nofollow then the search engines will find no value here - but traffic to the website may be generated.

Online directories
Now with online directorites you have to be a bit careful.

Some online directories will take your website and send them to lots of directories all over the Internet, but this is a bad thing. Too many links back to your website in a short amount of time will lead to Google noticing that there's a big chance that you might be cheating.

It's better to submit your website to each online directory seperately.

Still be warey as to which ones you chose as you don't want lots of incoming links from spammy websites. Also be careful when they ask for money - as again, it could be a scam.

Articles and press releases
This I'd say is a great way to get links back to your website.

Write an article or press release and then submit it to the article and press release directories, just make sure you include a link back to your website (the originating website).

I haven't done much of this myself, so again I'd look out for scams and spammy websites, but if you find the right ones to submit to then this could be a great way to get your articles out there and, therefore, get your website's link all over the Internet.

Permalink     Comments (2)     Trackbacks (0)

Share this on Facebook  Share on Twitter   Google  Yahoo  Technorati  Reddit  Digg  del.icio.us