This is the third part of our Gentoo tutorials. In the first two parts we have installed Gentoo from the minimal installation disc and added some interesting applications and utilities.
In this third part we will install an apache webserver with several different php versions. I will use php4 and php5, however this guide can be used for php5 and php6 (as soon as there is at least a release candidate version) or even it can be used to install multiple different php5 versions - it all depends on your needs.
If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)

This one puzzled me for some time… may be I’ve overlooked the php documentation, but I couldn’t find how to make use of the standard checkbox and return the selected values as an array from a simple form.
In the end, it turned to be easy. Consider that we have the following form:
<html>
<form action=’somewhere.php’ name=’form1′ action=’POST’>
John <input type=’checkbox’ name=’user’ value=’john’><br>
Sam <input type=’checkbox’ name=’user’ value=’sam’><br>
Marry <input type=’checkbox’ name=’user’ value=’marry’><br>
<input type=’submit’ value=’Delete User’>
You might expect that by submitting this form to the somewhere.php script, the POST variable would be user and the values would be stored in an array. That’s however not happening because what the browser is doing is sending the following as POST (I used FireFox and LiveHeaders plugin to track that down):
user=john, user=’sam’, user=’marry’ …
Great! That looks great and I would too expect to see an array, but that’s not what happens actually. Once submitted the above form will just pass: user=’marry’ and nothing else, regardless if you have checked Sam and John or not. It seems that each time user is set it overrides the previous information.
A quick glance at the php arrays and we have a solution. PHP as well as other languages uses special brackets ([] <- those one) to indicate that a variable is an array. So to achieve our goal we just need to rename the initial form variable from user to user[]. Just like that:
<input type=’checkbox’ name=’user[]‘ value=’john’>
… same for other users ….
If you submit the form now, you will see only one variable in the $_POST array called $user which is actually an array containing the selected users.
Nothing fancy, but as I said in the beginning it puzzled me for some time.
If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)

In Perl, the chop function removes the last character in a string, but in PHP it removes trailing white spaces only. To get the same functionality into PHP you can use the substr_replace() function. For example:
$string = substr_replace($string,”",-1);
will remove the last character of $string. You can play with it and replace the last character with empty space if you need such a functionality in your script.
Since most of the visits on this page had the ‘Remove last character bash’ search engine keyword, I figured that people might need that section as well, so here it is. To remove the last character from a string/file using bash scripting you need to use the echo option and ‘pipe’ it to the variable itself. For example:
var=”My String with an additional a at the end. a”
var=$(echo ${var%\a})
Now, if you do echo $var you will see that it will display “My String with an additional a at the end.” without the additional a at the end
If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)

In some cases, you might want to get the current URL of the script that is being executed. I haven’t yet found a convenient one-line function that is built-in into PHP and thus I’ve wrote the following function to do it:
/**
* Returns the current URL of the script.
* Usage: $url = cur_page_url();
*
* @access public
* @param none
* @return string
*
*/
function cur_page_url(){
$url = 'http';
if ($_SERVER["HTTPS"] == “on”) {$url .= “s”;}
$url .= "://";
if ($_SERVER["SERVER_PORT"] != “80″) {
$url .= $_SERVER["SERVER_NAME"]. “:”. $_SERVER["SERVER_PORT"]. $_SERVER["REQUEST_URI"];
} else {
$url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $url;
}
Copy and paste the above function in your php script and when you need to get the current page, simply call it just like that:
$url = cur_page_url();
That’s all
Pretty much simple.
If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)

Apache provides basic user authentication mechanism based on usernames and passwords. The easiestt way to manipulate them is to use a tool called ‘htpasswd’ from the command line interface. Various tools such as control panels use the same tool only that they provide a GUI interface.
This is a short summary how to manipulate users and passwords with ‘htpasswd’:
If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)

Or some essential tips to learn and have fun with classmates and friends.
Have you ever thought to make a website that would help your classmates and professors keep track of lectures, homework and curriculum activities? If this sounds boring to you let me explain how to turn your web page into the coolest and most visited site your school has ever had.
First and most important element about your community website is your content. Web content consists of all documents, data, applications, images, audio and video files that you publish on your web page. It is crucial that you update regularly your website content and publish information that is interesting to your readers. For example, if you are building an academic website you can speak to your teacher about his/hers lectures and ask permission to publish them online, where everyone can read them at home. You can also find out which are your classmates’ favorite books, games, and movies and ask them to write short reviews. Or you can start up a competition and publish the best school essays so everyone can log in, read them and vote. The best ideas about your website content you will find around yourself by asking friends what they like to read and learn more about. Your content is also a key element of your web page because search engines can index text easily and if the information is close to what a searcher is seeking it can be delivered as a site for the seeker of information. This will eventually result into growing number of visits to your site and high search engine ranking.
If you liked this post, buy me a beer. ($3 for a beer or $7.5 for a pitcher)
