Archive for the ‘Code’ Category

Random Rotation of Images Using PHP and Not Javascript

Wednesday, November 30th, 2011

I am not really against javascript but I do prefer to not use it when I can do the same with other coding methods like html, css and php.  There are a lot of scripts and examples to enable the random loading of an image each time a page loads, however most of them use javascript.  While they work, they relied not only on javascript but also that the viewer of the page was running javascript. Many people turn javascript off for fear of being hacked, hijacked or something else, which for 99.9% of the time will not happen, but paranoia is there with quite a few ;).

I am still relatively new to php, but I am learning the more I play with it.  While learning I came across the rand function which gave me some ideas when combining it with an echo.  Could I use php to look for images in a folder, randomly select one of them and then display it.  It sure could and it is very easy to do, you can do it as an ‘img src’ or even css background. (more…)

Share

SobiPro Templating How To…

Monday, June 20th, 2011

I am not against anyone making money from their great work and the developers of SobiPro are no exception.  However I do believe that if you are providing a solution that is supposedly for free that it comes with some basic documentation on how to use the product.  However to access this basic documentation a ‘club’ membership is required which I feel is wrong, but that is only my view, yours may be different.  During my use of SobiPro I have been compiling a list of how to references on using the SobiPro Template framework and the template language (XSL) used.

UPDATE: Yesterday I decided to trial a Club Membership and bought a 1 month membership to see what the documentation was like, and to be honest I was pleasantly surprised and really do believe that a 1 or 3 month membership is worth it as the documentation is very good.  It fills the gap between what I already knew and what I have been trying to work out.  So if you can afford a single months membership I suggest you get it, or better yet a 3 month membership.  The only thing that they need to consider adding is an upgrade path from a Bronze to Silver to Gold which I think will assure ongoing payments by users as they notice the true value of the documentation. 

(more…)

Share

Adobe kills off Homesite :(

Thursday, June 25th, 2009
Adobe kills off Homesite :(

Adobe kills off Homesite 🙁

It is sad news, my beloved XHTML editor is now dead no thanks to Adobe with them announcing the death of Homesite as of the 26th May 2009.  They acquired Homesite from Macromedia (2003) and simply let it die, without even a hint of updating it or letting anyone know it would be abandoned since they took it over.

While other editors exist and will have to take the place of Homesite, at this stage there os no product (yet) that is as good as Homesite.   Adobe have simply said use Dreamweaver, but if I wanted to use Dreamweaver I would already be doing that.  The benefit Homesite has over Dreamweaver is that Homesite is light weight and very customisable – which is very different to Dreamweaver which is well over priced (as are all Adobe products) and is over bloated with extensions and tools and add-ons that for the most part are not needed.

(more…)

Share

Keeping your CSS code clean

Friday, July 11th, 2008

I love code, that is pretty simple to see and I like it as it can give me full control over every element of the website design.  I also like clean code, without it your website may look nice but if you need to come back to the code in a year or two my bet is that it will take you more time to work out what is what in the code instead of simply getting the job done.

Clean code in whatever language you are using and for whatever purpose you need it for is essential.  This first post of a series I will do is for CSS (style sheets).

You can go even further by breaking up the CSS into separate style sheets such as Header, Footer, Content and so on, this is totally up to you, the following is my starting point I use for CSS, I hope you find it useful.

/*
Site Name:
Site URI: http://somedomain.com.au/
Description: Stylesheet for somedomain
Version: 1.0
Author: That Net Site
Author URI: http://thatnetsite/
Version Comments
v1.0
This Style sheet is ......
*/

/*-----------------------------------------------------
Reset all basic browser properties
-----------------------------------------------------*/

* {
     margin: 0;
     padding: 0;
     border: 0;
     font-family: sans-serif;
     font-size: 1em;
     font-weight: normal;
     font-style: normal;
     text-decoration: none;
}
/*-----------------------------------------------------
Basic Page Properties
-----------------------------------------------------*/
html {
     height: 100%;
     margin-bottom: 1px;
}
body {
     margin: 0;
     padding: 0;
}
p {
     margin-top: 10px;
     margin-bottom: 15px;
}
fieldset {
     border: 0;
     padding: 5px 0;
}
/*-----------------------------------------------------
Font Size Properties
-----------------------------------------------------*/
h1 {
     font-size: 200%;
}
h2 {
     font-size: 170%;
}
h3 {
     font-size: 150%;
}
h4 {
     font-size: 120%;
}
/*-----------------------------------------------------
Padding and Margins
-----------------------------------------------------*/
div {
     margin: 0;
}
h1 {
}
h2 {
}
h3 {
}
h4 {
}
h5 {
}
/*-----------------------------------------------------
Fonts and Font Weights
-----------------------------------------------------*/
body {
     font-family: "Lucida Grande", Tahoma, Helvetica, sans-serif;
}
h1 {
}
h2 {
}
h3 {
}
h4 {
}
h5 {
}
/*-----------------------------------------------------
Colours
-----------------------------------------------------*/
body {
     color: #5B5648;
}
a {
     color: #960000;
}
a:hover {
     color: #000000;
}
/*-----------------------------------------------------
Backgrounds
-----------------------------------------------------*/
/*-----------------------------------------------------
Text Decorations
-----------------------------------------------------*/
a:link,
a:visited {
     text-decoration: none;
}
a:hover {
     text-decoration: none;
}
/*-----------------------------------------------------
Borders
-----------------------------------------------------*/
a img {
     border: 0;
}
div {
     border: 0;
}
/*-----------------------------------------------------
Width and Heights
-----------------------------------------------------*/
/*-----------------------------------------------------
Floats and Alignments
-----------------------------------------------------*/
.clear {
     clear: both;
}
.right {
     float: right;
}
.left {
     float: left;
}
.center {
     text-align: center;
}
/*-----------------------------------------------------
Lists
-----------------------------------------------------*/
/*-----------------------------------------------------
Displays and Positions
-----------------------------------------------------*/

Please feel free to share your thoughts and comments on how the above can be improved or even if you have some alternative methods that work well for you.

Share

.htaccess file Code Snippets

Monday, July 7th, 2008

I often have a need to add specifics to the htaccess file to make the web site meet a clients needs (or my own).  Over the years I have compiled a number of htaccess code snippets that I have used that may be useful to you if needed.

Disable Directory Browsing

Options All -Indexes

Enable Directory Browsing

Options +Indexes

If you want to block specific file types from showing you can use

IndexIgnore *.wma *.mp3 *.avi

Prefer to use Custom Error Messages

ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html

If you need SSI working with HTML instead of just SHTML
These do not all have to be used they are provided just as examples

## SSI for html files
AddType text/html .html
AddHandler server-parsed .html
## SSI for shtml files
AddType text/html .shtml
AddHandler server-parsed .shtml
## SSI for htm files
AddType text/html .htm
AddHandler server-parsed .htm

Change the Default Home Page – note the order you place them in is followed

DirectoryIndex home.html index.html index.php

Block Users from accessing the site

<limit GET POST PUT>
order deny,allow
# By the IP Address
deny from XXX.XX.XXX.XX
# By Domain
deny from .domain.com
allow from all
</limit>

Allow only LAN users

order deny,allow
deny from all
allow from 192.168.0.0/24

Redirect Visitors to New Page/Directory

Redirect oldpage.html http://www.domain.com/newpage.html
Redirect /olddir http://www.domain.com/newdir/

Block site from specific referrers

RewriteEngine on
RewriteCond %{HTTP_REFERER} block-site\.com [NC]
RewriteCond %{HTTP_REFERER} block-site-2\.com [NC]
RewriteRule .* - [F]

Block Hot Linking/Bandwidth hogging

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]

Want to show a “Stealing is Bad” message too?

Add this below the Hot Link Blocking code:
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/nosteal.gif [R,L]

Another example of not letting someone hotlink or use your images on their site

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*php$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !domain1allowed\.com [NC]
RewriteCond %{HTTP_REFERER} !domain2allowed\.org [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) /pathto/nohotlink.jpe

Stop .htaccess (or any other file) from being viewed

<files file-name>
order allow,deny
deny from all
</files>

To use or not to use www in your URL

# Rule for duplicate content removal : domain.com vs www.domain.com
RewriteCond %{HTTP_HOST} ^www.domain\.com [NC]
RewriteRule (.*) http://domain.com/$1 [R=301,L,NC]

or in reverse

# Rule for duplicate content removal : domain.com vs www.domain.com
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L,NC]

Prefer to use just domain.com/ and not domain.com/index.php?

# Rule for not using index.php or index.html etc as home page
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^./index.php
RewriteRule ^(.)index.php$ http://domain.com/$1 [R=301,L]

Avoid the 500 Error

# Avoid 500 error by passing charset
AddDefaultCharset utf-8

Grant CGI Access in a directory

Options +ExecCGI
AddHandler cgi-script cgi pl
# To enable all scripts in a directory use the following
# SetHandler cgi-script

If you want to change script extensions

AddType application/x-httpd-php .gjw
gjw will now be treated as if they were PHP files!
The same can apply for cgi files
AddType application/x-httpd-cgi .gjw
Share