Author Archive

How to include multiple js file in one js file?

Posted by 17 October, 2010 (0) Comment

To include multiple js files in page is bad in terms of http request. Yslow Yahoo! tool can give you bad grade. Grade F on making more HTTP requests.
Apart from that page loading time increases and page does not looks clean.

Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet.

Including multiple .js file in one external file has several advantages.
1. Less HTTP request.
2. If cashing is on page lode faster.
3. Page looks clean.

Use this code to add as much as files as you want.

View Code JAVASCRIPT
 
document.write('<script type="text/javascript" src="file1.js"></script>');
document.write('<script type="text/javascript" src="file2.js"></script>');
document.write('<script type="text/javascript" src="file3.js"></script>');
document.write('<script type="text/javascript" src="file4.js"></script>');
Share
Categories : JavaScript Tags :

Is yahoo.com down?

Posted by 14 October, 2010 (0) Comment

Yes Yahoo.com is down today from 10/14/2010 1:54:22 PM

Still it is not up!

Share
Categories : Yahoo Tags :

How to add www in url through .htaccess?

Posted by 9 October, 2010 (1) Comment

Recently I was working on a project and SEO team requested to add WWW forcefully in project URL. I asked why, they said.
“Must have www in your URL! Google Like it.”
So here is .htaccess snippet to force a url with WWW
When you will type http://phpmind.com it will automatically become http://www.phpmind.com

RewriteEngine on
 
rewritecond %{http_host} ^phpmind.com [nc]
rewriterule ^(.*)$ http://www.phpmind.com/$1 [r=301,nc]

This is how I did in this site. I am telling you one .htaccess secret. You can experience here only.

Share
Categories : .htaccess,PHP Tags :

How to add and disable ETags through .htaccess?

Posted by 9 October, 2010 (2) Comment

What is ETag?
An ETag, or entity tag, is part of HTTP and it provides a unique identifier for the resource being supplied.

This identifier can then be used to validate if it resource has been modified or
Browser requests can use an etag and an if-match header to check whether a resource has been modified since it was served, providing an efficient caching facility that relies on content rather than on timeouts.

Use this code to setup ETags on your server, using following htaccess.

 
FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch "\.(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
   </filesmatch>
</ifmodule>

Sometimes developer want to be disable ETags from headers. To disable ETags, make sure to include following snippet in your .htaccess file.

 
Header unset ETag
FileETag None

Share
Categories : .htaccess,PHP Tags :

How to use .htaccess for permanent redirect 301?

Posted by 8 October, 2010 (0) Comment

If you are making search engine friendly URL from pages which are using query string (i.e. www.phpmind.com?id=2 ) and pages which are indexed in search engines or if you are rewriting your website with new urls then you need permanent redirect 301!!

Let me tell you what happens here. If you remove a page which is already in Google it will generate error and that is not good for your site.
So .htaccess for permanent redirect will save life! Just redirect old to new url and Google will like your site this is good practice in terms of SEO too.

This one line PHP code is worth to add in .htaccess file of your root directory without loosing search engine ranking in Google and Others.

Redirect 301 /oldPage.html http://mydomain.com/newpage.html
 
Another Way 
 
redirectpermanent /contact-me.html http://www.phpmind.com/contact-us.html
Share
Categories : .htaccess,PHP Tags :

How to prevent hot linking using .htaccess?

Posted by 8 October, 2010 (0) Comment

Don’t let your users your photo steel! If you have very good photo or even not good! and want to prevent your files using php technology, such as jpg, gif, bmp, png etc.

You can just put this code in root directory of .htaccess file of your php project and it won’t let others site use you files directly and it will save your bandwidth. This is the main purpose of blocking hotlinking using .htaccess in php.

 
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?my-website-url\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpg|gif|bmp|png)$ http://phpmind.com/no-hotlinking-please.png [L]
Share
Categories : .htaccess,PHP Tags :

How to upload big file using .htaccess?

Posted by 8 October, 2010 (0) Comment

You can upload big file yes it is possible without applet and other third party lib!
Simply put these standard configuration values and they will overwrite php.ini setting, which does not let you upload big file in your server.

php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_execution_time 300
php_value max_input_time 300
Share
Categories : .htaccess,PHP Tags :

How to force http to https through .htaccess?

Posted by 8 October, 2010 (0) Comment

In order to force https:// in payment and other secure pages even if your customer try to access http:// or they forget. You can use .htaccess file and simple code.

Example –
I had created a page http://www.phpmind.com/blog/
I want my visitor to access https://www.phpmind.com/blog/
Here is code which will force them to redirect to https://

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Share
Categories : .htaccess,PHP Tags :

How to explode a string and create hyperlink?

Posted by 4 October, 2010 (0) Comment

Here is very easy code to create Tagged List with hyperlink.
I have found several events where we have to create dynamic URL with Tagged text.
I have used very simple approach. Just Exploded sting and replaced space with “-”
You can use PHP function preg_replace() or str_replace() then used here-docs for creating hyperlink.
Instead of Echo Hear Docs is much better solution.
And at last removed the last Comma, and return your comma separated Dynamic links.

$tags = "jQuery Tutorials, PHP Display Errors, Drupal Module";
$tagL="";
function b2b_article_LinkedTags($stringTags) {
	$expTags = explode(",",$stringTags);
	foreach($expTags as $key=>$Tagevalue) {
	$Tagevalue = trim($Tagevalue);
	$link = preg_replace('/[^-a-z0-9]/', '-', strtolower($Tagevalue) );
	//$link = str_replace(" ","-", strtolower($Tagevalue));
	$tagL.=<<<EOF
	   <a href="./articles-tagged-$link">$Tagevalue</a>,
EOF;
	}
 
	return substr($tagL, 0, -1);
}  
echo b2b_article_LinkedTags($tags)
Share
Categories : Easy PHP,PHP Tags :

Shell Script in 5 minutes!

Posted by 18 September, 2010 (0) Comment

Shell scripts are short programs that are written in a shell programming language and interpreted by a shell process. They are extremely useful for automating tasks on Linux and other Unix-like operating systems.

1. Here is very short tutorials to make a very basic shell scripting.
. open vi or any other advance editor like vim

#!/bin/bash
clear
pwd
echo "Hello phpmind, world."

2. Save this script and give a name for example “phpmind.txt”
3. phpmind will be your command.
4. To run your command type ./phpmind
5. If its says Permission denied then use chmod 755 phpmind
6. Now the script is ready to run by typing the following, again while in the same directory, and then pressing the ENTER key:
./ phpmind

How It Works

The first of the three lines tells the operating system what shell to use to interpret the script and the location (i.e., absolute pathname) of the shell. The shell is bash, which is located in the /bin directory (as are all shells); thus the line contains /bin/bash. This instruction is always preceded by a pound sign and an exclamation mark in order to inform the operating system that it is providing the name and location of the shell (or other scripting language).
The second line tells the shell to issue the clear command. pwd (which shows the current directory),
The third line tells the shell to write the phrase Good morning, world. on the screen. It uses the echo command, which instructs the shell to repeat whatever follows it.

Share
Categories : Shell Script Tags :