Need help setting up an email. Check through our amazing guides

Designing a website

Sitting down to design your website can be a daunting experience, you’ve bought your domain name and hosting package, now what? You head over to google and type "designing a website", click search and millions of results are returned from, web design agencies to step-by-step guides and web design software. You start clicking through the step-by-step guides, before you know it you’re reading about screen resolutions, page layout, jpegs, html, css, etc. We’ve all been there, we start by looking for information on a particular topic and get swept along by the shear volume of information available, sure we pick up valuable information along the way but it’s not always relevant to what we need to get the job done. So stop, put down the mouse, step away from the computer and grab a pen and some paper we’re going to delve into the world of Information Architecture. Requirements Gathering The first step to creating a good website is to define the sites goals. It may sound like an obvious thing to do, but think of all those terrible sites you’ve been to in the past. Do you think the people designing those sites thought about their goals? Defining the sites goals will establish a clear idea of what you are about to do and what you are trying to achieve, without them why bother building a site? To define your goals start by asking yourself or your company some questions designed to clarify the purpose of the site: What is your personal vision or mission of the company? Why will people visit your site? Who is the site intended for? The first question is very important and will help define your website. The answer should explain what it is that you want to achieve. It doesn't have to be complicated, it could even be a one line statement e.g. AMAZON.COM - Earth's Biggest BookStore EBAY.COM - The World's Online Market Place FACEBOOK.COM - Connect and share with the people in your life. The answers from the last question "Who is the site intended for?" can be turned into audience goals (i.e. what users of the site will be trying to achieve). Depending on whether you are designing for yourself or a company will dictate how much filtering of the answers you’ll have to do. Either way you should have a list of answers that need to be refined into goals. Start by rephrasing your answers into a list of goals and group similar ones together. Once you have done this you need to prioritise the list and give the ones that you grouped category names. You now have a clear set of goals, a purpose for your website. Site Content By now you should know what your site is going to be about and who it is for and can now start to think about the actual content of the site. Using your list of goals create a new list of content elements required for the site. It may help to break these elements into two types static and dynamic. About Us, Privacy Policy and Terms and Conditions are examples of static content. Site searches, user login and newsletter subscription are all examples of dynamic content. By separating the two types of content you will also be able to see, primarily from the dynamic types, the functionality required for your site. Once you have this list it is a good idea to go and look on the Internet for similar websites or competitors and see if there are any pages or elements you have missed. Next you need to prioritise your content elements list and work out whether you have the necessary skills, technology, budget and time to achieve them, inevitably some may drop off the list or be considered out of scope for the first iteration. Once you are done you can begin to organise the content elements which will provide the basis for the site structure. Start by grouping the content elements and when you are happy with the groups, name them. This will help define the major sections of your website and in turn your site structure. At this point you may want to consider how you go about gathering and collating the actual content for pages of your website and may find content templates useful. Site Structure By now you should know what your sites purpose is, who it is for and the type of content it is going to contain. The next step is to define the structure of the site upon which everything else is built. You can start by creating a hierarchical map of the site, very similar to a table of contents for a document. Using the major sections defined earlier you can start to create a site structure listing e.g. Section 1 Section 1.1 Section 1.2 Section 2 Section 2.1 Section 2.1.1 Many people find it difficult to work with lists like these when thinking about how the site is going to fit together, which is where sitemaps can help. They give a more visual representation of the site structure and how the content elements are grouped and relate to each other. You can download software that can help you develop a sitemap in an intuitive and visual way (e.g. smartdraw.com), but to begin with a pencil, ruler and a large sheet of paper will do fine. Now we are ready to define the navigation for your site. Take a look at the site structure and identify the major sections, these should be the candidates for the main consistent navigation system that appears on every page allowing your users to quickly switch between sections. As a rule of thumb try to limit the main navigation to around 5 elements. You may also have pages that are related to each other and wish to show local navigation between them e.g. in a FAQ page sidebar show links to related FAQs. Where possible you should try to document the main and local navigation for a page, it can be as simple as a list or short description. This will prove invaluable when you get around to looking at page layout. Visual design When you read the title of this guide I bet you didn’t think it would take this long to get to graphical element of designing your website. Just before you go and fire up your favourite graphics package and start mocking up pages, lets just consider page layout first. Before you start introducing colour, photos, icons, logos, etc. you need to work out what content elements require prominent placement on the page. There are two commonly used techniques to depict layout of content without the distraction of graphical elements, theses are wireframes and grey boxes. Start by looking at all the page types you have defined in your site structure, most of the pages should have many common elements across the main sections (e.g. branding, navigation, page titles, sidebar, footer), but may have slightly different purposes (e.g. sales pages as opposed to user control panel). Try to come up with two or three page types that you can use as the basis for all of the others. This is an iterative process so expect to revise your wireframes or grey boxes several time. OK, now you’re are ready to pull out the sketch pad and fire up that graphics package, integrating the page layouts with graphical elements and producing mock-ups that look as close to the actual pages as possible. You now have all of the material you need to start constructing a prototype website. Whether you decide to hand code the website yourself, use a package like Serif WebPlus or employ a professional designer to do it, everything should effortlessly fall into place because you have taken the time to plan your site first.

How to create an email form with Perl

Form handling in Perl can be a very involved process. Below is a step-by-step for creating a simple feedback form. A visitor to your website fills this out and the information is emailed to you. Create the web form First we need to create a simple HTML form, to start with we'll keep the form simple by just asking for the users email address and comments. Here is our HTML form: <html> <head> <title>Simple Feedback Form</title> <style>label{display:block;}</style> </head> <body> <form action="/cgi-bin/feedback_form.cgi" method="post"> <label>Email Address</label> <input type="text" name="email_address" size="40"> <label>Your Feedback</label> <textarea name="feedback" cols="50" rows="10"></textarea> <input type="submit" name="send" value="Submit"> </form> </body> </html> This form will send two parameters to our cgi script, email_address and feedback. Save this file as feedback_form.html and upload it to the web folder on your hosting. Create the form script We're going to use the CGI.pm Perl module to help make writing our cgi script easier. At the top of the script we start with the location of the perl interpretor, then we tell Perl we want to use the CGI.pm module and create a new cgi object: #!/usr/bin/perl use CGI; my $cgi = new CGI; The CGI.pm module is object-orientated, this means all of the CGI.pm functions and data are accessed through an instance of CGI.pm, in our script this instance is called $cgi. Lets use our CGI object to retrieve the information from the form the user filled in. To access the form parameters we can use the CGI objects param function: my $email_address = $cgi->param('email_address'); my $feedback = $cgi->param('feedback'); We store the form data in two local Perl variables, $email_address and $feedback. Filtering user submitted data Whenever you write a cgi script that receives data from an unknown source you should always filter the data to make sure it doesn't contain anything harmful. For example, if we don't filter the data in our form it would be quite easy for a Hacker to use our cgi script to send out spam to thousands of people. The golden rule is never trust any data you haven't created or don't control. To filter our user data we're going to create two filter functions: sub filter_email_header { my $form_field = shift; $form_field = filter_form_data($form_field); $form_field =~ s/[\0\n\r\|\!\/\\^\$\%\*\&]+/ /g; return $form_field; } sub filter_form_data { my $form_field = shift; $form_field =~ s/From://gi; $form_field =~ s/To://gi; $form_field =~ s/BCC://gi; $form_field =~ s/CC://gi; $form_field =~ s/Subject://gi; $form_field =~ s/Content-Type://gi; return $form_field; } The first filter function removes special characters which could be used to trick our script into sending spam and is applied to the $email_address data.The second filter function removes common email headers from the data the user submitted and can be applied to both $email_address and $feedback. We'll place the two functions at the bottom of our script. Now we'll call the two filter functions to clean up our user submitted data: $email_address = filter_email_header($email_address); $feedback = filter_form_data($feedback); Emailing the feedback Once we have the filtered data we need to email it back to you. Our web hosting servers run a local mail server (sendmail) that your cgi script can use to send email. To send the email our cgi script opens a communication channel to the sendmail program using the pipe (|) symbol. It then prints all the information necessary to send an email across that channel: open ( MAIL, "| /usr/lib/sendmail -t" ); print MAIL "From: $email_address\n"; print MAIL "To: you\@domain.com\n"; print MAIL "Subject: Feedback Form Submission\n\n"; print MAIL "$feedback\n"; print MAIL "\n.\n"; close ( MAIL ); Make sure you set your email address on line 3, you'll need to escape the @ symbol by putting a backslash (\) before it because Perl uses the @ symbol to denote a special type of variable. The two newline characters (\n\n) at the end of line 4 are used to mark the end of the email headers ready for the content. The \n.\n on line 6 prints a dot (.) on its own line to tell sendmail that we've finished printing the message. Thank the user for their feedback Finally, when a user submits your form, let's show a page thanking them for their feedback: print $cgi->header(-type => 'text/html'); print <<HTML_PAGE; <html> <head> <title>Thank You</title> </head> <body> <h1>Thank You</h1> <p>Thank you for your feedback.</p> </body> </html> HTML_PAGE The first thing we do is print back the HTTP header, using the CGI header function, to let the web browser know what type of content to expect. Then we print out the HTML page. The final script This example script shows a very basic way to get form contents emailed to you, it doesn't however have the refinements of a professional script, e.g. input validation. Below is the finished script. We've added some comments (lines beginning with #) to help make it clearer. #!/usr/bin/perl use CGI; # Create a CGI.pm object my $cgi = new CGI; # Get the form data my $email_address = $cgi->param('email_address'); my $feedback = $cgi->param('feedback'); # Filter the form data $email_address = filter_email_header($email_address); $feedback = filter_form_data($feedback); # Email the form data open ( MAIL, "| /usr/lib/sendmail -t" ); print MAIL "From: $email_address\n"; print MAIL "To: you\@domain.com\n"; print MAIL "Subject: Feedback Form Submission\n\n"; print MAIL "$feedback\n"; print MAIL "\n.\n"; close ( MAIL ); # Print the HTTP header print $cgi->header(-type => 'text/html'); # Print the HTML thank you page print <<HTML_PAGE; <html> <head> <title>Thank You</title> </head> <body> <h1>Thank You</h1> <p>Thank you for your feedback.</p> </body> </html> HTML_PAGE # Functions to filter the form data sub filter_email_header { my $form_field = shift; $form_field = filter_form_data($form_field); $form_field =~ s/[\0\n\r\|\!\/\\^\$\%\*\&]+/ /g; return $form_field ; } sub filter_form_data { my $form_field = shift; $form_field =~ s/From://gi; $form_field =~ s/To://gi; $form_field =~ s/BCC://gi; $form_field =~ s/CC://gi; $form_field =~ s/Subject://gi; $form_field =~ s/Content-Type://gi; return $form_field ; } Save this script as feedback_form.cgi and upload it to the cgi-bin on your web hosting. Make sure you set the file permissions for the script to 755. Follow our How to change file permissions via FTP guide for instructions on how to do this. Now you're ready to test your feedback form. Load your feedback form in your browser, http://www.domain.com/feedback_form.html, fill the form in and submit it. If everything works you should receive an email containing what you just entered in the form. If not, try checking out our Troubleshooting common Perl issues guide.

How to create an email form with PHP

PHP was designed for making interactive web pages and mixing functionality with HTML. Form handling in PHP is quite a simple process. Here is a step-by-step guide for creating a simple feedback form. A visitor to your website fills this out and the information is emailed to you. Create the web form First we need to create a simple HTML form, to start with we'll keep the form simple by just asking for the users email address and comments. Here is our HTML form: <html> <head> <title>Simple Feedback Form</title> <style>label{display:block;}</style> </head> <body> <form action="/feedback_form.php" method="post"> <label>Email Address</label> <input type="text" name="email_address" size="40"> <label>Your Feedback</label> <textarea name="feedback" cols="50" rows="10"></textarea> <input type="submit" name="send" value="Submit"> </form> </body> </html> This form will send two parameters to our PHP script, email_address and feedback. Save this file as feedback_form.html and upload it to the web folder on your hosting. Create the form script First we receive the data from our form and store it in two PHP variables, $email_address and $feedback. <?php $email_address = $_POST['email_address']; $feedback = $_POST['feedback']; Filtering user submitted data Whenever you write a PHP script that receives data from an unknown source you should always filter the data to make sure it doesn't contain anything harmful. For example, if we don't filter the data in our form it would be quite easy for a Hacker to use our PHP script to send out spam to thousands of people. The golden rule is never trust any data you haven't created or don't control. To filter our user data we're going to create a functions: function filter_email_header($form_field) { return preg_replace('/[\0\n\r\|\!\/\\^\$\%\*\&]+/','',$form_field); } The filter function removes special characters which could be used to trick our script into sending spam and is applied to the $email_address data. We'll place the two functions at the bottom of our script. Now we'll call the filter function to clean up our user submitted email address: $email_address = filter_email_header($email_address); Emailing the feedback Once we have the filtered data we need to email it back to you. Our web hosting servers run a local mail server that a PHP script can use to send email. This can be done using the PHP in-built mail function: $headers = "From: $email_address\n"; $sent = mail('you@domain.com', 'Feedback Form Submission', $feedback, $headers); Make sure you set your email address on line 2. Thank the user for their feedback Finally, when a user submits your form lets show a page thanking them for their feedback: if ($sent) { ?><html> <head> <title>Thank You</title> </head> <body> <h1>Thank You</h1> <p>Thank you for your feedback.</p> </body> </html> <?php } else { ?><html> <head> <title>Somthing went wrong</title> </head> <body> <h1>Somthing went wrong</h1> <p>We could not send your feedback. Please try again.</p> </body> </html> <?php } ?> The final script This example script shows a very basic way to get form contents emailed to you, it doesn't however have the refinements of a professional script, e.g. input validation. Below is the finished script. We've added some comments (lines beginning with #) to help make it clearer. <?php #Receive user input $email_address = $_POST['email_address']; $feedback = $_POST['feedback']; #Filter user input function filter_email_header($form_field) { return preg_replace('/[\0\n\r\|\!\/\\^\$\%\*\&]+/','',$form_field); } $email_address = filter_email_header($email_address); #Send email $headers = "From: $email_address\n"; $sent = mail('you@domain.com', 'Feedback Form Submission', $feedback, $headers); #Thank user or notify them of a problem if ($sent) { ?><html> <head> <title>Thank You</title> </head> <body> <h1>Thank You</h1> <p>Thank you for your feedback.</p> </body> </html> <?php } else { ?><html> <head> <title>Somthing went wrong</title> </head> <body> <h1>Somthing went wrong</h1> <p>We could not send your feedback. Please try again.</p> </body> </html> <?php } ?> Save this script as feedback_form.php and upload it to the root of your web hosting on your web hosting. Now you're ready to test your feedback form. Load your feedback form in your browser, http://www.domain.com/feedback_form.html, fill the form in and submit it. If everything works you should receive an email containing what you just entered in the form. If not, try checking out our Troubleshooting common PHP issues guide.

How to password protect a website folder using .htaccess

It can sometimes be useful to protect areas of your website, for example you have pages that you only want your friends to see. To add password protection to your website you need to create a file to store usernames/passwords and add some code into a .htaccess file. Creating the password file The password file is a simple text file that contains username and password separated by a colon (:). However the password must be encrypted. There are lots of free tools that will encrypt the password for you or you can use our tool below. Simply enter a username and password and we'll generate a string of text that you can copy and paste. $( document ).ready(function() { $("#htpasswd_submit").click(function(click_event) { $("#htpasswd_results_area").addClass("updating"); $("#htpasswd_submit").val("updating"); $.ajax({ type: "get", url: "/support/articles/generate_htpasswd", data: "username="+ $("#htpasswd_username").val() + "&password=" + $("#htpasswd_password").val(), success: function(data) { $("#htpasswd_results_area").show(); $("#htpasswd_submit").attr("disabled", false); $("#htpasswd_submit").val("Generate Encrypted Password"); $("#htpasswd_results_area").removeClass("updating"); $("#htpasswd_result").html(data); } }); click_event. preventDefault(); }); }) Username: Password: Result: Open a plain text editor, such as Notepad on Windows or TextEdit on Mac, and copy and paste the username/password string into it. Save this file as ".htpasswd". Now you need to upload this file to your website using FTP. For extra security make sure that it is outside of your web folder so that it can never be accessed by someone going to http://www.domain.com/.htpasswd. Our hosting servers will block web access to any files beginning with .ht, but it is bad practice to put the password file in a publicly accessible folder. Creating the .htaccess file Once you have created and uploaded your .htpasswd file you'll need to create a .htaccess file to tell the web server what folder you want to protect and what username/password file to use. Open a plain text editor (e.g. Windows - notepad, Mac – textedit) and put in the following code: AuthType Basic AuthName "My Protected Folder" AuthUserFile /www/sites/5ce/448/www.domain.com/.htpasswd require valid-user Let's go through the parameters you've just set: Line 1 - Defines the type of authentication the web server will use, Basic is perfectly adequate for what we need. Line 2 - Sets the title of the username/password box that will popup when someone tries to view your protected page. Line 3 - Tells the web server where to find the username/password file. To find out the full path to your web folder login to you account, click the hosting icon, click on the manage link for your hosted domain. The full path is displayed in the Document Root row under Hosting Summary. Line 4 - Tells the web server who in your .htpasswd file can access your folder, by using valid-user everyone in the file can view the folder. Where to upload your .htaccess file The .htaccess file above will protect all of the files in the folder it is uploaded into, and all of the sub-folders under it. For example if you wanted to protect your entire website you could place the .htaccess file in your hosting web folder.

How to change PHP version

This guide explains how to change the PHP version used by your website, for customers using LCN.com Web hosting or WordPress hosting. Let’s get started… Log in to your LCN.com account. Click the Hosting icon: click Manage site which is located beside the hosting package that you want to manage. Look for the heading Scripting Support under the Site Summary section of this page. Use the drop-down menu to select the PHP version you’d like to be applied to your site. This will then take up to 15 minutes to take effect. Your browser does not support the video tag. That’s it! You’ve changed your PHP version.

Troubleshooting common PHP issues

This guide will explain how to troubleshoot some more common issues with scripting in PHP. For customers using LCN.com Web hosting and WordPress hosting. Turn on error reporting If you're having problems, one of the first things may want to do is enable error reporting. Error reporting takes a lot of the guess work out of debugging your code and should give you a good place to start. To turn on error reporting, include these lines of code at the top of your PHP script. ini_set('display_errors',1); error_reporting(E_ALL); Note: Remember to turn off error reporting once you have fixed your issue. Leaving it enabled may show unwanted output to your visitors. Broken Syntax Often problems with PHP code are cause by something very simple. Check your syntax and look for broken code highlighting (if your editor supports it). PHP code being displayed instead of running If you're code is being displayed on your website instead of running make sure all your files are saved with the .php extension. Another possible reason for this is that PHP is not enabled on your hosting. We don't enable PHP on our Starter hosting package, so if you wish to run PHP and are using this package you will need to upgrade. PHP version compatibility issues With the arrival of PHP7 there are a few incompatibilities with older PHP versions as well as new features that aren’t backwards compatible. Before switching your website over to PHP7 we’d advise testing any PHP included in your site. A list of backward incompatible changes from PHP 5.6.x to 5.7.x can be found here and a list of new features can be found here You can change the version of PHP your web hosting uses from within your LCN.com account, which you can learn how to do by reading our handy guide. PHP page loads continuously If you're using loops within your PHP code you may run into problems where by your script seems to never stop loading. A common cause of this problem is that the loop isn't counting properly. One way to debug this is to echo() the current count number at the beginning of each loop cycle, this will hopefully give you a better idea of where the problems lies. If you're not using loops and your page is continuously loading you should double check any HTML or Javascript code. Advanced troubleshooting and PHP knowledge sharing We highly recommend the very active discussion forum (PHP Builder) for discussing all aspects of PHP - www.phpbuilder.com/board.

What is a .htaccess file?

.htaccess files are configuration files that let you control how your website is accessed e.g. password protect access to content or rewriting long web addresses to shorter, easier to remember ones. A .htaccess file is a simple text file. Its name looks similar to a file extension like .txt or .html, however the entire filename is just .htaccess. You can use any plain text editor to create a .htaccess file (e.g. Windows - notepad, Mac – textedit). Some computers hide .htaccess files in folders by default. Windows On Windows you will need to turn on the Show hidden files and folders option under Folder and Search Options. Mac On Mac you will need to run the following Terminal commands: defaults write com.apple.finder AppleShowAllFiles FALSE killall Finder This will show you all of hidden files and folders on your Mac, note that editing hidden files can break things. To stop showing all hidden files run the same command again but replace TRUE with FALSE. Some FTP programs don't show .htaccess files by default. To show hidden files in Filezilla follow our How to change file permissions via FTP guide for instructions on how to do this.

How to use a database with PHP

Using a database is a very common task for PHP scripts but it can be a very involved process. Below we'll step through connecting to, inserting records and querying a database and displaying back the results. PHP has many predefined functions for dealing with MySQL databases, you can find a full description of these at: http://php.net/manual/en/book.mysql.php. Your database details If you haven't already created a MySQL database you can follow the How to create a MYSQL database guide. For the purpose of this example we'll use the database name my_database, remember to replace this with your actual database name. Connecting to the database <?php $database_username = 'username'; $database_password = 'password'; $database_host = 'database.lcn.com'; $database_name = 'my_database'; $connection = mysql_connect($database_host, $database_username, $database_password); if(!$connection) { // if our attempt to connect failed die('Could not connect: ' . mysql_error()); } mysql_select_db($database_name, $connection); // makes other mysql_ functions act on this database ?> Lines 2-5 - Declare variables to store our access details. Line 7 - Uses the variables to connect to our database. A reference to our database connection is now stored in the $connection variable – which we'll use next to perform some actions on our database. Lines 8-10 - If we couldn't connect for any reason we raise an error message. Line 11 - Selects our database, so that any other mysql_ functions after this will work on our database. Connecting to the database Databases organise their records into tables. Each table should only contain one type of information. In this example we'll create a simple table to store contact information that hold First Name, Last Name and Email Address. <?php $sql = "CREATE TABLE IF NOT EXISTS Contacts ( FirstName varchar(64), LastName varchar(64), EmailAddress varchar(255))"; // Execute query mysql_query($sql,$connection); ?> Lines 2-5 - Store a SQL query that will create our contacts table. We've declared FirstName and LastName as VARCHARs (variable characters, which is what we usually use for short text) with a length of 64 characters which should work for some pretty long names, and EmailAddress as a VARCHAR with a length of 255 characters, as Email Addresses can be quite long. Line 8 - Will run our SQL query on the database, and create our table. Inserting Records into our new table Our next step is to start filling our table with information. mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Peter', 'Griffin', 'peter@thehappygoluckytoyfactory.com')"); mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Homer', 'Simpson', 'homer@springfieldpowerplant.com')"); mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Philip', 'Fry', 'pjfry@planetexpress.com')"); mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Peter', 'Bishop', 'peter@thebishops.com')"); This code will insert 4 records into our Contacts table. Now that we have some data, we'll take a look at how we look up and fetch data from our table. Querying our database We're now going to find all the records from our Contacts table that have the FirstName "Peter". $results = mysql_query("SELECT FirstName, LastName, EmailAddress FROM Contacts WHERE FirstName='Peter'"); This code will put an Array containing the FirstName, LastName and EmailAddress fields from records with a FirstName of 'Peter' into the variable $results. Displaying our results We're now going to print our results into an HTML table. echo "<table border='1'> <tr> <th>FirstName</th> <th>LastName</th> <th>EmailAddress</th> </tr>"; while($row = mysql_fetch_array($results)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['EmailAddress'] . "</td>"; echo "</tr>"; } echo "</table>"; Lines 1-6 - Begins our table and creates some headings for our table. Lines 8-15 - Loop over each of our results, and prints out a new row in our table. Line 16 - Closes our table. Disconnecting from the database mysql_close($connection); It's important that we make sure to close our connection to the database at the end of our script, so that we don't end up leaving connections open. Having a lot of unclosed connections can cause issues. The final script <?php // Connect to the database $database_username = 'username'; $database_password = 'password'; $database_host = 'database.lcn.com'; $database_name = 'my_database'; $connection = mysql_connect($database_host, $database_username, $database_password); if(!$connection) { // if our attempt to connect failed die('Could not connect: ' . mysql_error()); } mysql_select_db($database_name, $connection); // makes other mysql_ functions act on this database // Create our table $sql = "CREATE TABLE IF NOT EXISTS Contacts ( FirstName varchar(64), LastName varchar(64), EmailAddress varchar(255))"; mysql_query($sql,$connection); // Insert some records mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Peter', 'Griffin', 'peter@thehappygoluckytoyfactory.com')"); mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Homer', 'Simpson', 'homer@springfieldpowerplant.com')"); mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Philip', 'Fry', 'pjfry@planetexpress.com')"); mysql_query("INSERT INTO Contacts (FirstName, LastName, EmailAddress) VALUES ('Peter', 'Bishop', 'peter@thebishops.com')"); // Query our Database $results = mysql_query("SELECT FirstName, LastName, EmailAddress FROM Contacts WHERE FirstName='Peter'"); // Print out our results echo "<table border='1'> <tr> <th>FirstName</th> <th>LastName</th> <th>EmailAddress</th> </tr>"; while($row = mysql_fetch_array($results)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['EmailAddress'] . "</td>"; echo "</tr>"; } echo "</table>"; // Close our connection to the database mysql_close($connection); ?> If you have any problems running this script try reading our PHP troubleshooting guide.

How to shorten a web address using .htaccess

Redirecting web addresses is a common use for .htaccess when addresses become too long or complicated. For example, if you had a blog running on your website and you wanted to share a post you had made the address could look something like: http://www.mydomain.com/how-to-use-htaccess-to-redirect-long-urls/ Using .htaccess we could create a redirect that is easier to type and remember e.g. http://www.mydomain.com/htaccess This technique is often referred to as url rewriting. Here is what our .htaccess file would look like: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^/htaccess$ /how-to-use-htaccess-to-redirect-long-urls [L] </IfModule> Lines 1 and 4 - Wrap our rewrite rule in a container that checks rewriting is available. Lines 2 - Turns rewriting on. Lines 3 - The rule says if there is a request for 'www.mydomain.com/htaccess' rewrite (redirect) it to 'www.mydomain.com/how-to-use-htaccess-to-redirect-long-urls'. Finally the [L] means don't process any more rules. Once you have created your .htaccess file you just need to upload it to the web folder for your hosting using FTP.

How to use a database with Perl

Connecting to a database is a very common task for cgi scripts but it can be a very involved process. Below we'll step through connecting to, inserting into and querying a database and displaying back the results. Connecting to the database If you haven't already created a MySQL database you can follow the How to create a MYSQL database guide. For the purpose of this example we'll use the database name my_database, remember to replace this with your actual database name. To make connecting to and using the database easier we're going to use the Perl DBI module. Lets start at the top of our script with the location of the Perl interpretor and then we tell Perl we want to use the DBI module and then create a DBI object. #!/usr/bin/perl use DBI; my $database_name = "my_database"; my $database_host = "mysql.lcn.com"; my $database_user = "username"; my $database_password = "password"; my $dbh = DBI->connect("dbi:mysql:$database_name:$database_host", $database_user, $database_password) or die "Unable to connect: $DBI::errstr\n"; The DBI module is object-orientated, this means all of the DBI functions and data are accessed through an instance of DBI, in our script this instance is called $dbh, short for database handle. Lines 4 to 7 - Defines local variable to store our connection data, make sure to update them with your actual database details. Line 9 - Creates the DBI object by calling the connect function using the variables we defined, if the connection fails the script will die. Create a table Lets create a simple contacts table and put some details in it. We'll store first name, surname and email address. my $sql = "CREATE TABLE IF NOT EXISTS contacts ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), first_name VARCHAR(64), surname VARCHAR(64), email VARCHAR(255))"; my $sth = $dbh->prepare($sql); $sth->execute() or die "SQL Error: $DBI::errstr\n"; Lines 10 to 15 - We build a string of SQL to create our table. On line 18 we prepare our SQL statement and assign it to a new local varible $sth, short for statement handle. Line 18 - We call the execute function on our $sth object and pass it our SQL string to actually create the table on the database. Insert data into the database Next we'll put some data into our new table. $sth = $dbh->prepare("INSERT INTO contacts(first_name, surname, email) VALUES(?,?,?)"); $sth->execute("Nick", "Jones", "nick.jones\@foo.com"); $sth->execute("Matt", "Smith", "matt.smith\@bar.com"); $sth->execute("Matt", "Brown", "matt.brown\@baz.com"); Line 20 - Here we prepare our new SQL statement, notice at the end of the statement we have a set of question marks. These are used as place-holders for the actual values we will put in when we execute the statement. Lines 21 to 23 - Executes our SQL statement passing in three values for first name, surname and email to replace the place-holders. Query the database Now that we've added some data into our database lets query it for all contacts whose first name is Matt. $sth = $dbh->prepare("SELECT first_name, surname, email FROM contacts WHERE first_name = ?"); $sth->execute("Matt"); Again, we prepare our SQL statement and use a place-holder for the value of our WHERE clause which tells the database to return all contact where the first_name field equals the value we pass in when we execute our query. Display back database results Finally, we want to display this data back in a web page. print "Content-type: text/plain\n\n"; print &rlaquo;<HTML_PAGE; <html> <head> <title>Database Test</title> </head> <body> <h1>Database Test</h1> <table> <tr> <th>First Name</th> <th>Surname</th> <th>Email</th> </tr> HTML_PAGE while( $row = $sth->fetchrow_hashref ) { print "<tr><td>$row->{first_name}</td>"; print "<td>$row->{surname}</td>"; print "<td>$row->{email}</td></tr>"; } print <<HTML_PAGE; </table> </body> </html> HTML_PAGE First print back the HTTP header to let the web browser know what type of content to expect. Then we print out the first part of the HTML page. We use a while loop to iterate over all the results returned by calling the fetchrow_hashref function on our $sth object, for each result we print out the field data and HTML for a table cell. The final script This example script shows a very basic way to get form contents emailed to you, it doesn't however have the refinements of a professional script, e.g. input validation. Below is the finished script. We've added some comments (lines beginning with #) to help make it clearer. #!/usr/bin/perl use DBI; # Define database details my $database_name = "my_database"; my $database_host = "mysql.lcn.com"; my $database_user = "username"; my $database_password = "password"; # Connect to database and create DBI object my $dbh = DBI->connect("dbi:mysql:$database_name:$database_host", $database_user, $database_password) or die "Unable to connect: $DBI::errstr\n"; # Create contacts table my $sql = "CREATE TABLE IF NOT EXISTS contacts ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), first_name VARCHAR(64), surname VARCHAR(64), email VARCHAR(255))"; my $sth = $dbh->prepare($sql); $sth->execute() or die "SQL Error: $DBI::errstr\n"; # Insert data into the table $sth = $dbh->prepare("INSERT INTO contacts(first_name, surname, email) VALUES(?,?,?)"); $sth->execute("Nick", "Jones", "nick.jones\@foo.com"); $sth->execute("Matt", "Smith", "matt.smith\@bar.com"); $sth->execute("Matt", "Brown", "matt.brown\@baz.com"); # Select data from the database $sth = $dbh->prepare("SELECT first_name, surname, email FROM contacts WHERE first_name = ?"); $sth->execute("Matt"); # Print out HTTP header print "Content-type: text/html\n\n"; print <<HTML_PAGE; <html> <head> <title>Database Test</title> </head> <body> <h1>Database Test</h1> <table> <tr> <th>First Name</th> <th>Surname</th> <th>Email</th> </tr> HTML_PAGE # Loop over database query results while( $row = $sth->fetchrow_hashref ) { print "<tr>$row->{first_name}</td>"; print "<td>$row->{surname}</td>"; print "<td>$row->{email}</td></tr>"; } print <<HTML_PAGE; </table> </body> </html> HTML_PAGE Replace the example database name, username and password, save this script as database_test.cgi and upload it to the cgi-bin on your web hosting. Make sure you set the file permissions for the script to 755 as described above. Now you're ready to test your database script. Load up your database test in your browser, http://www.domain.com/cgi-bin/database_test.cgi. If everything works you should see a html page show a table of contacts. If not, try checking out our troubleshooting guide below. Troubleshooting Common Perl Issues

How to create a PHP script

PHP is a general purpose scripting language that is well suited to web development and can be embedded into HTML. If you want to find out more about PHP take a look at is extensive online manual. You can use any plain text editor to create a PHP script (e.g. Windows - notepad, Mac – textedit). Lets take a look a a very simple PHP script: <?php echo “Hello World!”; ?> Line 1 - This tag tells the server that you are writing PHP code Line 2 - You can use the echo function to print out a string of text, this will be displayed back when the script is run. Line 3 - This tag tells the server that you have stopped writing PHP code Note Each line of PHP code is called a statement, and ends with a semi-colon to signify it is a complete statement. Open your text editor and type the code above into it (without the line numbers), and save it to a file called hello_world.php. Next upload your hello_world.php script to your web hosting using FTP. Now load up the script in your web browser e.g. http://www.domain.com/hello_world.php (replace domain.com with your domain name). If all goes well you should see 'Hello world!' at the top of your screen. If not check out the PHP Troubleshooting guide.

Troubleshooting common Perl issues

Here are some common problems and solutions you may find useful once you start scripting with Perl. Plain text Perl source code is displayed If your web browser simply displays the source code of your CGI script this indicates that the web server didn't know how to process it. The most common causes are incorrect file permissions (see below) or that the script is not in the cgi-bin folder. Incorrect permissions The top cause of this error is incorrect permissions on a script or directory. Directories that contain web content (including cgi scripts) must be mode 755. CGI scripts must also be 755. Invalid script interpreter The script interpreter is defined on the first line of the script after the #! and must exist on the server. This is usually perl and needs to be '/usr/bin/perl'. These paths can vary from system to system and it's important to ensure that they're correct for this server. Script uploaded in binary mode Text files are slightly different between Unix and Windows platforms. If you upload in ASCII mode, the ftp server will translate the files to Unix mode for you if necessary. If you upload in binary mode, it won't. CGI scripts are one of the few places on web servers where this difference actually matters. Script did not output headers CGI scripts must output HTTP headers. If you're using Perl, you must do it yourself or use a helper module to do it for you. You must also ensure that the headers are always the first output generated by the script. It's not uncommon for test or debugging code to output a message before the headers and that will cause the server to treat the script as broken. Syntax error in script This error will be generated if scripts have syntax errors and don't actually run successfully. You should obtain the relevant interpreter for your script and try to run it before uploading as this is the easiest way to ensure that there are no syntax errors. Script is trying to use a module not installed on the server Perl scripts will usually die with an error if a module the script requires is not installed. If you suspect a module you require is not installed, please contact our Support Team. What to do if all else fails If you've checked all of these things and can't fix the problem, our Support staff will be able to find out more specific details of the actual problem and give you more detailed information on how to resolve it.

What is Robots.txt

A robots.txt file is a protocol used to prevent web crawlers and robots from accessing all or part of a website. This allows you to control which web crawlers and robots can access your site and how often they do so. It's important to understand that robots.txt is not a way of blocking robots from scanning your site, but is simply a request to not visit it. Also, because this file is publicly available, anyone can see what sections of the site you don't want the robots to access. A Robots.txt file can be created in something like notepad or textedit and you can find a couple of examples below on how best to use this. To allow all robots complete access User-agent: * Disallow: To exclude all robots from the entire server User-agent: * Disallow: / To allow a single robot User-agent: Google Disallow: User-agent: * Disallow: / Once you have created your file, you would need to upload it to your root directory via FTP. Details of how to do this can be found at the link below: How to upload files to your website with FTP Note: The default robots.txt file that is added to any domain hosted with LCN.com is as follows: User-agent: * Disallow: Crawl-delay: 10 This means that it will allow all bots to crawl the site, but issues a crawl delay of 10 seconds per page. This helps to prevent server stress when bots crawl our servers. As this is set server side, the file itself is not displayed in your hosted files, but uploading a custom robots.txt will overwrite this.

How to create a Perl script

Perl is a general-purpose programming language used for a wide range of tasks including web development. If you want to find out more about Perl take a look this introduction to Perl and the online documentation. You can use any plain text editor to create a Perl script (e.g. Windows - notepad, Mac - textedit). Normally you would also install the Perl interpreter on your computer as well so that you can test the scripts you write. Lets take a look a very simple Perl script: #!/usr/bin/perl print "Content-type: text/plain\n\n"; print "Hello world!"; Line 1 - This tells the web server where and what to pass the script to for processing. Line 3 - Because we will be requesting this script in a web browser we need to tell it what type of content we are going to send it, in this case plain text. Normally you would want to return HTML content and would use text/html instead. Line 4 - Here we print back our line of content. Note Each line of Perl code is called a statement, and ends with a semi-colon to signify it is a complete statement. Open your text editor and type the code above into it (without the line numbers), and save it to a file called hello_world.cgi. Note When creating the script, be sure to ASCII mode not binary as the script will not work otherwise. Next upload your hello_world.cgi script to the web/cgi-bin on your web hosting using FTP. Using your FTP program set the permissions for your cgi script to 755. Follow our How to change file permissions via FTP guide for instructions on how to do this. Now load up the script in your web browser e.g. http://www.domain.com/cgi-bin/hello_world.cgi (replace domain.com with your domain name) If all goes well you should see 'Hello world!' at the top of your screen. If not check out the Perl troubleshooting guide.

How to add Google Analytics to your WordPress website

This guide will explain how to set up Google Analytics on your WordPress website for customers using LCN.com web hosting and WordPress hosting. Before you start, you’ll need to set up a Google Analytics account. You can learn about this and how to get started with Google Analytics here. Let’s get started… Installing the plugin Login to your WordPress dashboard. You can do this by navigating to http://www.yourdomain.com/wp-login.php Hover over Plugins on the left had side and click Add New Use the search bar in the top right had side to find Google Analytics by MonsterInsights Click Install Now Once installed you’ll need to turn the plugin on. Do this by clicking Activate Plugin Your browser does not support the video tag. Connecting to Google Analytics Once active, you’ll need to link the plugin to your Google Analytics account. You can do this by clicking Settings from the screen displayed immediately after the plugin is activated. Alternatively, you can go to Plugins, Installed Plugins and click Settings under the Google Analytics by MonsterInsights section. From the General tab click Authenticate with your Google account. A box will appear for you to login to your Google account Click Allow to give MonsterInsights permission to view your Google Analytics data Next an authentication code will be displayed. Copy this and paste it in to the Paste your Google code here field Click Save authentication code Select your Analytics profile from the drop down Click save changes Your browser does not support the video tag. Now this is set up, you’ll be able to view your analytics by hovering over Insights on the left hand side of the WordPress dashboard and clicking Dashboard.

How to add a site to your hosting package

This guide will explain how to add a site to your LCN.com web hosting, WordPress hosting or email hosting. Let’s get started… Using a domain from your account Login to your LCN.com account and click hosting Below the hosting package you want to use, click Add Site From the box which appears, click From your account Select the domain you want to use from the drop down and click CREATE SITE Your hosting will now be setup and ready to use! Your browser does not support the video tag. Using a domain at another provider Login to your LCN.com account and click hosting Below the hosting package you want to use, click Add Site From the box which appears, click At another provider Within the Point your domain to LCN section, type the domain you wish to use with your hosting package and click CREATE SITE. Your browser does not support the video tag. Now your site has been set up on your hosting package, you’ll then need to contact your domain registrar and ask them to update your domain’s nameservers to the below: ns0.lcn.com ns1.lcn.com ns2.lcn.com Nameserver updates can take up to 72 hours to complete, however this depends on the domain registry and can happen much quicker. Alternatively, you can Transfer your domain to LCN. You can learn about how to do this here.

How to remove ‘designed by WooThemes’ from your WordPress website

This guide will show you how to remove the Designed by WooThemes footer located on the WooThemes premium themes. This guide is applicable to customers using LCN.com WordPress hosting. Before you start you’ll need to know the username and password for the WordPress administration area of your site. If you are unsure of these details they can be reset from your LCN.com account. Let’s get started… Login to your WordPress administration panel, which can normally be accessed by browsing to http://www.yourdomain.com/wp-login.php Locate your Theme settings on the left-hand panel. Note: This will be the name of the theme that’s currently active. Across the top menu select Footer Customisation . Tick the two boxes located next to Enable Custom Footer (Left) and Enable Custom Footer (Right) . If you’d like to enter your own custom text in to the footer, put this in the Custom Text (Left) and Custom Text (Right) fields. Alternatively, you can leave these blank. Scroll to the bottom of the screen and click Save Changes. Go back to your website and refresh the page. Note: you can refresh the page by holding CTRL and pressing F5 on your keyboard Your browser does not support the video tag. That’s it! You’ve removed designed by WooThemes from your website’s footer.

Need a hand? Search over a hundred step-by-step support guides