<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.linuxquestions.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cubal</id>
	<title>LQWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.linuxquestions.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cubal"/>
	<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/wiki/Special:Contributions/Cubal"/>
	<updated>2026-04-11T19:55:01Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.0</generator>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=4175</id>
		<title>Php tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=4175"/>
		<updated>2004-03-11T11:13:34Z</updated>

		<summary type="html">&lt;p&gt;Cubal: fixed url&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==PHP TIPS==&lt;br /&gt;
[[PHP]] Hypertext Preprocessor is a great tool for making dynamic websites. Outside this Wiki, countless tips can be found in the comments section of the [http://www.php.net/manual/en/ official php manual] in the reference pages for each function. Here's a few little PHP tips and tricks.&lt;br /&gt;
&lt;br /&gt;
=== Making your first cut'n paste script work ===&lt;br /&gt;
The first thing people usually do when the experiment with php, is that they get a piece of php script from the web and try to use it. So here's how to make that first piece of code to work:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change the [[file permissions]] so that your [[webserver]] can use it.&lt;br /&gt;
* Make sure that the php-code starts with ''&amp;lt;?php'', because sometimes just the basic ''&amp;lt;?'' doesn't work (or at least in my configuration)&lt;br /&gt;
* Make sure that the file extension is .php, not .php3, .php4 or .phtml. A lot of these old filenames won't work with modern [[apache]] web servers.&lt;br /&gt;
&lt;br /&gt;
=== Creating larger pages with $variables ===&lt;br /&gt;
The first few pages work well by just by putting the code where you needed in the HTML-page. However,when your scripts grow bigger, it gets messy when you mix php and html.&lt;br /&gt;
I my opinion, the easiest way is to put the PHP-code code at the beginning of the file and the HTML in the end. &lt;br /&gt;
&lt;br /&gt;
The data that your great script has generated should be placed in string-type variables. For example: ''$pagetop'', ''$list'', ''$pageend'' and ''$menu''. &lt;br /&gt;
So now you can put all the generated data to those variables and use them in the HTML-part of you file by just putting ''&amp;lt;?php echo $pagetop; ?&amp;gt;'' in the according place.&lt;br /&gt;
&lt;br /&gt;
By doing this you can easily edit the PHP-scipt and the HTML part of your page without mixing the two so badly that you don't understand anything the next week .&lt;br /&gt;
&lt;br /&gt;
===FANCY TABLES===&lt;br /&gt;
It is easy -- and it also looks really cool 8) -- to generate a table with alternating coloured rows from PHP.  What you have to do is&lt;br /&gt;
#Declare a CSS style class for each background colour.&lt;br /&gt;
#Create an array with the background colours in the order you want them to appear in the table.&lt;br /&gt;
#Place some code in the loop which generates the table, to set a background colour for each row while recirculating the array.&lt;br /&gt;
The following code snippets should make it clear.&lt;br /&gt;
====Defining CSS Classes  (outside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;.DARKBG   {background-color: #bbbbbb}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.MIDDLEBG {background-color: #cccccc}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.LIGHTBG  {background-color: #dddddd}&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Initialising the array  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;$backgrounds = array(&amp;quot;LIGHTBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;, &amp;quot;DARKBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;);&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Building up the table  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;foreach ($foo as $i =&amp;gt; $j) {&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;array_push($backgrounds, ($bg = array_shift($backgrounds));&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;echo &amp;quot;&amp;amp;lt;TR CLASS=\&amp;quot;$bg\&amp;quot;&amp;amp;gt;&amp;quot;;&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;TD&amp;amp;gt;$i&amp;amp;lt;/TD&amp;amp;gt;&amp;amp;lt;TD&amp;amp;gt;$j&amp;amp;lt;/TD&amp;amp;gt;&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;/TR&amp;amp;gt;\n&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;};&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Explanation====&lt;br /&gt;
Each time around the loop  (here I've used a &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt; but it could be any kind of loop), the &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; (in the innermost brackets, so it gets evaluated first) causes a variable $bg to be set to the first element in $backgrounds and the others to be shifted down a place.  Then, this is pushed onto the tail end of the shortened array by the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt;.  So the whole array just gets recirculated, each time a value is read from the beginning it is moved to the end.  As the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; functions do not care about the length of the array, you could go through a whole rainbow of colours, or you could just alternate white and coloured rows.&lt;br /&gt;
&lt;br /&gt;
Note that if you want to use more than one table in your page, and you want them all to start on the same colour, you will have to re-create the array between finishing one table and starting the next.  This is because the array actually gets altered each time we go around the loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Configuration Tricks and Traps===&lt;br /&gt;
&lt;br /&gt;
Here are some common pitfalls or trickies. Also, go take a look at [http://wact.sourceforge.net/index.php/PhpApplicationSecurity this] for a more comprehensive look at security issues in PHP.&lt;br /&gt;
&lt;br /&gt;
====The &amp;lt;tt&amp;gt;register_globals&amp;lt;/tt&amp;gt; flag (a php.ini config option)====&lt;br /&gt;
&lt;br /&gt;
If set to true, all GET, POST, FILE, and COOKIE variables will be registered as global variables. That is, if you called the url &amp;lt;tt&amp;gt;index.php?page=home&amp;lt;/tt&amp;gt; the script would have the variable &amp;lt;tt&amp;gt;$page&amp;lt;/tt&amp;gt; available, with the value 'home'. However, with register_globals off (the way it should really be, for security) &amp;lt;tt&amp;gt;$page&amp;lt;/tt&amp;gt; would not be available. Instead, you would use &amp;lt;tt&amp;gt;$_GET['page']&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;$HTTP_GET_VARS['page']&amp;lt;/tt&amp;gt; (the first for any version of php beyond about 4.1; the second for older versions).&lt;br /&gt;
&lt;br /&gt;
====The &amp;lt;tt&amp;gt;allow_short_open_tags&amp;lt;/tt&amp;gt; option====&lt;br /&gt;
&lt;br /&gt;
If set to true, &amp;lt;tt&amp;gt;&amp;lt;?&amp;lt;/tt&amp;gt; is a legitimate way of starting a php block. This also means that you can use the short echo syntax: &amp;lt;tt&amp;gt;&amp;lt;?=$var ?&amp;gt;&amp;lt;/tt&amp;gt; will output the value of $var.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the shorts tags are a bad idea if:&lt;br /&gt;
* You are mixing scripting languages. Different languages use different tags, but often use the &amp;lt;? prefix.&lt;br /&gt;
* You have xml content. PHP will choke on the &amp;lt;?xml declaration if you are allowing the short tags; it reads it as a php command &amp;quot;xml&amp;quot;, which of course doesn't work, so spews a parse error.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=4022</id>
		<title>Php tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=4022"/>
		<updated>2004-03-11T11:08:01Z</updated>

		<summary type="html">&lt;p&gt;Cubal: Added link to wact php security page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==PHP TIPS==&lt;br /&gt;
[[PHP]] Hypertext Preprocessor is a great tool for making dynamic websites. Outside this Wiki, countless tips can be found in the comments section of the [http://www.php.net/manual/en/ official php manual] in the reference pages for each function. Here's a few little PHP tips and tricks.&lt;br /&gt;
&lt;br /&gt;
=== Making your first cut'n paste script work ===&lt;br /&gt;
The first thing people usually do when the experiment with php, is that they get a piece of php script from the web and try to use it. So here's how to make that first piece of code to work:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change the [[file permissions]] so that your [[webserver]] can use it.&lt;br /&gt;
* Make sure that the php-code starts with ''&amp;lt;?php'', because sometimes just the basic ''&amp;lt;?'' doesn't work (or at least in my configuration)&lt;br /&gt;
* Make sure that the file extension is .php, not .php3, .php4 or .phtml. A lot of these old filenames won't work with modern [[apache]] web servers.&lt;br /&gt;
&lt;br /&gt;
=== Creating larger pages with $variables ===&lt;br /&gt;
The first few pages work well by just by putting the code where you needed in the HTML-page. However,when your scripts grow bigger, it gets messy when you mix php and html.&lt;br /&gt;
I my opinion, the easiest way is to put the PHP-code code at the beginning of the file and the HTML in the end. &lt;br /&gt;
&lt;br /&gt;
The data that your great script has generated should be placed in string-type variables. For example: ''$pagetop'', ''$list'', ''$pageend'' and ''$menu''. &lt;br /&gt;
So now you can put all the generated data to those variables and use them in the HTML-part of you file by just putting ''&amp;lt;?php echo $pagetop; ?&amp;gt;'' in the according place.&lt;br /&gt;
&lt;br /&gt;
By doing this you can easily edit the PHP-scipt and the HTML part of your page without mixing the two so badly that you don't understand anything the next week .&lt;br /&gt;
&lt;br /&gt;
===FANCY TABLES===&lt;br /&gt;
It is easy -- and it also looks really cool 8) -- to generate a table with alternating coloured rows from PHP.  What you have to do is&lt;br /&gt;
#Declare a CSS style class for each background colour.&lt;br /&gt;
#Create an array with the background colours in the order you want them to appear in the table.&lt;br /&gt;
#Place some code in the loop which generates the table, to set a background colour for each row while recirculating the array.&lt;br /&gt;
The following code snippets should make it clear.&lt;br /&gt;
====Defining CSS Classes  (outside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;.DARKBG   {background-color: #bbbbbb}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.MIDDLEBG {background-color: #cccccc}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.LIGHTBG  {background-color: #dddddd}&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Initialising the array  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;$backgrounds = array(&amp;quot;LIGHTBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;, &amp;quot;DARKBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;);&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Building up the table  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;foreach ($foo as $i =&amp;gt; $j) {&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;array_push($backgrounds, ($bg = array_shift($backgrounds));&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;echo &amp;quot;&amp;amp;lt;TR CLASS=\&amp;quot;$bg\&amp;quot;&amp;amp;gt;&amp;quot;;&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;TD&amp;amp;gt;$i&amp;amp;lt;/TD&amp;amp;gt;&amp;amp;lt;TD&amp;amp;gt;$j&amp;amp;lt;/TD&amp;amp;gt;&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;/TR&amp;amp;gt;\n&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;};&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Explanation====&lt;br /&gt;
Each time around the loop  (here I've used a &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt; but it could be any kind of loop), the &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; (in the innermost brackets, so it gets evaluated first) causes a variable $bg to be set to the first element in $backgrounds and the others to be shifted down a place.  Then, this is pushed onto the tail end of the shortened array by the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt;.  So the whole array just gets recirculated, each time a value is read from the beginning it is moved to the end.  As the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; functions do not care about the length of the array, you could go through a whole rainbow of colours, or you could just alternate white and coloured rows.&lt;br /&gt;
&lt;br /&gt;
Note that if you want to use more than one table in your page, and you want them all to start on the same colour, you will have to re-create the array between finishing one table and starting the next.  This is because the array actually gets altered each time we go around the loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Configuration Tricks and Traps===&lt;br /&gt;
&lt;br /&gt;
Here are some common pitfalls or trickies. Also, go take a look at http://wact.sourceforge.net/index.php/PhpApplicationSecurity for a more comprehensive look at security issues in PHP.&lt;br /&gt;
&lt;br /&gt;
====The &amp;lt;tt&amp;gt;register_globals&amp;lt;/tt&amp;gt; flag (a php.ini config option)====&lt;br /&gt;
&lt;br /&gt;
If set to true, all GET, POST, FILE, and COOKIE variables will be registered as global variables. That is, if you called the url &amp;lt;tt&amp;gt;index.php?page=home&amp;lt;/tt&amp;gt; the script would have the variable &amp;lt;tt&amp;gt;$page&amp;lt;/tt&amp;gt; available, with the value 'home'. However, with register_globals off (the way it should really be, for security) &amp;lt;tt&amp;gt;$page&amp;lt;/tt&amp;gt; would not be available. Instead, you would use &amp;lt;tt&amp;gt;$_GET['page']&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;$HTTP_GET_VARS['page']&amp;lt;/tt&amp;gt; (the first for any version of php beyond about 4.1; the second for older versions).&lt;br /&gt;
&lt;br /&gt;
====The &amp;lt;tt&amp;gt;allow_short_open_tags&amp;lt;/tt&amp;gt; option====&lt;br /&gt;
&lt;br /&gt;
If set to true, &amp;lt;tt&amp;gt;&amp;lt;?&amp;lt;/tt&amp;gt; is a legitimate way of starting a php block. This also means that you can use the short echo syntax: &amp;lt;tt&amp;gt;&amp;lt;?=$var ?&amp;gt;&amp;lt;/tt&amp;gt; will output the value of $var.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the shorts tags are a bad idea if:&lt;br /&gt;
* You are mixing scripting languages. Different languages use different tags, but often use the &amp;lt;? prefix.&lt;br /&gt;
* You have xml content. PHP will choke on the &amp;lt;?xml declaration if you are allowing the short tags; it reads it as a php command &amp;quot;xml&amp;quot;, which of course doesn't work, so spews a parse error.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=User:Cubal&amp;diff=22162</id>
		<title>User:Cubal</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=User:Cubal&amp;diff=22162"/>
		<updated>2004-03-06T04:29:48Z</updated>

		<summary type="html">&lt;p&gt;Cubal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Howdy all!&lt;br /&gt;
&lt;br /&gt;
Distros:&lt;br /&gt;
* [[Red_Hat]]. I run Red Hat; for sheer ease-of-use it takes a lot of beating, but it still lets you do a decent amount of config, and runs nice on my Celeron 400.&lt;br /&gt;
* [[Linux_From_Scratch]] (LFS). I built my own Linux From Scratch system when I was gonna put an mp3-playing computer in my car (car stereo prices dropped - it wasn't worth the time). It was fun - you compile everything from scratch, write your own config files, and if you get it right it works :). I wouldn't recommend it for anything beyond seriously custom boxes or an educational opportunity.&lt;br /&gt;
* [[Debian]]. Very limited experience; I tried installing it on a server at work. I needed [[Subversion]] running for version control; and unfortunately Debian doesn't mix very well. That is, I had Debian Stable, Subversion was in unstable, and you would not believe the hassle it took. I blitzed it and installed Red Hat - not quite as rock-solid, but at least I could compile the software I needed.&lt;br /&gt;
&lt;br /&gt;
:(Ok, that's kinda harsh on Debian; it can be a brilliant system. If you need rock-solid stability with easy maintenance, and don't really need any custom software, it's excellent.)&lt;br /&gt;
&lt;br /&gt;
*[[Knoppix]]. Live CDs rock! Just drop it in and boot up. [[Gentoo]] also does a Live CD distro, but Knoppix seems easier to use - mainly as it comes with a full [[KDE]] gui, rather than Gentoo's OpenBox.&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
* Mac OS X. Yeah, I know. It's not Linux. But my main machine is a Powerbook, and it takes some beating. Having said that though, some days I just feel like using my linux box. There's something to be said for the almost infinite level of customisation possible in GNU/Linux.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Source_distributions&amp;diff=1717</id>
		<title>Source distributions</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Source_distributions&amp;diff=1717"/>
		<updated>2004-03-06T04:23:53Z</updated>

		<summary type="html">&lt;p&gt;Cubal: added lfs, slackware&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;----&lt;br /&gt;
&lt;br /&gt;
'''Description:'''&lt;br /&gt;
&lt;br /&gt;
Source based distributions enable the more experienced user to have a considerable degree of control over their system. Compiling and optimizing software for your particular hardware can bring noticeable performance improvements - however, compiling software can be a lengthy process. &lt;br /&gt;
&lt;br /&gt;
For more information on the various Source based distributions, click on the links below.&lt;br /&gt;
&lt;br /&gt;
''This article is a [[LinuxQuestions.org_Wiki:stub_articles|stub]] and needs to be finished. [[LinuxQuestions.org_Wiki:plunging_forward|Plunge forward]] and [[LinuxQuestions.org_Wiki:How_to_edit_a_page|help it grow]] !''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''Links:'''&lt;br /&gt;
&lt;br /&gt;
*[[Gentoo]]&lt;br /&gt;
*[[Source_Mage]]&lt;br /&gt;
*[[Linux_From_Scratch]]&lt;br /&gt;
*[[Slackware]]&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=User:Cubal&amp;diff=1701</id>
		<title>User:Cubal</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=User:Cubal&amp;diff=1701"/>
		<updated>2004-03-06T04:22:14Z</updated>

		<summary type="html">&lt;p&gt;Cubal: my user page :) info on my used distros&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Howdy all!&lt;br /&gt;
&lt;br /&gt;
Distros:&lt;br /&gt;
* [[Red_Hat]]. I run Red Hat; for sheer ease-of-use it takes a lot of beating, but it still lets you do a decent amount of config, and runs nice on my Celeron 400.&lt;br /&gt;
* [[Linux_From_Scratch]] (LFS). I built my own Linux From Scratch system when I was gonna put an mp3-playing computer in my car (car stereo prices dropped - it wasn't worth the time). It was fun - you compile everything from scratch, write your own config files, and if you get it right it works :). I wouldn't recommend it for anything beyond seriously custom boxes or an educational opportunity.&lt;br /&gt;
* [[Debian]]. Very limited experience; I tried installing it on a server at work. I needed [[Subversion]] running for version control; and unfortunately Debian doesn't mix very well. That is, I had Debian Stable, Subversion was in unstable, and you would not believe the hassle it took. I blitzed it and installed Red Hat - not quite as rock-solid, but at least I could compile the software I needed.&lt;br /&gt;
&lt;br /&gt;
(Ok, that's kinda harsh on Debian; it can be a brilliant system. If you need rock-solid stability with easy maintenance, and don't really need any custom software, it's excellent.)&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
* Mac OS X. Yeah, I know. It's not Linux. But my main machine is a Powerbook, and it takes some beating. Having said that though, some days I just feel like using my linux box. There's something to be said for the almost infinite level of customisation possible in GNU/Linux.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=2003</id>
		<title>Php tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=2003"/>
		<updated>2004-03-06T04:07:30Z</updated>

		<summary type="html">&lt;p&gt;Cubal: added &amp;quot;config tips and tricks&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==PHP TIPS==&lt;br /&gt;
[[PHP]] Hypertext Preprocessor is a great tool for making dynamic websites. Outside this Wiki, countless tips can be found in the comments section of the [http://www.php.net/manual/en/ official php manual] in the reference pages for each function. Here's a few little PHP tips and tricks.&lt;br /&gt;
&lt;br /&gt;
=== Making your first cut'n paste script work ===&lt;br /&gt;
The first thing people usually do when the experiment with php, is that they get a piece of php script from the web and try to use it. So here's how to make that first piece of code to work:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change the [[file permissions]] so that your [[webserver]] can use it.&lt;br /&gt;
* Make sure that the php-code starts with ''&amp;lt;?php'', because sometimes just the basic ''&amp;lt;?'' doesn't work (or at least in my configuration)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating larger pages with $variables ===&lt;br /&gt;
The first few pages work well by just by putting the code where you needed in the HTML-page, but when your scrips grow bigger, it gets messy when you have some php here and html there.&lt;br /&gt;
I my opinion, the easiest way is to put the PHP-code code at the beginning of the file and the HTML in the end. &lt;br /&gt;
&lt;br /&gt;
The data that your great script has generated should be placed in string-type variables. For example: ''$pagetop'', ''$list'', ''$pageend'' and ''$menu''. &lt;br /&gt;
So now you can put all the generated data to those variables and use them in the HTML-part of you file by just putting ''&amp;lt;?php echo $pagetop; ?&amp;gt;'' in the according place.&lt;br /&gt;
&lt;br /&gt;
By doing this you can easily edit the PHP-scipt and the HTML part of your page without mixing the two so badly that you don't understand anything the next week .&lt;br /&gt;
&lt;br /&gt;
===FANCY TABLES===&lt;br /&gt;
It is easy -- and it also looks really cool 8) -- to generate a table with alternating coloured rows from PHP.  What you have to do is&lt;br /&gt;
#Declare a CSS style class for each background colour.&lt;br /&gt;
#Create an array with the background colours in the order you want them to appear in the table.&lt;br /&gt;
#Place some code in the loop which generates the table, to set a background colour for each row while recirculating the array.&lt;br /&gt;
The following code snippets should make it clear.&lt;br /&gt;
====Defining CSS Classes  (outside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;.DARKBG   {background-color: #bbbbbb}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.MIDDLEBG {background-color: #cccccc}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.LIGHTBG  {background-color: #dddddd}&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Initialising the array  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;$backgrounds = array(&amp;quot;LIGHTBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;, &amp;quot;DARKBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;);&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Building up the table  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;foreach ($foo as $i =&amp;gt; $j) {&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;array_push($backgrounds, ($bg = array_shift($backgrounds));&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;echo &amp;quot;&amp;amp;lt;TR CLASS=\&amp;quot;$bg\&amp;quot;&amp;amp;gt;&amp;quot;;&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;TD&amp;amp;gt;$i&amp;amp;lt;/TD&amp;amp;gt;&amp;amp;lt;TD&amp;amp;gt;$j&amp;amp;lt;/TD&amp;amp;gt;&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;/TR&amp;amp;gt;\n&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;};&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Explanation====&lt;br /&gt;
Each time around the loop  (here I've used a &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt; but it could be any kind of loop), the &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; (in the innermost brackets, so it gets evaluated first) causes a variable $bg to be set to the first element in $backgrounds and the others to be shifted down a place.  Then, this is pushed onto the tail end of the shortened array by the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt;.  So the whole array just gets recirculated, each time a value is read from the beginning it is moved to the end.  As the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; functions do not care about the length of the array, you could go through a whole rainbow of colours, or you could just alternate white and coloured rows.&lt;br /&gt;
&lt;br /&gt;
Note that if you want to use more than one table in your page, and you want them all to start on the same colour, you will have to re-create the array between finishing one table and starting the next.  This is because the array actually gets altered each time we go around the loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Configuration Tricks and Traps===&lt;br /&gt;
&lt;br /&gt;
Here are some common pitfalls or trickies.&lt;br /&gt;
&lt;br /&gt;
====The &amp;lt;tt&amp;gt;register_globals&amp;lt;/tt&amp;gt; flag (a php.ini config option)====&lt;br /&gt;
&lt;br /&gt;
If set to true, all GET, POST, FILE, and COOKIE variables will be registered as global variables. That is, if you called the url &amp;lt;tt&amp;gt;index.php?page=home&amp;lt;/tt&amp;gt; the script would have the variable &amp;lt;tt&amp;gt;$page&amp;lt;/tt&amp;gt; available, with the value 'home'. However, with register_globals off (the way it should really be, for security) &amp;lt;tt&amp;gt;$home&amp;lt;/tt&amp;gt; would not be available. Instead, you would use &amp;lt;tt&amp;gt;$_GET['home']&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;$HTTP_GET_VARS['home']&amp;lt;/tt&amp;gt; (the first for any version of php beyond about 4.1; the second for older versions).&lt;br /&gt;
&lt;br /&gt;
====The &amp;lt;tt&amp;gt;allow_short_open_tags&amp;lt;/tt&amp;gt; option====&lt;br /&gt;
&lt;br /&gt;
If set to true, &amp;lt;tt&amp;gt;&amp;lt;?&amp;lt;/tt&amp;gt; is a legitimate way of starting a php block. This also means that you can use the short echo syntax: &amp;lt;tt&amp;gt;&amp;lt;?=$var ?&amp;gt;&amp;lt;/tt&amp;gt; will output the value of $var.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the shorts tags are a bad idea if:&lt;br /&gt;
* You are mixing scripting languages. Different languages use different tags, but often use the &amp;lt;? prefix.&lt;br /&gt;
* You have xml content. PHP will choke on the &amp;lt;?xml declaration if you are allowing the short tags; it reads it as a php command &amp;quot;xml&amp;quot;, which of course doesn't work, so spews a parse error.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=1671</id>
		<title>Php tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=1671"/>
		<updated>2004-03-06T04:00:10Z</updated>

		<summary type="html">&lt;p&gt;Cubal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==PHP TIPS==&lt;br /&gt;
[[PHP]] Hypertext Preprocessor is a great tool for making dynamic websites. Outside this Wiki, countless tips can be found in the comments section of the [http://www.php.net/manual/en/ official php manual] in the reference pages for each function. Here's a few little PHP tips and tricks.&lt;br /&gt;
&lt;br /&gt;
=== Making your first cut'n paste script work ===&lt;br /&gt;
The first thing people usually do when the experiment with php, is that they get a piece of php script from the web and try to use it. So here's how to make that first piece of code to work:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change the [[file permissions]] so that your [[webserver]] can use it.&lt;br /&gt;
* Make sure that the php-code starts with ''&amp;lt;?php'', because sometimes just the basic ''&amp;lt;?'' doesn't work (or at least in my configuration)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating larger pages with $variables ===&lt;br /&gt;
The first few pages work well by just by putting the code where you needed in the HTML-page, but when your scrips grow bigger, it gets messy when you have some php here and html there.&lt;br /&gt;
I my opinion, the easiest way is to put the PHP-code code at the beginning of the file and the HTML in the end. &lt;br /&gt;
&lt;br /&gt;
The data that your great script has generated should be placed in string-type variables. For example: ''$pagetop'', ''$list'', ''$pageend'' and ''$menu''. &lt;br /&gt;
So now you can put all the generated data to those variables and use them in the HTML-part of you file by just putting ''&amp;lt;?php echo $pagetop; ?&amp;gt;'' in the according place.&lt;br /&gt;
&lt;br /&gt;
By doing this you can easily edit the PHP-scipt and the HTML part of your page without mixing the two so badly that you don't understand anything the next week .&lt;br /&gt;
&lt;br /&gt;
===FANCY TABLES===&lt;br /&gt;
It is easy -- and it also looks really cool 8) -- to generate a table with alternating coloured rows from PHP.  What you have to do is&lt;br /&gt;
#Declare a CSS style class for each background colour.&lt;br /&gt;
#Create an array with the background colours in the order you want them to appear in the table.&lt;br /&gt;
#Place some code in the loop which generates the table, to set a background colour for each row while recirculating the array.&lt;br /&gt;
The following code snippets should make it clear.&lt;br /&gt;
====Defining CSS Classes  (outside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;.DARKBG   {background-color: #bbbbbb}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.MIDDLEBG {background-color: #cccccc}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.LIGHTBG  {background-color: #dddddd}&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Initialising the array  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;$backgrounds = array(&amp;quot;LIGHTBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;, &amp;quot;DARKBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;);&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Building up the table  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;foreach ($foo as $i =&amp;gt; $j) {&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;array_push($backgrounds, ($bg = array_shift($backgrounds));&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;echo &amp;quot;&amp;amp;lt;TR CLASS=\&amp;quot;$bg\&amp;quot;&amp;amp;gt;&amp;quot;;&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;TD&amp;amp;gt;$i&amp;amp;lt;/TD&amp;amp;gt;&amp;amp;lt;TD&amp;amp;gt;$j&amp;amp;lt;/TD&amp;amp;gt;&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;/TR&amp;amp;gt;\n&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;};&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Explanation====&lt;br /&gt;
Each time around the loop  (here I've used a &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt; but it could be any kind of loop), the &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; (in the innermost brackets, so it gets evaluated first) causes a variable $bg to be set to the first element in $backgrounds and the others to be shifted down a place.  Then, this is pushed onto the tail end of the shortened array by the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt;.  So the whole array just gets recirculated, each time a value is read from the beginning it is moved to the end.  As the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; functions do not care about the length of the array, you could go through a whole rainbow of colours, or you could just alternate white and coloured rows.&lt;br /&gt;
&lt;br /&gt;
Note that if you want to use more than one table in your page, and you want them all to start on the same colour, you will have to re-create the array between finishing one table and starting the next.  This is because the array actually gets altered each time we go around the loop.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=1660</id>
		<title>Php tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Php_tips&amp;diff=1660"/>
		<updated>2004-03-06T03:59:24Z</updated>

		<summary type="html">&lt;p&gt;Cubal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Configuration Tricks and Traps===&lt;br /&gt;
&lt;br /&gt;
==PHP TIPS==&lt;br /&gt;
[[PHP]] Hypertext Preprocessor is a great tool for making dynamic websites. Outside this Wiki, countless tips can be found in the comments section of the [http://www.php.net/manual/en/ official php manual] in the reference pages for each function. Here's a few little PHP tips and tricks.&lt;br /&gt;
&lt;br /&gt;
=== Making your first cut'n paste script work ===&lt;br /&gt;
The first thing people usually do when the experiment with php, is that they get a piece of php script from the web and try to use it. So here's how to make that first piece of code to work:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change the [[file permissions]] so that your [[webserver]] can use it.&lt;br /&gt;
* Make sure that the php-code starts with ''&amp;lt;?php'', because sometimes just the basic ''&amp;lt;?'' doesn't work (or at least in my configuration)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating larger pages with $variables ===&lt;br /&gt;
The first few pages work well by just by putting the code where you needed in the HTML-page, but when your scrips grow bigger, it gets messy when you have some php here and html there.&lt;br /&gt;
I my opinion, the easiest way is to put the PHP-code code at the beginning of the file and the HTML in the end. &lt;br /&gt;
&lt;br /&gt;
The data that your great script has generated should be placed in string-type variables. For example: ''$pagetop'', ''$list'', ''$pageend'' and ''$menu''. &lt;br /&gt;
So now you can put all the generated data to those variables and use them in the HTML-part of you file by just putting ''&amp;lt;?php echo $pagetop; ?&amp;gt;'' in the according place.&lt;br /&gt;
&lt;br /&gt;
By doing this you can easily edit the PHP-scipt and the HTML part of your page without mixing the two so badly that you don't understand anything the next week .&lt;br /&gt;
&lt;br /&gt;
===FANCY TABLES===&lt;br /&gt;
It is easy -- and it also looks really cool 8) -- to generate a table with alternating coloured rows from PHP.  What you have to do is&lt;br /&gt;
#Declare a CSS style class for each background colour.&lt;br /&gt;
#Create an array with the background colours in the order you want them to appear in the table.&lt;br /&gt;
#Place some code in the loop which generates the table, to set a background colour for each row while recirculating the array.&lt;br /&gt;
The following code snippets should make it clear.&lt;br /&gt;
====Defining CSS Classes  (outside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;.DARKBG   {background-color: #bbbbbb}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.MIDDLEBG {background-color: #cccccc}&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;.LIGHTBG  {background-color: #dddddd}&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Initialising the array  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;$backgrounds = array(&amp;quot;LIGHTBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;, &amp;quot;DARKBG&amp;quot;, &amp;quot;MIDDLEBG&amp;quot;);&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Building up the table  (inside &amp;amp;lt;? ?&amp;amp;gt;)====&lt;br /&gt;
:&amp;lt;tt&amp;gt;foreach ($foo as $i =&amp;gt; $j) {&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;array_push($backgrounds, ($bg = array_shift($backgrounds));&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;&amp;lt;strong&amp;gt;echo &amp;quot;&amp;amp;lt;TR CLASS=\&amp;quot;$bg\&amp;quot;&amp;amp;gt;&amp;quot;;&amp;lt;/strong&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;TD&amp;amp;gt;$i&amp;amp;lt;/TD&amp;amp;gt;&amp;amp;lt;TD&amp;amp;gt;$j&amp;amp;lt;/TD&amp;amp;gt;&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
::&amp;lt;tt&amp;gt;echo &amp;quot;&amp;amp;lt;/TR&amp;amp;gt;\n&amp;quot;;&amp;lt;/tt&amp;gt;&lt;br /&gt;
:&amp;lt;tt&amp;gt;};&amp;lt;/tt&amp;gt;&lt;br /&gt;
====Explanation====&lt;br /&gt;
Each time around the loop  (here I've used a &amp;lt;tt&amp;gt;foreach&amp;lt;/tt&amp;gt; but it could be any kind of loop), the &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; (in the innermost brackets, so it gets evaluated first) causes a variable $bg to be set to the first element in $backgrounds and the others to be shifted down a place.  Then, this is pushed onto the tail end of the shortened array by the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt;.  So the whole array just gets recirculated, each time a value is read from the beginning it is moved to the end.  As the &amp;lt;tt&amp;gt;array_push&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;array_shift&amp;lt;/tt&amp;gt; functions do not care about the length of the array, you could go through a whole rainbow of colours, or you could just alternate white and coloured rows.&lt;br /&gt;
&lt;br /&gt;
Note that if you want to use more than one table in your page, and you want them all to start on the same colour, you will have to re-create the array between finishing one table and starting the next.  This is because the array actually gets altered each time we go around the loop.&lt;/div&gt;</summary>
		<author><name>Cubal</name></author>
	</entry>
</feed>