Friday, January 22, 2010

Tutorial 2 Php Introduction 1002

Tutorial 2 Php Introduction  1002

Html code can  be embedded into Php.

The following will display as bold
<?Php
echo ”<b>hello</b>”;
?>


Let’s try the  below example with some cool CSS (Cascading style sheets) formatting
.
We will save the below document as a php document - nice.php and a separate file named nicestyle.css in the webroot folder,.

The following is the complete document - nice.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Control Panel login</title>
<link rel="stylesheet" type="text/css" href="nicestyle.css" />
</head>

<body>


<center>
<div id="bkground1"> <!-- finishes on line 19-->

<p><a href="myfile.php">My Online Auctions</a></p>
<p> <?Php echo "<b>Welcome to my site<b>"; ?> </p>

</div> <!--end bkground1 from line 16-->

</center>

</body>
</html>

The following is the CSS document – nicestyle.css

#bkground1 {
  width: 100px;
  background: #FFFFCC;
  padding: 4px;
  border: 1px solid #ccc;
  }

P{
font-weight: bold;
}

/* Navigation Links */
a {color:maroon;} a:hover {color:red;} a:visited {color:green;}

Save both the above files in the webroot and run the php file  - nice.php to see some nice formatting.

Thursday, January 21, 2010

An Introduction to Php 1001

Your computer should have at least php5 and apache 2.x webserver installed and running before you can try out the examples or write some php code.  Mysql database server will be need to be installed for trying out php connections to Mysql. See my 1st article for how to ideas.

All php scripts are saved with a .php extension e.g index.php.

For writing php scripts any text editor will do, however text editors with line numbering and syntax highlighting are the best. There are good open source and paid text editing software you can use e.g leaf text editor and notepad +. A good commercial text editing software is Rapid HTML. You can google for these to find out more.

All php scripts should be saved in your webroot folder e.g  c:/myfolder/www/myfile.php

Note: I test run all examples before posting them, if you find typo or execution errors, etc, your feedback would be welcome.

To execute above script, you would type the following in your web browser:
http://localhost/myfile.php  Note: all script file names are case sensitive.

Some important points to remember:

All php scripts start with <?php
And end with ?>
Semi colons are used to terminate end of line for some code.
Comments inside php use /*   */  for long comments ,   #  for  bold comments ,  // for single line comments.

Example:

<?Php

//This is one line comment

/* this is multi line comment
and more multi line comment */
##################
#My boxed comment#
##################
echo “hello”;
?>


Save above example as myfile.php or similar and run it in your web browser. It should display “Hello” on your screen.

Monday, January 18, 2010

How to run your own web server continued ARTICLE 2

Ok, now you have finished downloading the software mentioned on Article 1.



Find out what your pc's internal ip address my clicking on my network places>view net work connections>LAN and looking at the 'details' box on the left. Write this down e.g 192.168.1.100



Note, please ensure that any anti-virus programs are disabled while you are installing these programs, or the installations may not finish correctly.



Unzip the contents of php.zip to a folder named c:/php



Install the Mysql database server software by running the installer.



Install the apache web server software, when the installer asks for a IP address or server address, give it an address similar to this: http://192.168.0.194 (whatever the ip address you wrote down) and use your email address for admin contact. Restart the system . Check to see if the Apache server is running by typing in the following into your web broswer: http://localhost/ If you see "It works" in your browser window, that means that the apache web server is running. There will also be a small icon in the lower right hand corner of the screen stating whether the apache service is running. If you have problems, be sure to check the apache error log to trouble shoot.

The above gives you total control over the configuration, and you know what exactly you are doing. If you break some code, you can easily fix it. The only downside is that Apache, Php and Mysql have to be manually installed, which takes more time.

If you want a quick web server with above features, you can download WAMP or XAMP. Try googling for each of them. In my opinion WAMP is easier to setup then XAMP and emulates a real production environment.

First Steps for running your own web server ARTICLE 1 Web Server How to

Hello adventurers.

It is easy to run your own web server and host your own web site. This gives you total control
over your machine and what you can do with it. And you can always use your machine to test out dynamic sites before you decide to host your site at a commerical web hosting company.

Let's get started.

Most of us are familar with the windows XP operating system and the same goes for me. I must say Linux is also good in this regards, but the learning curve is steep. But don't fret, nothing is impossible. I'll cover "running Ubuntu Linux Web Server" later.

The folllowing are the software you will need to download for Windows XP 32 bit operating system:

1) Php.zip from http://www.php.net/ (Note: Do not download Php self installing file)
2) Apache Web server installer from http://www.apache.org/
3) Mysql database installer from http://www.mysql.com/


Once you are done, we'll look at installing the above software & setting up your windows XP pc to run as a web server.

Newer Posts Home