<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CrankBerry Blog</title>
	<atom:link href="http://www.crankberryblog.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crankberryblog.com</link>
	<description>Sharing ideas on web design, development and the internet economy</description>
	<lastBuildDate>Thu, 24 Nov 2011 19:37:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting up virtual host on XAMPP (OSX)</title>
		<link>http://www.crankberryblog.com/2011/setting-up-virtual-host-on-xampp-osx</link>
		<comments>http://www.crankberryblog.com/2011/setting-up-virtual-host-on-xampp-osx#comments</comments>
		<pubDate>Thu, 24 Nov 2011 19:37:08 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=504</guid>
		<description><![CDATA[If you have decided to go with XAMPP on your OSX machine, then you have made the right choice as it works excellent on the Mac and has almost no limitations. Because of the file structure was not the typical WAMP or server setup I was used to it was a bit tricky at first. In case anyone else had trouble here's a quick tutorial on how to get it rolling.]]></description>
			<content:encoded><![CDATA[<p>If you have decided to go with XAMPP on your OSX machine, then you have made the right choice as it works excellent on the Mac and has almost no limitations. Because of the file structure was not the typical WAMP or server setup I was used to it was a bit tricky at first. In case anyone else had trouble here&#039;s a quick tutorial on how to get it rolling.</p>
<p>I&#039;ve got XAMPP installed in /Applications/XAMPP so for the rest of this blog I&#039;ll assume you did the same. Open up your Terminal which you can find under /Applications/Utilities/Terminal.</p>
<h2>Enable Virtual Hosting (vhost)</h2>
<p>To enable virtual host, navigate to the XAMPP folder by typing in:</p>
<pre>cd /Applications/XAMPP/</pre>
<p>This is the root for your XAMPP application, now navigate into the etc folder:</p>
<pre>cd /etc/</pre>
<p>Here you&#039;ll find a bunch of files which is really the configuration for your localhost server. What you need to edit is the httpd.conf file. You do so with the vi editor. Next I&#039;ll show you the series of steps to do so and do a quick comment explaining them using the # sign (which means don&#039;t type in the # stuff). Some of you may have read/write problems so just tag sudo infront like I did and type in your computer password.</p>
<pre># Open the httpd.conf file with the VI editor
sudo vi httpd.conf

# Find where the vhost module is and include it
/vhost

# You'll end up with a line like this:
# LoadModule vhost_alias_module modules/mod_vhost_alias.so
# (which is commented out)
# Hit i to go into edit mode
i

# Remove the hash at the beginning of that line
# Once you're done hit [ESC]
[ESC]

# Now we look for the second vhost line
/vhost

# If the above command lingers in the line you just edited
# keep hitting it until you find this
# Virtual hosts
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
# Hit i to go into edit mode
i

# Remove the hash at the beginning of the line with Include
# hit [ESC] when done
[ESC]
# Now save and exit the file
:wq</pre>
<h2>Creating Virtual Hosts</h2>
<p>Ok now you&#039;ll be back in the etc directory, now you have to add some virtual host for your machine. Navigate into the extra folder:</p>
<pre>cd /extra/</pre>
<p>Now we&#039;re going to edit the httpd-vhosts.conf file which tells the local which domains are virtual hosts. Once again we do so with the vi editor:</p>
<pre># Edit the httpd-vhosts.conf
sudo vi httpd-vhosts.conf</pre>
<p>At the top of the file you&#039;ll see a huge chunk of comments which is for you reference, navigate to the bottom by hitting Shift + G. By default you&#039;ll need this chunk of code:</p>
<div class="dean_ch" style="white-space: wrap;"># LocalHost &#8211; Default &#8211; Must KEEP<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;VirtualHost *:80&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerName localhost<br />
&nbsp; &nbsp; &nbsp; &nbsp; DocumentRoot &quot;/Applications/XAMPP/htdocs&quot;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;Directory &quot;/Applications/XAMPP/htdocs&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Options Indexes FollowSymLinks Includes execCGI<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AllowOverride None<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Order Allow,Deny<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Allow From All<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</div>
<p>If you have it then you&#039;re fine, if you don&#039;t hit [i] and paste it at the bottom. This block basically tells the localhost that the address http://localhost leads to /Applications/XAMPP/htdocs, which is that orange/white screen default for XAMPP. You&#039;ll need to change the address if you&#039;ve installed it in a different directory.</p>
<p>Now after that chunk of code you can start creating virtual hosts. Instead of writing line by here&#039;s a chunk of code you can copy modify and paste in. This chunk is to define http://myhost.crankberry/ as my local Crankberry virtual host.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;VirtualHost *:80&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerName myhost.crankberry<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerAlias www.myhost.crankberry<br />
&nbsp; &nbsp; &nbsp; &nbsp; ServerAdmin webmaster@localhost</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; DocumentRoot &quot;/Applications/XAMPP/htdocs/crankberry&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; DirectoryIndex index.php</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;Directory &quot;/Applications/XAMPP/htdocs/crankberry&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Options Indexes FollowSymLinks<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AllowOverride All<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Order allow,deny<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Allow from all<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</div>
<p>There&#039;s four lines in there you&#039;ll need to change. The second and third which indicates your virtual host names. You can create anything but don&#039;t create something like google.com because then you won&#039;t be able to actually access google. Then you have to change the Document Root and Directory URL to point to where it physically sits. Once you&#039;re done:</p>
<pre># Hit [ESC]
[ESC]

# Save and exit
:wq</pre>
<h2>Telling Your Machine You Have Virtual Hosts</h2>
<p>Now your virtual host is almost done, you just need to tell your machine that you have these virtual hosts setup and they need to direct to those path. You will need to edit your computer&#039;s hosts file, do so by using the VI editor again:</p>
<pre>sudo vi /etc/hosts
# Notice the / in front of etc, that means I'm looking into
# the root of the computer, not the etc folder in XAMPP</pre>
<p>Now we&#039;re going to define the virtual host on the localhost port which is 127.0.0.1:</p>
<pre># Navigate to the bottom
Shift + G

# Hit i to insert
i

# Type in the IP and your vhost
127.0.0.1 myhost.crankberry

# Hit [ESC]
[ESC]

# Save and exit
:wq</pre>
<p>After that you made need to restart your XAMPP, but for me if I navigate to http://myhost.crankberry on my browser it works like a charm. Give it a go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/setting-up-virtual-host-on-xampp-osx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>crankSlider the Jquery DIV and Image Slider Script</title>
		<link>http://www.crankberryblog.com/2011/crankslider-the-jquery-div-and-image-slider-script</link>
		<comments>http://www.crankberryblog.com/2011/crankslider-the-jquery-div-and-image-slider-script#comments</comments>
		<pubDate>Mon, 30 May 2011 22:10:36 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=501</guid>
		<description><![CDATA[I was looking for a simple Jquery DIV slider the other day and took a while before I found anything but they were too heavy and clunky. I just decided the best way was to write my own. Sometimes you may want a slider for not just images but for Divs as well, that way you can include other elements inside the div or create more animations inside.

Without further ado head over here to grab the <a href="http://www.crankberryblog.com/tool/crank-slider.php">crankSlider Jquery Div and Image Slider</a>.]]></description>
			<content:encoded><![CDATA[<p>I was looking for a simple Jquery DIV slider the other day and took a while before I found anything but they were too heavy and clunky. I just decided the best way was to write my own. Sometimes you may want a slider for not just images but for Divs as well, that way you can include other elements inside the div or create more animations inside.</p>
<p>Without further ado head over here to grab the <a href="http://www.crankberryblog.com/tool/crank-slider.php">crankSlider Jquery Div and Image Slider</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/crankslider-the-jquery-div-and-image-slider-script/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Installing Sphinx on CentOS/Linux through SSH</title>
		<link>http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh</link>
		<comments>http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh#comments</comments>
		<pubDate>Fri, 22 Apr 2011 17:29:00 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=479</guid>
		<description><![CDATA[Here are the steps into setting up Sphinx for your Plesk sever through SSH. I'm running on CentOS 5.2 but I'm pretty sure these instructions work on most Linux environment. If you're looking to <a href="http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows">install Sphinx on WAMP</a> (Windows machine) there's another article for that.
]]></description>
			<content:encoded><![CDATA[<p>Here are the steps into setting up Sphinx for your Plesk sever through SSH. I&#039;m running on CentOS 5.2 but I&#039;m pretty sure these instructions work on most Linux environment. If you&#039;re looking to <a href="http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows">install Sphinx on WAMP</a> (Windows machine) there&#039;s another article for that.</p>
<p>Here is my environment:</p>
<ul>
<li>CentOS 5.2</li>
<li>MySQL 5.1.36</li>
<li>PHP 5.3.6</li>
<li>Sphinx 1.10</li>
</ul>
<p>To do all this, login to your server via SSH with your favourite Telnet/SSH client. I prefer to use <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank">PuTTY</a>. Oh, you must login as root so have root access!</p>
<h3>How Does Sphinx Works</h3>
<p>In brief this is how Sphinx works. Sphinx creates a separate index of the table you want to search. Your PHP scripts calls the Sphinx API to search connecting to a specific port where Sphinx is listening to. Sphinx then searches its own index and does the search returning the result. Yes, the index has to be updated every time your update your original table. On my live environment I have a <a href="http://www.crankberryblog.com/2010/php-cron-job-without-using-cron-tab-cron-alternative-with-mysql-or-just-txt">cron job setup</a> to reindex with Sphinx every so often.</p>
<h3>Step 1 Extract and Prepare Conf File</h3>
<p>First of all you have to download the Sphinx package and extract it on your server. Here are the command lines for that. Note that the package I&#039;m downloading is the newest (1.10 Beta at this moment). If you&#039;re downloading the older stable version or newer ones since this article is written then you have to change the URL. BTW don&#039;t type in the ($).</p>
<pre>$ wget http://sphinxsearch.com/files/sphinx-1.10-beta.tar.gz
$ tar xzvf sphinx-0.9.8.tar.gz
$ cd sphinx</pre>
<p>To Summarize, the first line downloaded the Sphinx package to your server. Second line untarred it and lastly you went into the directory of your new download.</p>
<p>You can do the configuration if you&#039;ll like to edit the installation process. Here&#039;s an excerpt from Sphinx&#039;s site:</p>
<pre>$ ./configure

There's a number of options to configure. The complete listing may be
obtained by using --help switch. The most important ones are:

--prefix, which specifies where to install Sphinx; such as
--prefix=/usr/local/sphinx (all of the examples use this prefix)
--with-mysql, which specifies where to look for MySQL include and
library files, if auto-detection fails;
--with-pgsql, which specifies where to look for PostgreSQL include
and library files.</pre>
<p>Once you&#039;re done then all you have to do is make the binaries and install the software:</p>
<pre>$ make
$ make install</pre>
<p>Once you have installed Sphinx you&#039;ll need to prepare the configuration file. This is the most important part as Sphinx actually acts based on the settings and parameters defined in this single document. Let&#039;s say we&#039;ve installed Sphinx into /usr/local/sphinx. Copy the sample configuration file from the downloaded package into the Sphinx installation folder:</p>
<pre>mv /sphinx/sphinx-min.conf.in /usr/local/sphinx/sphinx.conf </pre>
<p>I named it sphinx.conf for ease, but you can call it anything you want. Now you want to edit sphinx.conf with your favourite editor. I like to use VI editor. Here&#039;s what the initial open of the file looks like and I&#039;ll run through each section of this script.</p>
<pre>#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
	type			= mysql

	sql_host		= localhost
	sql_user		= test
	sql_pass		=
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	sql_query		= \
		SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS
		date_added, title, content \
		FROM table

	sql_attr_uint		= group_id
	sql_attr_timestamp	= date_added

	sql_query_info		= SELECT * FROM table WHERE id=$id
}

index test1
{
	source			= src1
	path			= @CONFDIR@/data/test1
	docinfo			= extern
	charset_type		= sbcs
}

index testrt
{
	type			= rt
	rt_mem_limit		= 32M

	path			= @CONFDIR@/data/testrt
	charset_type		= utf-8

	rt_field		= title
	rt_field		= content
	rt_attr_uint		= gid
}

indexer
{
	mem_limit		= 32M
}

searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= @CONFDIR@/log/searchd.log
	query_log		= @CONFDIR@/log/query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= @CONFDIR@/log/searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 0
	unlink_old		= 1
	workers			= threads # for RT to work
}</pre>
<p>These settings should cover most of what you&#039;re looking for in terms of setting up Sphinx. I&#039;ll try to run through everything as much as possible. There are more parameters and customization you can do by reading their documentation here.</p>
<p><strong>source src1</strong></p>
<p>This section defines your SQL settings and what is needed to be index. So the first few lines sql_host, sql_user, sql_pass, sql_db is exactly your local host MySQL settings. The sql_port is defaulted to 3306. I haven&#039;t changed this setting for Wamp so that&#039;s where my port sits.</p>
<p>The sql_query is actually crucial. This is the query that you want Sphinx to do and build an index on. Its just like an SQL query you would do. Say my table people had columns: id, name, address, city, age, and joined (stored as time stamp) as follow:</p>
<table width="520" border="1" cellspacing="2" cellpadding="2">
<tr>
<td>id</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>age</td>
<td>joined</td>
</tr>
<tr>
<td>50</td>
<td>john doe</td>
<td>546 random st.</td>
<td>Vancouver</td>
<td>42</td>
<td>124568794562</td>
</tr>
<tr>
<td>51</td>
<td>amanda smith</td>
<td>
<p>3425 great ave</p>
</td>
<td>Vancouver</td>
<td>18</td>
<td>124568923423</td>
</tr>
<tr>
<td>52</td>
<td>justin heiber</td>
<td>352 awesome dr</td>
<td>
<p>Burnaby</p>
</td>
<td>56</td>
<td>124569000231</td>
</tr>
<tr>
<td>53</td>
<td>macy store</td>
<td>355 loser pl</td>
<td>Richmond</td>
<td>26</td>
<td>124569000352</td>
</tr>
</table>
<p>I want to be able to search for the people&#039;s name and address only so thats all I care about, but I have to include the id and the timestamp. You can also defined unsigned integer attributes. So my sql_query will be:</p>
<pre>sql_query		= \
		SELECT id, id AS id_attr, name, address, joined  \
		FROM people

sql_attr_uint		= id_attr
sql_attr_timestamp	= joined

sql_query_info		= SELECT * FROM people WHERE id=$id</pre>
<p>I&#039;ve defined the sql_attr_uint, sql_attr_timestamp, and sql_query_info. The sql_attr_uint is the unsigned integer attribute and it can&#039;t be the first column which is to define your id. The sql_attr_timestamp is the UNIX timestamp in your column. You can convert if you want but I usually store my dates in timestamp anyways. The sql_query_info is for testing purpose only. It is the query that retrieves the actual row after searching. You have to do this yourself in your PHP Script.</p>
<p><strong>index test1</strong></p>
<p>You can change the name of test1 to anything you want but for the sake of it I&#039;ll just leave it. The source is just the name of the section we did above. If you changed the name then you have to change it here. The path is where you want to store the indexed file on your site. So I&#039;ll store it in the site directory in a folder called sphinx: /var/www/vhosts/site.com/sphinx/test1. The remainder I left the same. I&#039;ve taken out the real time indexing because I&#039;ll be doing my own thing and I heard there were lots of limitations to it at this point, so its not my thing. If it floats your boat you can do some more research and look into it. Here&#039;s my index:</p>
<pre>index test1
{
	source			= src1
	path			= /var/sphinx/test1
	docinfo			= extern
	charset_type		= sbcs
}
indexer</pre>
<p>This section defines the indexer. My database is big so I increased the mem_limit to 64M. Don&#039;t just go for a high or low number. Too low can hurt your searching and too high can hurt your server. Find the balance based on the size of your database.</p>
<p><strong>searchd</strong></p>
<p>This part defined the searchd which is the search application from Sphinx. Besides the log paths I didn&#039;t change anything else. The listen port is where you want searchd to listen in on for search queries. I left it at 9312 which is where I&#039;ll point my PHP script to later on.</p>
<p>Here is my sphinx.conf file:</p>
<pre>#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
	type			= mysql

	sql_host		= localhost
	sql_user		= test
	sql_pass		=
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	sql_query		= \
		SELECT id, id AS id_attr, name, address, joined  \
		FROM people

	sql_attr_uint		= id_attr
	sql_attr_timestamp	= joined

	sql_query_info		= SELECT * FROM people WHERE id=$id
}

index test1
{
	source			= src1
	path			= /var/sphinx/test1
	docinfo			= extern
	charset_type		= sbcs
}

indexer
{
	mem_limit		= 64M
}

searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= /var/log/sphinx/test1searchd.log
	query_log		= /var/log/sphinx/test1query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= /var/log/sphinx/test1searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 0
	unlink_old		= 1
}</pre>
<h3>Getting Sphinx Ready</h3>
<p>Now that you have the conf file setted up, save and close the file. Now we&#039;re ready to install.</p>
<p>First, we&#039;re going to build the index by typing in <em>indexer -config /usr/local/sphinxsphinx.conf test1</em>. Replace test1 if you changed the name of your index. If you don&#039;t get any errors and see some numbers run then you&#039;re fine.</p>
<p>Once the index is build you want to prepare Sphinx&#039;s service on your machine. Type in searchd -install -config /usr/local/sphinx/sphinx.conf. It&#039;ll prompt you that the installation was successful.</p>
<h3>Testing Sphinx Out</h3>
<p>Let us try out the new nifty search. So say I want to search my table for john doe I&#039;ll type search /usr/local/sphinx/sphinx.conf &#034;john doe&#034;. That should return something for me. I can define the matching modes and which column to search as well such as search -ext2 -config /usr/local/sphinx/sphinx.conf &#034;@name john @address awesome&#034;. If you are getting the results you want then you are ready to move forward into your PHP script.</p>
<h3>Sphinx and Your PHP Script</h3>
<p>You need the Sphinx API in your script for it to work so go to c:\sphinx\api and copy sphinxapi.php to your site directory. Include this file in your script and call on the class:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">require_once</span><span class="br0">&#40;</span><span class="st0">&#039;sphinxapi.php&#039;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//Sphinx</span><br />
<span class="re0">$s</span> = <span class="kw2">new</span> SphinxClient;<br />
<span class="re0">$s</span>-&gt;<span class="me1">setServer</span><span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>, <span class="nu0">9312</span><span class="br0">&#41;</span>;<br />
<span class="re0">$s</span>-&gt;<span class="me1">setMatchMode</span><span class="br0">&#40;</span>SPH_MATCH_EXTENDED2<span class="br0">&#41;</span>;</div>
<p>Noticed I have setServer pointing to the port I told Sphinx to listen to. The setMatchMode is just the matching mode you&#039;ll like to use. In my case I&#039;m using extended 2.</p>
<p>Now you can query search your Sphinx index with:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="co1">//Search Query</span><br />
<span class="re0">$result</span> = <span class="re0">$s</span>-&gt;<span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;@name $searchName @address $searchAddress&quot;</span><span class="br0">&#41;</span>;</div>
<p>The $result returned will not include the rows and columns of your actual table. It&#039;ll return the follow parameters (taken from <a href="http://www.php.net" target="_blank">php.net</a>):</p>
<table width="520" border="1" cellpadding="1" cellspacing="1">
<thead valign="middle">
<tr valign="middle">
<th>Key</th>
<th>Value description</th>
</tr>
</thead>
<tbody valign="middle">
<tr valign="middle">
<td align="left">&quot;matches&quot;</td>
<td align="left">An array with found document IDs as keys and their weight and attributes values as values</td>
</tr>
<tr valign="middle">
<td align="left">&quot;total&quot;</td>
<td align="left">Total number of matches found and retrieved (depends on your settings)</td>
</tr>
<tr valign="middle">
<td align="left">&quot;total_found&quot;</td>
<td align="left">Total number of found documents matching the query</td>
</tr>
<tr valign="middle">
<td align="left">&quot;words&quot;</td>
<td align="left">An array with words (case-folded and stemmed) as keys and per-word statistics as values</td>
</tr>
<tr valign="middle">
<td align="left">&quot;error&quot;</td>
<td align="left">Query error message reported by searchd</td>
</tr>
<tr valign="middle">
<td align="left">&quot;warning&quot;</td>
<td align="left">Query warning reported by searchd</td>
</tr>
</tbody>
</table>
<p>This means that $result['total'] will tell me how many results were found and $result['matches'] is where the id of the search results are stored. So here&#039;s a simple line to return all of the results:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#91;</span><span class="st0">&#039;total&#039;</span><span class="br0">&#93;</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#91;</span><span class="st0">&#039;matches&#039;</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re0">$id</span> =&gt; <span class="re0">$otherStuff</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Get Column</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$searchColumn</span> = <a href="http://www.php.net/mysql_fetch_array"><span class="kw3">mysql_fetch_array</span></a><span class="br0">&#40;</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM people WHERE id=$id&quot;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Dump</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span><span class="re0">$searchColumn</span><span class="br0">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;No results found&#039;</span>; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span class="br0">&#125;</span></div>
<p>Notice that the mysql_query is the same as sql_query_info in sphinx.conf. What a coincidence eh? LOL. That is all and now you have a working Sphinx search system setup on your local machine. If you need to reindex your Sphinx you can do so without restarting the service. In command prompt just run <em>indexer -config /usr/local/sphinx/sphinx.conf -rotate test1</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Intalling Sphinx on Wamp localhost (Windows)</title>
		<link>http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows</link>
		<comments>http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows#comments</comments>
		<pubDate>Sun, 03 Apr 2011 20:42:39 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=458</guid>
		<description><![CDATA[I recall the first time trying to setup Sphinx search on my Windows machine with Wamp it wasn't so obvious of how it was to be setup. Here's a guide in how to get it setup on you local machine. If you want to <a href="http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh">install Sphinx on Linux / Plesk</a> there's an article for that too.]]></description>
			<content:encoded><![CDATA[<p>I recall the first time trying to setup Sphinx search on my Windows machine with Wamp it wasn&#039;t so obvious of how it was to be setup. Here&#039;s a guide in how to get it setup on you local machine. If you want to <a href="http://www.crankberryblog.com/2011/installing-sphinx-on-centoslinux-through-ssh">install Sphinx on Linux / Plesk</a> there&#039;s an article for that too.</p>
<p>Here is my environment:</p>
<ul>
<li>Windows Vista</li>
<li>Wamp 2.0</li>
<li>Apache 2.2.11</li>
<li>MySQL 5.1.36</li>
<li>PHP 5.3.0</li>
<li>Sphinx 1.10</li>
</ul>
<p>First of all download Sphinx for Windows which can be found (<a href="http://sphinxsearch.com/downloads/beta/">http://sphinxsearch.com/downloads/beta/</a>). I downloaded Win32 binaries w/MySQL support version because I only work with MySQL. Once you got this you&#039;re ready to begin.</p>
<h3>How Does Sphinx Works</h3>
<p>In brief this is how Sphinx works. Sphinx creates a separate index of the table you want to search. Your PHP scripts calls the Sphinx API to search connecting to a specific port where Sphinx is listening to. Sphinx then searches its own index and does the search returning the result. Yes, the index has to be updated every time your update your original table. On my live environment I have a <a href="http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab">cron job</a> setup to reindex with Sphinx every so often.</p>
<h3>Step 1 Extract and Prepare Conf File</h3>
<p>Extract the files into any folder you want, I&#039;ve selected c:\sphinx\. The next thing you need to do is create a document in c:\sphinx\bin called sphinx.conf. This is the most important part as Sphinx actually acts based on the settings and parameters defined in this single document. Once you have created sphinx.conf in the bin folder copy the content from c:\sphinx\sphinx-min.conf.in (this is their provided sample file). It looks like:</p>
<pre>#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
	type			= mysql

	sql_host		= localhost
	sql_user		= test
	sql_pass		=
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	sql_query		= \
		SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS
		date_added, title, content \
		FROM table

	sql_attr_uint		= group_id
	sql_attr_timestamp	= date_added

	sql_query_info		= SELECT * FROM table WHERE id=$id
}

index test1
{
	source			= src1
	path			= @CONFDIR@/data/test1
	docinfo			= extern
	charset_type		= sbcs
}

index testrt
{
	type			= rt
	rt_mem_limit		= 32M

	path			= @CONFDIR@/data/testrt
	charset_type		= utf-8

	rt_field		= title
	rt_field		= content
	rt_attr_uint		= gid
}

indexer
{
	mem_limit		= 32M
}

searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= @CONFDIR@/log/searchd.log
	query_log		= @CONFDIR@/log/query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= @CONFDIR@/log/searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 0
	unlink_old		= 1
	workers			= threads # for RT to work
}</pre>
<p>These settings should cover most of what you&#039;re looking for in terms of setting up Sphinx. I&#039;ll try to run through everything as much as possible. There are more parameters and customization you can do by reading their documentation <a href="http://sphinxsearch.com/docs/1.10/">here</a>.</p>
<p><strong>source src1</strong></p>
<p>This section defines your SQL settings and what is needed to be index. So the first few lines sql_host, sql_user, sql_pass, sql_db is exactly your local host MySQL settings. The sql_port is defaulted to 3306. I haven&#039;t changed this setting for Wamp so that&#039;s where my port sits.</p>
<p>The sql_query is actually crucial. This is the query that you want Sphinx to do and build an index on. Its just like an SQL query you would do. Say my table people had columns: id, name, address, city, age, and joined (stored as time stamp) as follow: </p>
<table width="520" border="1" cellspacing="2" cellpadding="2">
<tr>
<td>id</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>age</td>
<td>joined</td>
</tr>
<tr>
<td>50</td>
<td>john doe</td>
<td>546 random st.</td>
<td>Vancouver</td>
<td>42</td>
<td>124568794562</td>
</tr>
<tr>
<td>51</td>
<td>amanda smith</td>
<td>
<p>3425 great ave</p>
</td>
<td>Vancouver</td>
<td>18</td>
<td>124568923423</td>
</tr>
<tr>
<td>52</td>
<td>justin heiber</td>
<td>352 awesome dr</td>
<td>
<p>Burnaby</p>
</td>
<td>56</td>
<td>124569000231</td>
</tr>
<tr>
<td>53</td>
<td>macy store</td>
<td>355 loser pl</td>
<td>Richmond</td>
<td>26</td>
<td>124569000352</td>
</tr>
</table>
<p>I want to be able to search for the people&#039;s name and address only so thats all I care about, but I have to include the id and the timestamp. You can also defined unsigned integer attributes. So my sql_query will be:</p>
<pre>sql_query		= \
		SELECT id, id AS id_attr, name, address, joined  \
		FROM people

sql_attr_uint		= id_attr
sql_attr_timestamp	= joined

sql_query_info		= SELECT * FROM people WHERE id=$id</pre>
<p>I&#039;ve defined the sql_attr_uint, sql_attr_timestamp, and sql_query_info. The sql_attr_uint is the unsigned integer attribute and it <strong>can&#039;t</strong> be the first column which is to define your id. The sql_attr_timestamp is the UNIX timestamp in your column. You can convert if you want but I usually store my dates in timestamp anyways. The sql_query_info is for testing purpose only. It is the query that retrieves the actual row after searching. You have to do this yourself in your PHP Script.</p>
<p><strong>index test1</strong></p>
<p>You can change the name of test1 to anything you want but for the sake of it I&#039;ll just leave it. The source is just the name of the section we did above. If you changed the name then you have to change it here. The path is where you want to store the indexed file on your site. So I&#039;ll store it in the site directory in a folder called sphinx: C:\Wamp\www\site\sphinx\test1. The remainder I left the same. I&#039;ve taken out the real time indexing because I&#039;ll be doing my own thing and I heard there were lots of limitations to it at this point, so its not my thing. If it floats your boat you can do some more research and look into it. Here&#039;s my index:</p>
<pre>index test1
{
	source			= src1
	path			= C:\Wamp\www\site\sphinx\test1
	docinfo			= extern
	charset_type		= sbcs
}</pre>
<p><strong>indexer</strong></p>
<p>This section defines the indexer. My database is big so I increased the mem_limit to 64M. Don&#039;t just go for a high or low number. Too low can hurt your searching and too high can hurt your server. Find the balance based on the size of your database.</p>
<p><strong>searchd</strong></p>
<p>This part defined the searchd which is the search application from Sphinx. Besides the log paths I didn&#039;t change anything else. The listen port is where you want searchd to listen in on for search queries. I left it at 9312 which is where I&#039;ll point my PHP script to later on.</p>
<p>Here is my sphinx.conf file:</p>
<pre>#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
	type			= mysql

	sql_host		= localhost
	sql_user		= test
	sql_pass		=
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	sql_query		= \
		SELECT id, id AS id_attr, name, address, joined  \
		FROM people

	sql_attr_uint		= id_attr
	sql_attr_timestamp	= joined

	sql_query_info		= SELECT * FROM people WHERE id=$id
}

index test1
{
	source			= src1
	path			= C:\Wamp\www\s\sphinx\test1
	docinfo			= extern
	charset_type		= sbcs
}

indexer
{
	mem_limit		= 64M
}

searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= C:\Wamp\www\s\sphinx\searchd.log
	query_log		= C:\Wamp\www\s\sphinx\query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= C:\Wamp\www\s\sphinx\searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 0
	unlink_old		= 1
}</pre>
<h3>Getting Sphinx Ready</h3>
<p>Now that you have prepared the Configuration file which is the hardest part of this then you&#039;re ready to begin. The first part you want to do is prepare the Sphinx index. Open up your command promt (Start > Search [cmd] > CMD.</p>
<p>In command promt navigate to your Sphinx bin folder by typing in <em>cd c:\sphinx\bin</em>. </p>
<p>Once there launched the indexer to build the index by typing in <em>indexer.exe &#8211;config c:\sphinx\bin\sphinx.conf test1</em>. Replace test1 if you changed the name of your index. If you don&#039;t get any errors and see some numbers run then you&#039;re fine. If you get a &#034;failed to write&#034; message it&#039;s because you don&#039;t have admin access to your machine.</p>
<p>Once the index is build you want to install Sphinx on your Windows machine as a service by typing <em>searchd.exe &#8211;install &#8211;config c:\sphinx\bin\sphinx.conf &#8211;servicename Sphinx</em>. It&#039;ll prompt you that the installation was successful.</p>
<p>Now you have to start the service you just installed. Go to control panel > administrative tools > services. Find Sphinx in the list. Click on it and on the left side you should see Start (on my machine that&#039;s where it is). Click on it and it should start.</p>
<h3>Testing Sphinx Out</h3>
<p>Go back to command prompt and test it out using search. So say I want to search my table for john doe I&#039;ll type <em>search sphinx.conf &#034;john doe&#034;</em>. That should return something for me. I can define the <a href="http://sphinxsearch.com/docs/1.10/matching-modes.html">matching modes</a> and which column to search as well such as <em>search &#8211;ext2 &#8211;config sphinx.conf &#034;@name john @address awesome&#034;</em>. If you are getting the results you want then you are ready to move forward into your PHP script.</p>
<h3>Sphinx and Your PHP Script</h3>
<p>You need the Sphinx API in your script for it to work so go to c:\sphinx\api and copy sphinxapi.php to your site directory. Include this file in your script and call on the class:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">require_once</span><span class="br0">&#40;</span><span class="st0">&#039;sphinxapi.php&#039;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//Sphinx</span><br />
<span class="re0">$s</span> = <span class="kw2">new</span> SphinxClient;<br />
<span class="re0">$s</span>-&gt;<span class="me1">setServer</span><span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>, <span class="nu0">9312</span><span class="br0">&#41;</span>;<br />
<span class="re0">$s</span>-&gt;<span class="me1">setMatchMode</span><span class="br0">&#40;</span>SPH_MATCH_EXTENDED2<span class="br0">&#41;</span>;</div>
<p>Noticed I have setServer pointing to the port I told Sphinx to listen to. The setMatchMode is just the matching mode you&#039;ll like to use. In my case I&#039;m using extended 2.</p>
<p>Now you can query search your Sphinx index with:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="co1">//Search Query</span><br />
<span class="re0">$result</span> = <span class="re0">$s</span>-&gt;<span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;@name $searchName @address $searchAddress&quot;</span><span class="br0">&#41;</span>;</div>
<p>The $result returned will not include the rows and columns of your actual table. It&#039;ll return the follow parameters (taken from <a href="http://php.net/manual/en/sphinxclient.query.php">php.net</a>):</p>
<table width="520" border="1" cellpadding="1" cellspacing="1">
<thead valign="middle">
<tr valign="middle">
<th>Key</th>
<th>Value description</th>
</tr>
</thead>
<tbody valign="middle">
<tr valign="middle">
<td align="left">&quot;matches&quot;</td>
<td align="left">An array with found document IDs as keys and their weight and attributes values as values</td>
</tr>
<tr valign="middle">
<td align="left">&quot;total&quot;</td>
<td align="left">Total number of matches found and retrieved (depends on your settings)</td>
</tr>
<tr valign="middle">
<td align="left">&quot;total_found&quot;</td>
<td align="left">Total number of found documents matching the query</td>
</tr>
<tr valign="middle">
<td align="left">&quot;words&quot;</td>
<td align="left">An array with words (case-folded and stemmed) as keys and per-word statistics as values</td>
</tr>
<tr valign="middle">
<td align="left">&quot;error&quot;</td>
<td align="left">Query error message reported by searchd</td>
</tr>
<tr valign="middle">
<td align="left">&quot;warning&quot;</td>
<td align="left">Query warning reported by searchd</td>
</tr>
</tbody>
</table>
<p>This means that $result['total'] will tell me how many results were found and $result['matches'] is where the id of the search results are stored. So here&#039;s a simple line to return all of the results:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#91;</span><span class="st0">&#039;total&#039;</span><span class="br0">&#93;</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#91;</span><span class="st0">&#039;matches&#039;</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re0">$id</span> =&gt; <span class="re0">$otherStuff</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Get Column</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$searchColumn</span> = <a href="http://www.php.net/mysql_fetch_array"><span class="kw3">mysql_fetch_array</span></a><span class="br0">&#40;</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM people WHERE id=$id&quot;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Dump</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span><span class="re0">$searchColumn</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;No results found&#039;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></div>
<p>Notice that the mysql_query is the same as sql_query_info in sphinx.conf. What a coincidence eh? LOL. That is all and now you have a working Sphinx search system setup on your local machine. If you need to reindex your Sphinx you can do so without restarting the service. In command prompt just run <em>indexer.exe &#8211;config c:\sphinx\bin\sphinx.conf &#8211;rotate test1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Why do I get &quot;page includes resources which are not secure&quot;</title>
		<link>http://www.crankberryblog.com/2011/why-do-i-get-page-includes-resources-which-are-not-secure</link>
		<comments>http://www.crankberryblog.com/2011/why-do-i-get-page-includes-resources-which-are-not-secure#comments</comments>
		<pubDate>Thu, 03 Mar 2011 23:51:11 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Security]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=454</guid>
		<description><![CDATA[You just built a site, and have implemented <a href="http://www.crankberryblog.com/2009/what-is-ssl-and-do-i-need-ssl">SSL</a>, but when you go to test it you get "page includes resources which are not secure". This is annoying but you need to fix it.]]></description>
			<content:encoded><![CDATA[<p>You just built a site, and have implemented <a href="http://www.crankberryblog.com/2009/what-is-ssl-and-do-i-need-ssl">SSL</a>, but when you go to test it you get &#034;page includes resources which are not secure&#034;. This is annoying but you need to fix it.</p>
<p>You can choose to ignore it as for most browser this message is not obtrusive but for some this may generate constant popups that will bug the hell out of your users.</p>
<p>There is only one reason why this message shows up but maybe multiple elements that contributes to this. The reason why this message appears is that on the page you&#039;re trying to load through SSL you have links to elements that are not secured through the layer. The warning is letting the user know that although the page maybe secure some elements could put the user at risk. It is essential to have this message. Image you&#039;re on a payment website about to type in your credit card and &#034;BAM&#034; this message pops up. What if it is the credit card module that is not secure? Wouldn&#039;t you worry? Let&#039;s see some of the elements that causes this.</p>
<h3>Your Own Content</h3>
<p>Depending on the way you apply SSL to your user there maybe a leakage in the elements that are secure. You can use HTACCESS to force SSL on a folder by placing this in .htaccess within that folder:</p>
<div class="dean_ch" style="white-space: wrap;"># Turn On for This Folder<br />
RewriteCond %{SERVER_PORT} 80 <br />
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]</div>
<p>This is assuming you have the rewrite engine and everything enabled. If you have a single file within the directory put into SSL this might be trickier. Look at the page and the elements it links to. Although the page maybe forced into SSL the images, scripts and CSS may not be (don&#039;t worry about included PHP scripts they don&#039;t count for this). The method that could work is to force those directory into SSL as well. Now this code is not perfect but it has worked:</p>
<div class="dean_ch" style="white-space: wrap;">RewriteCond %{SERVER_PORT} ^443$<br />
RewriteCond %{REQUEST_URI} ^/(image|css|javascripts)/?<br />
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/$2 [R,L]</div>
<p>Basically image, css and javascripts are locations (folders) where those files are located. Change these based on your files. Add more directories with | in between each name.</p>
<h3>Analytics</h3>
<p>If you use a third party analytics tracker you may have pasted some sort of code at the bottom of your page. Depending on who you use they may not support SSL. If that&#039;s the case you can code it into your file to exclude the script from running. Here&#039;s a PHP example:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#039;HTTPS&#039;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> || <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#039;HTTPS&#039;</span><span class="br0">&#93;</span> != <span class="st0">&quot;on&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw2">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Analytics Script</span><br />
<span class="kw2">&lt;?php</span> <span class="br0">&#125;</span> <span class="kw2">?&gt;</span></div>
<h3>Advertisement and Third Party Codes</h3>
<p>Just like the analytics code above, third party codes may not have an SSL option for you. If you use a third party code on your site such as advertisements, widgets and feeds you may have to turn it off with the same code as above:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#039;HTTPS&#039;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> || <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#039;HTTPS&#039;</span><span class="br0">&#93;</span> != <span class="st0">&quot;on&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw2">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Ads, Widgets and Feeds</span><br />
<span class="kw2">&lt;?php</span> <span class="br0">&#125;</span> <span class="kw2">?&gt;</span></div>
<p>The downside is that on these pages you can&#039;t use the third party codes. Depending on the page, you may not want to anyways. For example, if you were using analytics on a checkout page, you may just want to check your database for actual analytics rather than hits and bounce rates.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/why-do-i-get-page-includes-resources-which-are-not-secure/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Structuring websites in terms of folders, codes and naming conventions</title>
		<link>http://www.crankberryblog.com/2011/structuring-websites-in-terms-of-folders-codes-and-naming-conventions</link>
		<comments>http://www.crankberryblog.com/2011/structuring-websites-in-terms-of-folders-codes-and-naming-conventions#comments</comments>
		<pubDate>Thu, 03 Mar 2011 23:25:29 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=447</guid>
		<description><![CDATA[When you begin to build bigger sites composed of 50 or more files you start to get messy and unorganized - it's time to structure. The key to organizing a website is folders, code structure and naming conventions. Master these skills, be consistent, and you'll be more organize and prepared for the future.]]></description>
			<content:encoded><![CDATA[<p>When you begin to build bigger sites composed of 50 or more files you start to get messy and unorganized &#8211; it&#039;s time to structure. The key to organizing a website is folders, code structure and naming conventions. Master these skills, be consistent, and you&#039;ll be more organize and prepared for the future.</p>
<p>The future means resume working on a site after a long break. Often, when you&#039;re working on a site you&#039;ll know where every single line of code is. It&#039;s just like when you leave your keys or wallet somewhere, chances are you&#039;ll remember where it&#039;s located, but leave it there for a year and try to find it &#8211; unless it&#039;s in hindsight you&#039;ll forget where you&#039;ve put them. Train yourself to be organized and let it be a habit. Coming back to a site that you have left for months or years will natural as your organization skills haven&#039;t changed.</p>
<h3>Folders</h3>
<p>The first and simplest thing you can use is folders. Everybody knows how to create them and place files inside. Use them to group files together. One thing most developer will do is place all images in a folder, so that is a good start. Do this for everything. You can group css, images, functions, javascripts, and templates in their own folders. The first two maybe obvious and probably done by most developers already. As for functions, these can be scripts that are mainly classes and specific funtions. Javascripts can be all javascripts or specific ones like JQuery related codes. The last group, templates, can hold files that affects the aesthetics of the site (non-css files).</p>
<p>You can also use subfolders if you have a lot of files within each folder. If your site is composed of thousands of images, group them based on their location or their function of the site. Location based could be broken down as header, footer, landing page, content page and etc. Function based grouping can be something like user profiles, navigation, products and etc. I&#039;d like to keep it to the rule of third which is no further than three levels deep as then it starts to get messy again, but this really depends on your site. If your site is composed of thousands or files, then be my guest.</p>
<h3>Code Structure</h3>
<p>The structure of your code within each file is more of an art than science. Do what you need to do but ensure you&#039;re organized. Use comments as much as possible and don&#039;t be afraid to be descriptive. You can be creating with your comments as to highlight sections and create titles for individual sections. On certain files such as CSS you can code a based on hierarchy of your site, which means the top of your file defines the HTML then the BODY all the way to the FOOTER which is at the bottom. This type of structure can only work on certain files. Try and see what works best.</p>
<h3>Naming Conventions</h3>
<p>Organizing your files based on name is a really good skill too. If multiple files work together in a certain way you can name them to group them together without necessarly creating a folder for them. Say three files work together to make up the product update module you can have them named prod_update_delete.php, prod_update_edit and prod_update_info.php. That way when you need to edit the product update module you can quickly find the three files and know where to go. If the module has its own folder you can still combine the two for a quicker find, such as:</p>
<ul>
<li>[FOLDER] administrator
<ul>
<li>[FOLDER] products</li>
<li>[FILE] _class_prod.php</li>
<li>[FILE] _class_search.php</li>
<li>[FILE] _class_template.php</li>
<li>[FILE] images.php</li>
<li>[FILE] prod_update_delete.php</li>
<li>[FILE] prod_update_edit.php</li>
<li>[FILE] prod_update_info.php</li>
<li>[FILE] search.php</li>
<li>[FOLDER] shopping_cart</li>
</ul>
</li>
<li>[FOLDER] css</li>
<li>[FOLDER] images</li>
<li>[FOLDER] javascript</li>
</ul>
<p>Underscores can be used to bring files to the top of the list. You can use this for important or commonly shared files within the module such as classes and functions.</p>
<p>Structure and organization is good skills and habits to have especially if you work with multiple sites at a time or you often leave and come back to sites. Like everything else you do, you&#039;ll need practice to get better. Chances are you won&#039;t be comfortable with the way you did things on your first try, keep changing and perfecting it until you&#039;re where you prefer. As you deviate and evolve try to be consistent, it&#039;ll keep your style flowing. Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2011/structuring-websites-in-terms-of-folders-codes-and-naming-conventions/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP text based counter &#8211; script specific no MySQL counter</title>
		<link>http://www.crankberryblog.com/2010/php-text-based-counter-script-specific</link>
		<comments>http://www.crankberryblog.com/2010/php-text-based-counter-script-specific#comments</comments>
		<pubDate>Wed, 29 Sep 2010 17:49:03 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[PHP Script]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=428</guid>
		<description><![CDATA[Here's a counter script that can help you count downloads, specific pages, or overall general count. This is a simple function that works by storing text rather than using a MySQL database. Just for quick usage.]]></description>
			<content:encoded><![CDATA[<p>Here&#039;s a counter script that can help you count downloads, specific pages, or overall general count. This is a simple function that works by storing text rather than using a MySQL database. Just for quick usage.</p>
<p>A sample of the results page:</p>
<p><img src="http://www.crankberryblog.com/images/counter.jpg" /></p>
<p>Here&#039;s the function that you&#039;ll need for this to work.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> counter<span class="br0">&#40;</span><span class="re0">$counterName</span>, <span class="re0">$counterStage</span> = <span class="st0">&#039;store&#039;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$counter_name</span> = <a href="http://www.php.net/preg_replace"><span class="kw3">preg_replace</span></a><span class="br0">&#40;</span><span class="st0">&quot;/[^a-zA-Z0-9-]/&quot;</span>, <span class="st0">&quot;&quot;</span>, <span class="re0">$counterName</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//File</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$file</span> = <span class="st0">&#039;counter/counter_&#039;</span> . <span class="re0">$counter_name</span> . <span class="st0">&#039;.csv&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Get Time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$now</span> = <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="st0">&quot;now&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//IP</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$ip</span> = <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#039;REMOTE_ADDR&#039;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Open File</span><br />
&nbsp; &nbsp; <span class="re0">$handle</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="re0">$file</span>, <span class="st0">&quot;a+&quot;</span><span class="br0">&#41;</span>; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Store</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$counterStage</span> == <span class="st0">&#039;store&#039;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Store Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$storeArray</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$ip</span>, <span class="re0">$now</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Store</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fputcsv<span class="br0">&#40;</span><span class="re0">$handle</span>, <span class="re0">$storeArray</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Read</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">elseif</span> <span class="br0">&#40;</span><span class="re0">$counterStage</span> == <span class="st0">&#039;read&#039;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Row Counter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span> = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$totalRow</span> = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dispArray</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$data</span> = <a href="http://www.php.net/fgetcsv"><span class="kw3">fgetcsv</span></a><span class="br0">&#40;</span><span class="re0">$handle</span>, <span class="nu0">0</span>, <span class="st0">&quot;,&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> !== <span class="kw2">FALSE</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Counter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$num</span> = <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$data</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Store To Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$totalRow</span> &lt; <span class="nu0">100</span><span class="br0">&#41;</span> <span class="re0">$dispArray</span><span class="br0">&#91;</span><span class="re0">$row</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$data</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>, <span class="re0">$data</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Increase Row</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span>++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$totalRow</span>++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Display</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;h2&gt;Counter Total For &#039;</span> . <span class="re0">$counterName</span> . <span class="st0">&#039;: &#039;</span> . <span class="re0">$row</span> . <span class="st0">&#039;&lt;/h2&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;Recent 100 Counts (&lt;a href=&quot;&#039;</span> . <span class="re0">$file</span> .<span class="st0">&#039;&quot; target=&quot;_blank&quot;&gt;Download full Stats&lt;/a&gt;):</p>
<p>&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;table border=&quot;1&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot;&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;20&quot; style=&quot;font-size: 10px;&quot;&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;100&quot; style=&quot;font-size: 10px;&quot;&gt;&lt;strong&gt;IP&lt;/strong&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;160&quot; style=&quot;font-size: 10px;&quot;&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Sort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/krsort"><span class="kw3">krsort</span></a><span class="br0">&#40;</span><span class="re0">$dispArray</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$rowCount</span> = <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Displaying</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$dispArray</span> <span class="kw1">as</span> <span class="re0">$row</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;font-size: 10px;&quot;&gt;&#039;</span> . <span class="re0">$rowCount</span> . <span class="st0">&#039;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;font-size: 10px;&quot;&gt;&#039;</span> . <span class="re0">$row</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> . <span class="st0">&#039;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;font-size: 10px;&quot;&gt;&#039;</span> . <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&#039;M d, Y h:i a&#039;</span>, <span class="re0">$row</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> . <span class="st0">&#039;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$rowCount</span>++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;/table&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>To call the script to store this is the function to call:</p>
<div class="dean_ch" style="white-space: wrap;">counter<span class="br0">&#40;</span><span class="st0">&#039;test&#039;</span><span class="br0">&#41;</span>;</div>
<p>The above case would store in a script called &#034;test&#034;. If you&#039;re trying to do specific pages you can name your script home, about, or contact, whichever you please. To view results you&#039;ll call it with.</p>
<div class="dean_ch" style="white-space: wrap;">counter<span class="br0">&#40;</span><span class="st0">&#039;test&#039;</span>, <span class="st0">&#039;read&#039;</span><span class="br0">&#41;</span>;</div>
<p>Same thing with the store function just change &#034;test&#034; to whichever counter you wish to retrieve.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2010/php-text-based-counter-script-specific/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP Cron job without using Cron tab (cron alternative with MySQL or just txt)</title>
		<link>http://www.crankberryblog.com/2010/php-cron-job-without-using-cron-tab-cron-alternative-with-mysql-or-just-txt</link>
		<comments>http://www.crankberryblog.com/2010/php-cron-job-without-using-cron-tab-cron-alternative-with-mysql-or-just-txt#comments</comments>
		<pubDate>Tue, 28 Sep 2010 00:21:49 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cron alternative]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[cron tab]]></category>
		<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=420</guid>
		<description><![CDATA[You may have the need to schedule a PHP script to run but don't know and don't want to bother to learn how to use <a href="http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab">CRON job</a>. That is ok because when I develop for smaller clients with shared hosting I tend to use a different technique anyways. Here's my alternative to running a  CRON tab.]]></description>
			<content:encoded><![CDATA[<p>You may have the need to schedule a PHP script to run but don&#039;t know and don&#039;t want to bother to learn how to use <a href="http://www.crankberryblog.com/2009/setting-php-cron-job-with-crontab">CRON job</a>. That is ok because when I develop for smaller clients with shared hosting I tend to use a different technique anyways. Here&#039;s my alternative to running a  CRON tab.</p>
<p>Its simple and many developers have mentioned it, just include the script in your scripts to run. Here&#039;s how to set this up. First of all you&#039;ll need to setup a MySQL table to store the date. If you don&#039;t have access to a MySQL database or choose not to use one, then you are being too picky. Doesn&#039;t matter, I&#039;ll work with you here. </p>
<h3>MySQL Version &#8211; Create this Table</h3>
<div class="dean_ch" style="white-space: wrap;">CREATE TABLE <span class="kw1">IF</span> NOT EXISTS cronjob <span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; job_id bigint<span class="br0">&#40;</span><span class="nu0">20</span><span class="br0">&#41;</span> NOT <span class="kw2">NULL</span> AUTO_INCREMENT,<br />
&nbsp; &nbsp; job_name varchar<span class="br0">&#40;</span><span class="nu0">50</span><span class="br0">&#41;</span> NOT <span class="kw2">NULL</span>,<br />
&nbsp; &nbsp; job_date bigint<span class="br0">&#40;</span><span class="nu0">12</span><span class="br0">&#41;</span> NOT <span class="kw2">NULL</span>,<br />
&nbsp; &nbsp; PRIMARY <a href="http://www.php.net/key"><span class="kw3">KEY</span></a> <span class="br0">&#40;</span>job_id<span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; INDEX <span class="br0">&#40;</span>job_name<span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; INDEX <span class="br0">&#40;</span>job_date<span class="br0">&#41;</span><br />
<span class="br0">&#41;</span></div>
<h3>Non MySQL Version &#8211; Do This</h3>
<p>If you are not using MySQL database then create a file called cronjob.txt and just leave the content of it blank.</p>
<h2>The CRON function</h2>
<p>You&#039;ll need to have this function either in your script or in the class/object that you&#039;re using. </p>
<div class="dean_ch" style="white-space: wrap;"><span class="co1">//Cronjob Function</span><br />
<span class="kw2">function</span> cronjob <span class="br0">&#40;</span><span class="re0">$runScript</span>, <span class="re0">$runHours</span> = <span class="nu0">1</span>, <span class="re0">$database</span> = <span class="kw2">TRUE</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Get Time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$now</span> = <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="st0">&quot;now&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$runScript_name</span> = <a href="http://www.php.net/preg_replace"><span class="kw3">preg_replace</span></a><span class="br0">&#40;</span><span class="st0">&quot;/[^a-zA-Z0-9-]/&quot;</span>, <span class="st0">&quot;&quot;</span>, <span class="re0">$runScript</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Convert Time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$timePass</span> = <span class="br0">&#40;</span> <span class="nu0">60</span> * <span class="nu0">60</span> <span class="br0">&#41;</span> * <span class="re0">$runHours</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$timeLast</span> = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Get Passed Time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$database</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$get_time</span> = <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span> <span class="st0">&quot;SELECT job_date FROM cronjob WHERE job_name=&#039;$runScript_name&#039; ORDER BY job_date DESC LIMIT 0, 1&quot;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$get_time_num</span> = <a href="http://www.php.net/mysql_num_rows"><span class="kw3">mysql_num_rows</span></a><span class="br0">&#40;</span><span class="re0">$get_time</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Reading</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$get_time_num</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="re0">$timeLast</span> = <a href="http://www.php.net/mysql_result"><span class="kw3">mysql_result</span></a><span class="br0">&#40;</span> <span class="re0">$get_time</span>, <span class="nu0">0</span>, <span class="st0">&#039;job_date&#039;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//File</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$file</span> = <span class="st0">&#039;cronjob/cronjob_&#039;</span> . <span class="re0">$runScript_name</span> . <span class="st0">&#039;.txt&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Open File</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$handle</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="re0">$file</span>, <span class="st0">&quot;a+&quot;</span><span class="br0">&#41;</span>;&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$get_time</span> = <a href="http://www.php.net/fread"><span class="kw3">fread</span></a><span class="br0">&#40;</span><span class="re0">$handle</span>, <span class="nu0">12</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$get_time</span> != <span class="st0">&#034;</span><span class="br0">&#41;</span> <span class="re0">$timeLast</span> = <span class="re0">$get_time</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Close</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Run Script</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$timeLast</span> + <span class="re0">$timePass</span><span class="br0">&#41;</span> &lt; <span class="re0">$now</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Run Script</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">include</span> <span class="br0">&#40;</span> <span class="re0">$runScript</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Ending</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$database</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Insert Time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$insert_time</span> = @<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span> <span class="st0">&quot;INSERT INTO cronjob(job_name, job_date) VALUES(&#039;$runScript_name&#039;, &#039;$now&#039;)&quot;</span> <span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Open File</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$handle</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="re0">$file</span>, <span class="st0">&quot;w&quot;</span><span class="br0">&#41;</span>;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Write</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/fwrite"><span class="kw3">fwrite</span></a><span class="br0">&#40;</span><span class="re0">$handle</span>, <span class="re0">$now</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Close File</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></div>
<h2>Using the Function</h2>
<p>To call the cron job simple include the following line in one of the scripts that&#039;s often loaded in your site.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="co1">//Run Job &#8211; MySQL Database Version</span><br />
cronjob <span class="br0">&#40;</span><span class="st0">&#039;function/delete_logistics.php&#039;</span>, <span class="nu0">1</span>, <span class="kw2">TRUE</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//Run Job &#8211; Txt Version</span><br />
cronjob <span class="br0">&#40;</span><span class="st0">&#039;function/delete_logistics.php&#039;</span>, <span class="nu0">1</span>, <span class="kw2">TRUE</span><span class="br0">&#41;</span>;</div>
<p>Basically you call the function cronjob and the arguements are: script name, hours to run script, and using MySQL database (TRUE for yes and FALSE for no). Say I want to run the script crankberry_awesome.php every two days using txt format. This is what I would have.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="co1">//Run Job</span><br />
cronjob <span class="br0">&#40;</span><span class="st0">&#039;crankberry_awesome.php&#039;</span>, <span class="nu0">48</span>, <span class="kw2">FALSE</span><span class="br0">&#41;</span>;</div>
<p>That&#039;s all there is to it. So have fun with running your crons aka scheduled PHP tasks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2010/php-cron-job-without-using-cron-tab-cron-alternative-with-mysql-or-just-txt/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The ultimate newb&#039;s guide to learning web development (Pt. 1: The Basic)</title>
		<link>http://www.crankberryblog.com/2010/the-ultimate-newbs-guide-to-learning-web-development-pt-1-the-basic</link>
		<comments>http://www.crankberryblog.com/2010/the-ultimate-newbs-guide-to-learning-web-development-pt-1-the-basic#comments</comments>
		<pubDate>Fri, 24 Sep 2010 22:22:21 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=406</guid>
		<description><![CDATA[If you are just discovering the world of web development but know nothing about HTML code, css and mumble-jumble, here's a good place to start. In this article I will outline in general where to find resources and some good skills to pick up on to becoming a minor expert in the field.]]></description>
			<content:encoded><![CDATA[<p>If you are just discovering the world of web development but know nothing about HTML code, css and mumble-jumble, here&#039;s a good place to start. In this article I will outline in general where to find resources and some good skills to pick up on to becoming a minor expert in the field.</p>
<p>To be honest, web development is all about practice and understanding, of course creativity as well (I&#039;ll get to this later). Here&#039;s a little scope about how I picked up on web development. I started making websites through FrontPage when I was 13, using only a bit of HTML and mainly the WYSIWYG (what you see is what you get) editor. It wasn&#039;t until I was 15 that I started developing with HTML and using CSS. When I was 18 I felt the need for more power in my websites which is when I picked up PHP and MySQL. About a year ago was finally when I started picking up on Javascript.</p>
<p>Basically, I learned everything through every resource except taking classes. I would search through the web, read books from the library or just pure trial and error. It wasn&#039;t insanely hard to gather all the information but the only times when I really learn was through projects and experiments. Web development is definitely a hands-on type of thing. Point is, if you want to learn web development you&#039;ll have to spend 30% reading and 70% doing.</p>
<h2>The Program/Software</h2>
<p>Web development can be accomplished through a few languages and most of them don&#039;t require any special software to write. The basic notepad that came with your Windows is capable of completing the task. I prefer to use a software that color codes coding to mitigate headaches. Here&#039;s a list of software that you could choose from.</p>
<ul>
<li><a href="http://notepad-plus-plus.org/" target="_blank">Notepad++ (Free)</a></li>
<li><a href="http://kompozer.net/" target="_blank">KompoZer (Free)</a></li>
<li><a href="http://www.w3.org/Amaya/" target="_blank">Amaya (Free)</a></li>
<li><a href="http://www.seamonkey-project.org/" target="_blank">SeaMonkey (Free)</a></li>
<li><a href="http://www.microsoft.com/expression/" target="_blank">Microsoft Expression Studio ($149)</a></li>
<li><a href="http://www.adobe.com/products/dreamweaver/" target="_blank">Adobe Dreamweaver ($399)</a></li>
</ul>
<p>I personally use Dreamweaver on my computer as I have been using it since I was young so I have a nostalgic feeling to it. When I&#039;m on the go I have notepad++ on my USB.</p>
<h2>Learning HTML</h2>
<p>Before you learn anything else, you have to be really good at HTML (hyper text markup language). The basic of websites all boils down to this language. HTML is the markup language containing markup tags that creates the webpage document. Every website requires HTML to make it work, yes even Flash websites.</p>
<p>Your basic website is wrapped in an opening and closing HTML tag. Opening tags are surrounded by arrow brackets while closing tags are the same but there&#039;s a front slash immediately after the first arrow bracket like such</p>
<div class="dean_ch" style="white-space: wrap;">&lt;html&gt;&lt;/html&gt;</div>
<p>Within the HTML tags there will be a HEAD and BODY tag. The head tags will describe items related to the website but will not be produced in the content. Items such as site title, meta tags, CSS, and Javascripts can be defined in the HEAD tag. The BODY tag will describe content that will be outputted to the user. A code like this:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;html&gt;<br />
&lt;head&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;Test Page&lt;/title&gt;<br />
&lt;/head&gt;</p>
<p>&lt;body&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Hello world!<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div>
<p>Will output &#034;Hello world!&#034; on the browser with the title Test Page in the browser title bar. Once you get this down you&#039;re ready to start building the website. The goal following this is to output the content you wish to show, it could be paragraphed text, images or tables. Everything you wished to use requires a markup tag to make it work. It&#039;ll be redundant for me to give you a tutorial on all the tags but here are two resources that are great.</p>
<ul>
<li><a href="http://www.w3schools.com/html/default.asp" target="_blank">w3school &#8211; HTML</a></li>
<li><a href="http://www.html.net/tutorials/html/" target="_blank">HTML.net</a></li>
</ul>
<p>w3school is great, as they are short writeups but concise so you can digest all of the content quickly. HTML.net is more detailed and a great read too but they incorporate a bit of CSS so its better to read it after w3school to cross-reference some of the ideas and undestanding. Once you&#039;ve got this down you&#039;re ready for some CSS.</p>
<h2>Learning CSS</h2>
<p>CSS (Cascading Style Sheet) is a language that focuses on the style and layout of your markup language. Its a common standard now generate the accurate aesthetic results of many websites. There are a few ways to include CSS in your website.</p>
<div class="dean_ch" style="white-space: wrap;">//Link to a CSS file &#8211; Goes in the &lt;head&gt;&lt;/head&gt; tag<br />
&lt;link href=&quot;css/styles.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</p>
<p>//Have the CSS in the &lt;head&gt;&lt;/head&gt; tag<br />
&lt;style type=&quot;text/css&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; .css { font-weight: bold; }<br />
&lt;/style&gt;</p>
<p>//Inline with content markup tags &#8211; in &lt;body&gt;&lt;/body&gt; tag<br />
&lt;p style=&quot;font-size: 22px;&quot;&gt;this is a paragraph&lt;/p&gt;<br />
&nbsp;</div>
<p>Once you have your website linked with some CSS you can start controlling your website. Here are some example of CSS controlling a webpage.</p>
<div class="dean_ch" style="white-space: wrap;">//All paragraph content will be bold and have a line height of 22 pixels<br />
p { font-weight: bold; line-height: 22px; }</p>
<p>//The following code will modify all markup tags with the class &quot;change&quot; to have a background color of black<br />
.change { background: #000; }</p>
<p>//The following code will modify the element with ID &quot;element_1&quot; to have a background color of white<br />
#element_1 { background: #FFF; }</div>
<p>Here are the resources to read to learn all about CSS.</p>
<ul>
<li><a href="http://www.w3schools.com/css/default.asp" target="_blank">w3school &#8211; CSS</a></li>
<li><a href="http://www.html.net/tutorials/css/" target="_blank">HTML.net</a></li>
</ul>
<p>Again its good to go over the basics with w3school first then head to HTML.net. </p>
<p>At this point you should practice making a few websites with HTML and CSS. Try to envision something and then build it. The best practice is to try to design something in Photoshop then try to build a web site from it. As I always tell developers, just design it and I&#039;ll make it into a template, because I don&#039;t believe there&#039;s many design limitations that can&#039;t be built with HTML and CSS. By doing this exercise it&#039;ll help you learn different methods of building different elements.</p>
<h2>Notes and Reminders</h2>
<p>There are some things you should keep in mind when building with HTML and CSS though.</p>
<h3>Using tables for design</h3>
<p>This is a no and not recommended. A lot of people argue over this topic. Some believe that tables are good for design because its easier to control and it holds the shape of the original design better. The problem is tables are clunky, heavy in coding and not very flexible. Tables have specific standards to them so if you have two rows and two columns, the columns have to be equal width while rows have to be equal height. In order to work around that you&#039;ll have to nest your tables, imagine dealing with that. Its also less flexible for future expansions. You should use a table for tabular data though. Extreme non-table believers will argue that you don&#039;t, they can produce the same effect with other elements. They sure can but when it comes down to the user extracting your data (copying to word or excel), copying for a table is much easier than anything else. It just makes sense.</p>
<h3>Avoid absolute positioning of everything</h3>
<p>Many developers when they start will notice the amount of control with absolute positioning. It is not until their design gets more complicated that it all falls apart. Absolute position provides more flexibility but will sometimes diminish your control, use wisely.</p>
<h3>Test in multiple browsers</h3>
<p>There are various browsers on the web. It sometimes depends on who your website caters to but mind as well cover the major users. Test on desktop machines with Internet Explorer 6, 7, 8, 9, Chrome, Firefox, Safari. On mobile devices with Android, Opera Mini, iOS. Just make sure everything&#039;s consistent. This is a good chance to test how good your skills are too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2010/the-ultimate-newbs-guide-to-learning-web-development-pt-1-the-basic/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>USB for web developer</title>
		<link>http://www.crankberryblog.com/2010/usb-for-web-developer</link>
		<comments>http://www.crankberryblog.com/2010/usb-for-web-developer#comments</comments>
		<pubDate>Fri, 27 Aug 2010 17:43:49 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=394</guid>
		<description><![CDATA[The other day I was working on a friend's machine, and since he didn't have the tools and programs I needed to commence my crazy development, I had to whip out my "stick". My USB stick that is. I plugged it in, and within minutes I was slicing, coding, and uploading. He asked me, "how'd you do that?". All I could reply was, "magic", but in fact you all might know by now, it's not magic. I have kept a USB with me for the last few years that has kept programs for mobile web development work. Today I will share with you the apps I have installed.]]></description>
			<content:encoded><![CDATA[<p>The other day I was working on a friend&#039;s machine, and since he didn&#039;t have the tools and programs I needed to commence my crazy development, I had to whip out my &#034;stick&#034;. My USB stick that is. I plugged it in, and within minutes I was slicing, coding, and uploading. He asked me, &#034;how&#039;d you do that?&#034;. All I could reply was, &#034;magic&#034;, but in fact you all might know by now, it&#039;s not magic. I have kept a USB with me for the last few years that has kept programs for mobile web development work. Today I will share with you the apps I have installed.</p>
<h3>The USB</h3>
<p>Before you can get started you&#039;ll have to get a USB flash drive (if you don&#039;t have one already). For the capacity, you&#039;ll want something 4 GB or more. The apps won&#039;t take up the whole 4 GB but having the extra space will be beneficial. As for the physical size, you&#039;ll want something easy to carry but hard to lose, so find something that you&#039;ll be comfortable carrying around all the time.</p>
<h3>The Setup</h3>
<p>First of all you&#039;ll want the launcher to organize everything on your USB. The launcher is a free software called PortableApps and can be found at: <a href="http://portableapps.com/apps" target="_blank">http://portableapps.com/apps</a>.</p>
<h3>The Apps</h3>
<p>After you have installed the launcher you can get all the apps. Here&#039;s a list of all the apps I used. You can pick and choose as you may have your own preference.</p>
<p><strong>HTML Editor &#8211; Notepad++</strong><br />
<a href="http://portableapps.com/apps/development/notepadpp_portable" target="_blank">http://portableapps.com/apps/development/notepadpp_portable</a><br />
The first and most important thing to have is a HTML editor. I vary between Dreamweaver and Notepad++ on my desktop so using Notepad++ on my USB was no surprise. Its light and has a nice color scheme.</p>
<p><img src="http://www.crankberryblog.com/images/usb-notepad.jpg" alt="USB Notepad++" /></p>
<p><strong>Server &#8211; XAMPP</strong><br />
<a href="http://portableapps.com/apps/development/xampp" target="_blank">http://portableapps.com/apps/development/xampp</a><br />
If you&#039;re coding with a database or using server-side scripting you&#039;ll need a server to do so. I&#039;m used to WAMP but using XAMPP is not bad either. A great portable alternative.</p>
<p><img src="http://www.crankberryblog.com/images/usb-xampp.jpg" alt="USB XAMPP" /></p>
<p><strong>Browser &#8211; FireFox</strong><br />
<a href="http://portableapps.com/news/2010-08-12_-_firefox_portable_4.0_beta_3" target="_blank">http://portableapps.com/news/2010-08-12_-_firefox_portable_4.0_beta_3</a><br />
Should I explain more? This is Firefox, FIREFOX!</p>
<p><img src="http://www.crankberryblog.com/images/usb-firefox.jpg" alt="USB Firefox" /></p>
<p><strong>FTP &#8211; Filezilla</strong><br />
<a href="http://portableapps.com/apps/internet/filezilla_portable" target="_blank">http://portableapps.com/apps/internet/filezilla_portable</a><br />
If you need to FTP your files there&#039;s the great Filezilla. I use Filezilla on my desktop already because its free and easy to use with constant updates. Its pretty much the same for the portable version.</p>
<p><img src="http://www.crankberryblog.com/images/usb-filezilla.jpg" alt="USB Filezilla" /></p>
<p><strong>FTP &#8211; Filezilla</strong><br />
<a href="http://portableapps.com/apps/internet/filezilla_portable" target="_blank">http://portableapps.com/apps/internet/filezilla_portable</a><br />
If you need to FTP your files there&#039;s the great Filezilla. I use Filezilla on my desktop already because its free and easy to use with constant updates. Its pretty much the same for the portable version.</p>
<p><img src="http://www.crankberryblog.com/images/usb-filezilla.jpg" alt="USB Filezilla" /></p>
<p><strong>Graphic &#8211; GIMP</strong><br />
<a href="http://portableapps.com/apps/graphics_pictures/gimp_portable" target="_blank">http://portableapps.com/apps/graphics_pictures/gimp_portable</a><br />
Working from graphics to coding cannot be easier with the great Photoshop alternative, GIMP!</p>
<p><img src="http://www.crankberryblog.com/images/usb-gimp.jpg" alt="USB GIMP" /></p>
<h3>Optional Apps</h3>
<p><strong>Compression &#8211; 7 ZIP</strong><br />
<a href="http://portableapps.com/apps/utilities/7-zip_portable" target="_blank">http://portableapps.com/apps/utilities/7-zip_portable</a><br />
Zip and unzip files with ease on the go.</p>
<p><img src="http://www.crankberryblog.com/images/usb-7zip.jpg" alt="USB 7zip" /></p>
<p><strong>Tablet &#8211; On Screen Keyboard</strong><br />
<a href="http://portableapps.com/apps/accessibility/on-screen_keyboard_portable" target="_blank">http://portableapps.com/apps/accessibility/on-screen_keyboard_portable</a><br />
If you&#039;re working on a tablet machine that doesn&#039;t have a native on screen keyboard, this is the right tool for you.</p>
<p><img src="http://www.crankberryblog.com/images/usb-keyboard.jpg" alt="USB Keyboard" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2010/usb-for-web-developer/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
