Friday, July 30, 2010
Clear Soap Cache PHP
ini_set("soap.wsdl_cache_enabled", "0");
.htaccess for force download microsoft technologies using php
In your HTML directly link to the file which is to be downloaded.
i.e.
a href="........./files/somefile.pdf">Download Pdf
for PHP
?php
// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
?
You will get a pop-up box asking whether you want to save the file or open it normally.
Now you want to download it so open .htaccess file and write there some lines according yo your requirement mentioning extension of files which you want to download directly.
Place the following code into your .htaccess file.
AddType application/octet-stream .pdf
AddType application/octet-stream .doc
AddType application/octet-stream .csv
This script will force download all files having extensions .pdf, .doc or .csv.
.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
There is .htaccess file present by default at the root directory of your server. If not, you can always create a file named as .htaccess, code it and upload it in the desired directory or at the root level of your website.
In several web servers (most commonly Apache), .htaccess (hypertext access) is the default name of directory-level configuration files. A .htaccess file is placed in a particular directory, and the directives in the .htaccess file apply to that directory, and all subdirectories thereof. It provides the ability to customize configuration for requests to the particular directory. The file name starts with a dot because dot-files are by convention hidden files on Unix-like operating systems.
AddType application/vnd.ms-word.document.macroEnabled.12 .docm for docx in .htaccess in ubuntu
i.e.
a href="........./files/somefile.pdf">Download Pdf
for PHP
?php
// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
?
You will get a pop-up box asking whether you want to save the file or open it normally.
Now you want to download it so open .htaccess file and write there some lines according yo your requirement mentioning extension of files which you want to download directly.
Place the following code into your .htaccess file.
AddType application/octet-stream .pdf
AddType application/octet-stream .doc
AddType application/octet-stream .csv
This script will force download all files having extensions .pdf, .doc or .csv.
.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
There is .htaccess file present by default at the root directory of your server. If not, you can always create a file named as .htaccess, code it and upload it in the desired directory or at the root level of your website.
In several web servers (most commonly Apache), .htaccess (hypertext access) is the default name of directory-level configuration files. A .htaccess file is placed in a particular directory, and the directives in the .htaccess file apply to that directory, and all subdirectories thereof. It provides the ability to customize configuration for requests to the particular directory. The file name starts with a dot because dot-files are by convention hidden files on Unix-like operating systems.
AddType application/vnd.ms-word.document.macroEnabled.12 .docm for docx in .htaccess in ubuntu
Monday, July 19, 2010
Auto Refresh
Refreshing or redirecting off old web pages (to newer versions or locations) is very often necessary if you move (and/or upgrade) your web pages a lot.
Meta HTTP-EQUIV="REFRESH"
html>
head>
meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
meta http-equiv="refresh" content="0;
url=" />
title>Refresh Page
/head>
body>
p>test
p>##
p>If you are not re-directed to the page automatically,
please use the link above.
/body>
/html>
meta http-equiv="refresh" content="0;
url=http://www.google.com" />
Content="0"?... What is that?
The "0" is the number of seconds before the page will automatically refresh! So, it could be anything.
And don't forget to add a link further down the page so that the next time a Search Engine Spider crawls around in those old pages, their index will be updated!
Meta HTTP-EQUIV="REFRESH"
html>
head>
meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
meta http-equiv="refresh" content="0;
url=
title>Refresh Page
/head>
body>
p>test
p>##
p>If you are not re-directed to the page automatically,
please use the link above.
/body>
/html>
meta http-equiv="refresh" content="0;
url=http://www.google.com" />
Content="0"?... What is that?
The "0" is the number of seconds before the page will automatically refresh! So, it could be anything.
And don't forget to add a link further down the page so that the next time a Search Engine Spider crawls around in those old pages, their index will be updated!
Refresh / re-direct using PHP
We know how to use Refresh Meta tags in our head tags. But what if we needed to do the same thing only this time do it in PHP?
We can use PHP's header() function
We can re-direct or refresh our web pages by simply doing either of the following in our PHP scripts
or codes:
Method I: using header('location...')
You probably know this ol' favourite...
php:
// refresh / re-direct without delay
// ---------------------------------
header( 'location:http://www.desilva.biz/webdsn/' );
?>
Method II: using header('refresh...')
php:
// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 5; url=/webdsn/' );
echo '
// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 3; url=/' ); # redirects to our homepage
echo '
// refresh / redirect to an external web page
// ------------------------------------------
header( 'refresh: 0; url=http://www.example.net' );
echo '
?>
We can use PHP's header() function
We can re-direct or refresh our web pages by simply doing either of the following in our PHP scripts
or codes:
Method I: using header('location...')
You probably know this ol' favourite...
php:
// refresh / re-direct without delay
// ---------------------------------
header( 'location:http://www.desilva.biz/webdsn/' );
?>
Method II: using header('refresh...')
php:
// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 5; url=/webdsn/' );
echo '
You will be re-directed in 5 seconds...
';// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 3; url=/' ); # redirects to our homepage
echo '
You will be re-directed in 3 seconds...
';// refresh / redirect to an external web page
// ------------------------------------------
header( 'refresh: 0; url=http://www.example.net' );
echo '
You won\'t know what hit you!
';?>
Tuesday, July 13, 2010
How to reset the all users' settings in Gnome?
rm -rf .gnome .gnome2 .gconf .gconfd .metacity
Monday, July 12, 2010
Mysql Remote database connect from terminal
To connect the remote database from your terminal the command is
user>mysql --host=hostname --user=root --password
To change the password from the mysql command prompt is
mysql>SET PASSWORD FOR root@localhost = OLD_PASSWORD('mypassword');
user>mysql --host=hostname --user=root --password
To change the password from the mysql command prompt is
mysql>SET PASSWORD FOR root@localhost = OLD_PASSWORD('mypassword');
Thursday, July 8, 2010
Using Memcache
“memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.”
Basically, what this means is that memcached is a daemon running on a server which allows you to save and retrieve variables in the server memory. This is primarily used to ease database load on websites and applications. The logic for doing something like this is…
- Before running a query, check if the result is available in memcache.
- If the result is in memcache, return the cached result.
- If not, run the query on the database, and store the result in memcache.
To install memcached, simply run the following command:
sudo apt-get install memcached
Once it’s installed, edit /etc/memcached.conf and change the line beginning ‘-m’ which is the amount of memory (in megabytes) to allocate to the server. You can also change the IP address that the server listens on in the line beginning ‘-l’.
Now restart the daemon by running
/etc/init.d/memcached restart
Now you have memcache set up and running on your server. A great feature of memcached is that you can easily cluster servers. If you want to do this, simply install memcache on your other servers before continuing.
At this point, I’d recommend downloading memcache.php which is a php script showing you a lot of useful information about your memcached servers. Once downloaded, put it in a web facing directory on your server, and modify the $MEMCACHE_SERVERS array with your server addresses.
Using memcache in php scripts is very easy. There are either procedural, or object oriented functions already available. Here is an example of a script which will store a simple variable and then retrieve it and display it.
$memcache = new Memcache;
$memcache->addServer(’10.2.0.245′, 11211) or die (“Could not connect”);
$memcache->addServer(’10.2.0.249′, 11211) or die (“Could not connect”);
$memcache->set(‘mytestvariable’, “this is the data in my test variable”, false, 60) or die (“Unable to save the data to the server”);
echo “Data has been stored in the cache
”;
$result = $memcache->get(‘mytestvariable’);
echo “Retrieved data from the server:
”;
var_dump($result);
?>
Obviously if you only have one server then only use one addServer line.
The script above will store the test variable in the cache for 60 seconds. If you drop the timeout down to something like 1 second, and then sleep for 3 seconds before attempting to get the data, you will find that the data has expired and nothing will be returned.
It’s also useful to know that you can store anything which can be serialized in memcache. This means it’s safe to store things like arrays in the cache without having to ‘flatten’ the data beforehand.
Obviously how and where you implement a cache is entirely dependant on how your system works. If you have a lot of intense database usage then you will find that even caching with a short timeout will vastly reduce the amount of database queries. You should find that memcache is considerably faster than normal database access, and even faster than the mysql query cache. You also have total control over what data is cached, and how long it is cached for before your queries fall back to checking a database.
Basically, what this means is that memcached is a daemon running on a server which allows you to save and retrieve variables in the server memory. This is primarily used to ease database load on websites and applications. The logic for doing something like this is…
- Before running a query, check if the result is available in memcache.
- If the result is in memcache, return the cached result.
- If not, run the query on the database, and store the result in memcache.
To install memcached, simply run the following command:
sudo apt-get install memcached
Once it’s installed, edit /etc/memcached.conf and change the line beginning ‘-m’ which is the amount of memory (in megabytes) to allocate to the server. You can also change the IP address that the server listens on in the line beginning ‘-l’.
Now restart the daemon by running
/etc/init.d/memcached restart
Now you have memcache set up and running on your server. A great feature of memcached is that you can easily cluster servers. If you want to do this, simply install memcache on your other servers before continuing.
At this point, I’d recommend downloading memcache.php which is a php script showing you a lot of useful information about your memcached servers. Once downloaded, put it in a web facing directory on your server, and modify the $MEMCACHE_SERVERS array with your server addresses.
Using memcache in php scripts is very easy. There are either procedural, or object oriented functions already available. Here is an example of a script which will store a simple variable and then retrieve it and display it.
$memcache = new Memcache;
$memcache->addServer(’10.2.0.245′, 11211) or die (“Could not connect”);
$memcache->addServer(’10.2.0.249′, 11211) or die (“Could not connect”);
$memcache->set(‘mytestvariable’, “this is the data in my test variable”, false, 60) or die (“Unable to save the data to the server”);
echo “Data has been stored in the cache
”;
$result = $memcache->get(‘mytestvariable’);
echo “Retrieved data from the server:
”;
var_dump($result);
?>
Obviously if you only have one server then only use one addServer line.
The script above will store the test variable in the cache for 60 seconds. If you drop the timeout down to something like 1 second, and then sleep for 3 seconds before attempting to get the data, you will find that the data has expired and nothing will be returned.
It’s also useful to know that you can store anything which can be serialized in memcache. This means it’s safe to store things like arrays in the cache without having to ‘flatten’ the data beforehand.
Obviously how and where you implement a cache is entirely dependant on how your system works. If you have a lot of intense database usage then you will find that even caching with a short timeout will vastly reduce the amount of database queries. You should find that memcache is considerably faster than normal database access, and even faster than the mysql query cache. You also have total control over what data is cached, and how long it is cached for before your queries fall back to checking a database.
Memcache
Problems start when you are dealing with more than one webserver. Since there is no shared cache between the servers situations can occur where data is updated on one server and it takes a while before the other server is up to date.. It can be really useful to have a really high TTL on your data and simply replace or delete the cache whenever there is an actual update. When you are dealing with multiple webservers this scheme is simply not possible with the previous caching methods.
Introducing memcached. Memcached is a cache server originally developed by the LiveJournal people and now being used by sites like Digg, Facebook, Slashdot and Wikipedia.
How it works
* Memcached consists of a server and a client part.. The server is a standalone program that runs on your servers and the client is in this case a PHP extension.
* If you have 3 webservers which all run Memcached, all webservers connect to all 3 memcached servers. The 3 memcache servers are all in the same 'pool'.
* The cache servers all only contain part of the cache. Meaning, the cache is not replicated between the memcached servers.
* To find the server where the cache is stored (or should be stored) a so-called hashing algorithm is used. This way the 'right' server is always picked.
* Every memcached server has a memory limit. It will never consume more memory than the limit. If the limit is exceeded, older cache is automatically thrown out (if the TTL is exceed or not).
* This means it cannot be used as a place to simply store data.. The database does that part. Don't confuse the purpose of the two!
* Memcached runs the fastest (like many other applications) on a Linux 2.6 kernel.
* By default, memcached is completely open.. Be sure to have a firewall in place to lock out outside ip's, because this can be a huge security risk.
Introducing memcached. Memcached is a cache server originally developed by the LiveJournal people and now being used by sites like Digg, Facebook, Slashdot and Wikipedia.
How it works
* Memcached consists of a server and a client part.. The server is a standalone program that runs on your servers and the client is in this case a PHP extension.
* If you have 3 webservers which all run Memcached, all webservers connect to all 3 memcached servers. The 3 memcache servers are all in the same 'pool'.
* The cache servers all only contain part of the cache. Meaning, the cache is not replicated between the memcached servers.
* To find the server where the cache is stored (or should be stored) a so-called hashing algorithm is used. This way the 'right' server is always picked.
* Every memcached server has a memory limit. It will never consume more memory than the limit. If the limit is exceeded, older cache is automatically thrown out (if the TTL is exceed or not).
* This means it cannot be used as a place to simply store data.. The database does that part. Don't confuse the purpose of the two!
* Memcached runs the fastest (like many other applications) on a Linux 2.6 kernel.
* By default, memcached is completely open.. Be sure to have a firewall in place to lock out outside ip's, because this can be a huge security risk.
Install Memchache In Ubuntu
sudo apt-get install make
sudo apt-get install php5-dev
sudo apt-get install php-pear
sudo apt-get install zlib1g-dev
sudo apt-get install memcached
sudo pecl install Memcache
Don't forget to enable the extension in /etc/php5/apache2/php.ini by adding the line extension=memcache.so and restarting the webserver.
sudo apt-get install php5-dev
sudo apt-get install php-pear
sudo apt-get install zlib1g-dev
sudo apt-get install memcached
sudo pecl install Memcache
Don't forget to enable the extension in /etc/php5/apache2/php.ini by adding the line extension=memcache.so and restarting the webserver.
Subscribe to:
Comments (Atom)