User Tools

Site Tools


webdev

Minimal page requirements

Suitable for most pages, contains link to screen/print CSS and meta description&keywords

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="css/screen.css" media="screen"/>
	<link rel="stylesheet" type="text/css" href="css/print.css" media="print"/>
	
	<title>website title</title>
	<meta name="description" content="Page description goes here !" />
	<meta name="keywords" content="keywords, key, words" />
</head>
<body>
</body>
</html>

Apache

Minimal site declaration

<VirtualHost *:80>
        ServerAdmin admin@mysite.tld
        ServerName mysite.tld
        DocumentRoot /var/www/mysite

        CustomLog ${APACHE_LOG_DIR}/sites/mysite-access.log combined
        ErrorLog ${APACHE_LOG_DIR}/sites/mysite-error.log
</VirtualHost>

.htaccess

Redirect depending on language

To send a user to a different page depending on their browsers language:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Language} ^fr* [NC]
RewriteRule ^$ /fr/ [L]
RewriteRule ^$ /en/ [L]

If the users language is French, they go to /fr/, for any other language they go to /en/
We ask the condition to start with “fr”, and can have anything after that, the [NC] means that the language is not case sensitive. The [L] means that if the condition is met, we don't read any further.

blank space at beginning of page

Symptom: when using PHP's include(), a blank space is inserted in the beginning of the page
Cause: pages have been edited with different editors and/or changed format too often (utf8/ansi), the editor adds an invisible character at the beginning of the document to define this.
Solution: http://studentguru.gr/b/solidus/archive/2009/12/30/lt-php-include-gt-strange-extra-white-space-at-the-beginning-of-page.aspx

PHP

file_get_contents() doesn't work with https

Use cURL:

function fetchUrl($url) {
$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_URL,$url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
webdev.txt · Last modified: 2013/12/25 16:47 (external edit)