There is a very simple method to detect what language the users web browser is using. The following code: //session variable ensures it’s available //throughout current session $_SESSION['lang'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); echo $_SESSION['lang']; Will give you the correct two letter ISO code for the language the browser is using.
Use this script to copy a file from a remote server and save on your own server. <?php $feed = “http://www.domain.com/thefile.pdf”;// url to original $copydir = “/home/webdev/public_html/copies/”; //directory to copy to (CHMOD 777) $data = file_get_contents($feed); $file = fopen($copydir . “thefile.pdf”, “w+”); fputs($file, $data); fclose($file); ?>
Using PHP and MySQL in XML sitemaps is quite easy. The first step is to use the AddType directive. The second step is to add the following code to the top of your .xml file: <?php session_start(); unset($_SESSION['aErrors']); header(‘Content-type: text/xml’); echo ‘<?xml version=”1.0″ encoding=”UTF-8″ ?>’; ?>
The AddType directive is added to the .htaccess file in the directory, to modify the default mimetypes of the files you wish to be effected. A common use of the AddType directive is if you wish to use PHP in .xml files for dynamic xml sitemaps or .html files. The syntax is quite simple: AddType [...]
Many of us use more than one server during the entire project lifecycle. To ensure that you are able to connect to the various versions of the mysql database on each server, use this php connection script: <?php $host = $_SERVER['HTTP_HOST']; // which server is it running on switch ($host) { case ‘localhost’: $server=”localhost”; $user=”root”; [...]