Posts Tagged ‘ php ’
Quick Post: Django vs Grails
Coming from the Django world, I can already see big similarities. They both provide database abstraction for example, they allow the developer to essentially create a database and minimize the amount of SQL code needed. From what I can tell, the two are very similar, and this does excite me. Also makes me feel at home with Grails.
My temptation however is to compare these frameworks back to PHP, which is a largely unfair comparison. Therefore, I will leave that discussion for another day.
After downloading Grails, my first impression was installation should be the easiest part of imparting on new framework, with Django, it requires issuing setup and Django takes it away configuring and installing the necessary items. However, Grails requires a bit more manipulation to get it going. I found a good resource and should be on my way. More details as I get further into Grails.
Category: Coding | 1 Comment »Simple Login Script
After creating a database named users, a table named users and two fields username and password, you can begin making this login script.
The basic form
Create a page named index.php, and inside that page add the following code.
<form action="login.php" method="post"> <label for="name">Username</label> <input name="username" type="text" /> <label for="password">Passwod</label> <input name="password" type="password" /> <input type="submit" value="submit" /> </form>

photo credit: Laughing Squid
The form action tells the form where the information should be going once the submit button is clicked. Next, the method tells it how the information should be transmitted. In PHP there are two methods for tranmitting information,
- Post
- Get
Remember visiting Youtube and seeing youtube.com/watch?v=mEj-88iLjmM&feature=popular? This was submitted using a get, because you can see everything that is going on.
In cases where security is important this is not system, we do not want people to be able to hi-jack our login credentials.
We have basic input boxes. The “name” value is what is transmitted to the subsequent PHP pages.
Connecting to a database
Make a new document and name it: “connection.php”. This document will store the database connection information.
We have the variables stored with our database information, now we need to do something with them. Take the server location (most cases its localhost), database user, and database password and connecting. or die(mysql_error()) says, if connection does not complete, give us an error message.
Next, we select the database, and if something went wrong there, we display another error message.
We want to include this on every page that needs database access.
Category: PHP Script | No Comments »Why use an array?
Recently, I asked myself the same question. You might be wondering, what is an array. According to Wiki:
In computer science an array [1] is a data structure consisting of a group of elements that are accessed by indexing.
What does that really mean? Well, I’ll explain by using an example I got off one of the programming forums I frequent, SamponVideos.com. I will actually quote some of Johnathan Sampson’s message because it captures the idea. In his example, if you were creating a an image uploader, and you did not want to allow executable files, you would do something like this:
$fileTypes = array("jpeg","gif","jpg","bmp");
Without the use of an array, it would turn into this:
if ($fileExtension == “jpeg”) {
# Approved
} else
if ($fileExtension == “gif”) {
# Approved
} else
if (fileExtension == “jpg”) {
# Approved
}
Or this:
if ($fileExtension == “jpeg” || $fileExtension == “gif” || $fileExtension == “jpg”) {
# Approved
}
The array makes the code, much easier to handle, and looks cleaner. Have you used arrays in your projects?
Category: PHP Script | No Comments »Easy Site-Wide Link Updating
As I have created more websites, I have come to love includes. They are useful when you need to use one file repeatadly. For instance, you may want the same navigation scheme across a site. It would be troublesome, or bothersome to insert you navigation code on each page.
What happens when you add or subtract a page? You would have to change every single page. 9 times out of 10, you always miss at least one page. There are other situations where using an include would come in handy, but those are more programming oriented.
You will need:
This code requires the use of PHP, on the main page you need to write, and so this page must end in .php, for example, index.php. The ending php tells your server it needs to do more work with that page before displaying it.
Whenever you are using a PHP tag, you must enclose it in
<?php **Place Code Here** ?>
On the every page you want this content to appear insert the code:
<?php include(“file directory here/link.html”); ?>
This tells the server to include “file.html” in that place on the page. Now, you create “link.html”.
<ul>
<li><a href=”index.php” title=”Home”>Home</a></li>
<li><a href=”contact.php” title=”Contact Us”>Contact Us</a></li>
<li><a href=”location.php” title=”Location”>Location</a></li>
</ul>
Now upload these pages to your webserver and only update “link.html” as needed.
Category: PHP Script | No Comments »Automatic Copyright Updating
Many people who design websites put copyright dates on every page of their website. By inserting this snippet of code your site will bringing in the new year with an up to date copyright date.
Today this snippet will output Copyright 2008 Resnodesigns and next year, it will greet the New Year with Copyright 2009 Resnodesigns.
Copyright <? echo date("Y"); ?> Resnodesigns
Category:
PHP Script |
No Comments »
What are PHP and ASP.net?
Recently, I have been having alot of questions about what PHP and ASP.net are and how do they help on a site.
What are PHP and ASP.net? Why do I care?
1. What are PHP and ASP.net?
1. Well, when you want to use a shopping cart, forum, or anything outside of a static website it requires the server to do something. For example, this blog is written in PHP, because I can add blogs and I do not have to edit the html code.
2. What’s the difference between PHP and ASP.net?
1. PHP generally is used by people like us, who design and build websites.
2. ASP.net is generally used by big corporations. They like ASP.net because it is backed and supported by Windows.
3. Now, why do you care?
1. Does your business want to sell products online?
2. Do you want a forum or other social networking system? (Facebook, Myspace, YouTube, etc.)
3. These types of sites require the server to handle parts of your site because html can not do it alone.





