Skip navigation.

Technolosity

Random rant about technical things.

Posts tagged with "php"

Chat updated, again...

, , , ...

I'm too lazy to take a screenshot. Look here if you want to see.

New features that I remember:
  • A bit more enhanced look
  • Interface uses jQuery (I know I said I'd use Prototype, but jQuery was easier to implement)
  • Auto-create URLs
  • Text format adds: CSS3 text-shadow
  • YouTube video popup window thingamajig whatchamacallit
  • Sent message history (up and down arrows)
  • Remote server connection (some clichés with images though, too lazy)

Still lacking:
  • Database
  • File-sharing
  • More

Interesting thing here is remote server connection. Just putting the following in a page header you'll be able to connect and see my chat. I can't be less arsed to test it though.
<link rel=stylesheet href="http://joonasr.com/webchat/default.css" type="text/css" title="style" id="stylesheet" />
<script type="text/javascript" src="http://joonasr.com/webchat/javascript/chat-remote.js"></script>
<script type="text/javascript">
var localServer = false;
var debug = 1; // very optional
</script>

The Javascript files are not minified, so I guess everyone are free to study them. There's also tiny feedback form in the chat if someone wants to send me some crappy comments. That's it. One of my shortest posts.

http://joonasr.com/webchat/

A quick glimpse to PHP

, ,

Alright, some time since the last post. This time I'm going to go through a bit about PHP. Once again I write this text by improvising and this is really just a quick glimpse.

PHP (Hypertext Preprocessor) is a programming language designed to create dynamic websites. Most of the popular and even less popular sites use PHP (or in worse case ASP). Good thing in PHP is that it's free, uses extensions and lots and lots of other good stuff. You can find more info from the net.

You should have some basic knowledge about HTML and programming to fully understand everything, or just read this and start to finally understand something :wink:

Before you can start using PHP you have to do few steps:

  • Download and install an HTTP server software (we are using Apache)
  • Download and install PHP (I use PHP 5) or alternate XAMPP distribution for quick install and simpletons
  • If you downloaded the normal PHP, spend some time to configure it (not easy for new people)

Configuring Apache:

There's some things to change in the default configuration. Often there can be some differences and unlogical problems in installations but you can always ask for help (I'm here).

  • Open httpd.conf file from the conf folder in the Apache installation directory.
  • Locate and change DocumentRoot to a directory you want to use as the website root.
  • In DirectoryIndex, add index.php.
  • To include PHP you have to add next lines somewhere in the file and change them to match your directories:
    LoadModule php5_module "C:/Program files/PHP/php5apache2.dll"
    AddType application/x-httpd-php .php
    
    PHPIniDir "C:/Program files/PHP"
    

Testing the installation:

Create index.php file in the website root directory and copy next lines into it:
<html>
<head><title>Test</title></head>
<body>
<?php
phpinfo();
?>
</body>
</html>
Then open your browser (God, I hope it's Opera) and open http://localhost/ to test whether the installation was successful. The page should show all info about your PHP installation and modules etc.


Some basic stuff about PHP:

PHP code is written in plain text and is always executed before the data is sent to the client. As you might noticed, the PHP code which you want to execute is always included in between special tags (<?php and ?>). PHP can also include external files. I do this for example to separate database functions, file parsing, texts and page drawing in different files, which are included only when needed.

PHP resembles some other programming languages, like C++ or Java. All variables are prefixed with dollar sign ($) like you'll see in the code below. You can use loops, functions and other familiar stuff. It helps quite a lot if you've done programming and/or web design earlier.

Example page:

Below you see three (3) different codes for php files. File index.php contains only two lines of code to include other files. Files head.php and body.php contain HTML and PHP mixed. Take some time to understand them because I couldn't be less arsed to explain in detail. Finally save all of the files in the same website directory.

index.php:
<?php
include 'head.php';
include 'body.php';
?>

head.php:
<html>
<head><title>
<?php
$title = "This is title text";
echo $title;
?>
</title></head>

body.php:
<body>
<h1>Header</h1>
<table>
<?php
// make ten table rows
for ($i = 1; $i <= 10; $i++)
{
  echo "<tr><td>Row $i<td>Cell for row $i!";
}
?>
</table>
</body>
</html>

End words:
I hope you got some idea about PHP. I'm not going any deeper into the programming, but you can find a lot of tutorials in the net and perhaps read a book or two. Keep practicing and you'll gonna get friggin' good in this.

-J-
Download Opera, the fastest and most secure browser
January 2010
M T W T F S S
December 2009February 2010
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31