Auto Shorten dynamic URL by javascript

Live Demo

Thinking of using bit.ly Url Shortening service in your site? You can use a simple javascript code in any page of your site, specially if it is a dynamic page. For example, look at a dynamic page of my online code compiling site:

The link of a dynamic page is somewhat this: http://shafiul.progmaatic.com/hostcode/compiled.php?i=wRZWM&c=252&ext=11

The link is too long. So, I automatically shortened the links, and gifted it to the viewers! 😉

how to use bit.ly in your site

How to use bit.ly service in your site

First, you need an account on http://bit.ly. To create one, go to the site and register.

Once you’ve registered, login and go to your Account page. There, you will find your API key.

Now, we’ve all the resources. Let’s go to the code section

The Code

Between the <HEAD> and </HEAD> tag of your page, place the following code:

	
  • <script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=******&apiKey=*****************"></script>
  • Replace the first ***** by your bit.ly username and second ************** by your bit.ly API key!

    Now, place the following code anywhere of your page. It is nothing but a text-input field, where shortened link will be placed. You can use anything instead of a text area, perhaps a <div>tag to display the shortened link!

    <h3>Link to this page</h3><br>
    Use this link to tell others about this page! <input onclick = "this.select()" type = 'text' id = "qlink" style = "width:100%;">
    
    <br><br>
    
    

    Now, the final task. Place the following code just before </BODY> the tag of you page:

    <script>
    	// Bit.ly API
    	BitlyCB.shortenResponse = function(data) {
    			var sss = '';
    			var first_result;
    			// Results are keyed by longUrl, so we need to grab the first one.
    			for     (var r in data.results) {
    					first_result = data.results[r]; break;
    			}
    			sss = first_result["shortUrl"].toString();
    			document.getElementById("qlink").value = sss;
    	}
    	BitlyClient.shorten(window.location, 'BitlyCB.shortenResponse');
    </script>
    
    

    Yeah, you’re done! Now anyone entering the page with any query string, the link of the page with the query string will be automatically shortened 😀

    PHP Auto Sitemap Submit Script for Google Bing Yahoo or Other Search Engines

    Sitemaps are useful to tell search engines about different pages of your website. Once you submit a sitemap to a search engine, they can crawl all the links which you provided in your sitemap. So generating a sitemap for your website is very important. If you don’t have a sitemap for your site, create one by Google Codes or manually create one by Learning how to create a sitemap (it’s nothing but a simple XML file!)

    Now, there are two ways for making a scheduled update for your sitemap:

    Automatic: By PHP & Cron Job

    Download this PHP file. Give it a name, like “sitemap_updater.php”. Edit it to type in it the correct location of your sitemap. Now upload it to your server, suppose in /public_html/cron_jobs/ directory. Give the file a name, for example, sitemap_updater.php

    Now, go to Cron job section of your server from the Control Panel/Admin account of your hosting. If you’ve acces to Cpanel, you may click cron jobs like following:

    Next, click a option that suits you most. If you’re new, click standard

    Cron job - how to select method
    Cron job – how to select method

    Next we’re on the main panel. Select your schedule – how often you want to run the code. Then in the command to run box, type the following command:

    php -f /home/your-username/public_html/cron_jobs/sitemap_updater.php
    
    

    Look at the URL: /home/your-username/public_html/ replace it with appropritae location of your root directory.

    If you have a different location for the sitemap_updater.php file, type it accordingly. The following screen-shot might be helpful (ignore the command given in the image)!

    Cpanel how to execute PHP file as a Cron job

    More details on Cron jobs here

    Download the Sitemap_Updater.php file


    Manually Updating Site-maps

    Well, if you don’t have access to PHP/Cron jobs, you can manually update sitemaps. The trick is, we will create a HTML file, save it in our local disk, and run the file manually whenever we need to update the sitemap!

    1. Download this HTML file
    2. Rename it like something.html
    3. Open the file for editing, edit line # 5, give here your sitemap address. Save it
    4. Now whenever you need to update your sitemap, just open the HTML file in your brower! 🙂

    Well, that’s all. Rock with your sitemaps 😀

    Online Code Compile, Sharing Site – Host, Compile & Download your Codes

    🙂 Say hello to…

    HostCode.SF.net

    Online free code hosting

    Whoa! At long last, I’ve finished my Code Sharing/Download/Hosting Project! And with bonus –  with the features to Compile & Execute your codes! 😀 Yummy, huh? Yes, I was looking for a online code storage so that I can demostrate my codes to others, with perfect syntax highlighting, direct one click download facilities etc. I dreamt of a site that would be handy, no registration will be required, just hit the site and paste your code. To spice up everything, I’ve also implemented comment from viewer facility – yes I know you want comment from your viewers! 😉 And lastly, online compilation of your code! Just hit the compile button, provide some input or not, and submit, you find your output that is permanent, share your code/compilation information with anyone on the web!

    So you can share your code here, compile it online, provide links at your blogs & it would be simply superb. Okay enough talking, now let’s see some eXclusive features of the site:

    Now what? Just try the site. If you like it, please recommend to others, I spent a significant amount of site in the development 😦 It’s totally free, and always will be. Please give me feedback, I will definitely take them seriously and implement ASAP……..

    Take care.

    Bangla/Bengali Web File Manager by PHP বাংলা ফাইল ম্যানেজার

    Hello, everybody! Today I’m going to share one of my little but proud contributions to the Bengali language – A Complete Bangla File Manager written in PHP. No, I didn’t write the core file manager script, as there are plenty of scripts available written by professional coders. So I chose File Thingie, a singe-file open source PHP based file manager script. The next thing I did, translated it to my mother lagnguage Bengali 🙂

    Check out the screenshots:

    So what you need to do?

    1. Download latest copy of File Thingie from here (recommended 2.5.3)
    2. Download Bangla Translation extension from here. Rename it to “ft_lang_bn.php” & put it in the same folder where your downloaded copy of File Thingie resides.
    3. Edit the file thingie script, select Bangla as the default language. All you need to do, is simply edit the File Thingie script, find the line containing $ft[“settings”][“LANG”] and set it to bn:

    $ft[“settings”][“LANG”]              = “bn”;

    Now it should be working properly, as working properly in my servers:

    Anyway, I think your tasks are simplified, since translating is not that kind of job for a programmer 😦 Anyway, some of my translations are spelled incorrectly, some of them might not be suitable. Please let me know about them. And you’re always at your freedom to modify the code as you need!

    Note: My translation also stays in the translation packages-download page of File thingie. But i recommend to download it from the hostcode-site, as i may update the script later.

    So fire up your bangla file manager now!!!

    Free PHP FTP Uploader Script

    As many of you already know, & rest will be known by the end of the post that you can make FTP connections and actions by PHP, we can create a simple one-page FTP based File Uploader running in PHP 🙂

    Well, are you wondering, what’s the need of this heck when we can already upload files by simple PHP calls? Well, many of us run our files on Free Hosting Providers, and they dont allow us to write files. They simply restrict opening files in Write mode, so though we can read the file from a remote location, we can’t write it safely in our server 😦

    So if we want to copy some files from another server to our server, & if you’re allowed to make FTP connections (that means you have an FTP username & password) we can use the script below. This is a one file PHP script, Put it in the directory where you want to upload files, and use it with simple efforts.

    The Script

    Yes, it’s free 🙂 Grab it from here

    The code is pretty self-explanatory, so if you’re going to modify it, you’ll find it a piece of cake!

    Screenshot

    Really simple huh?

    Issues

    • If FTP is not enabled in your server configuration, this will not work. Check your PHP configuration by phpinfo();
    • If your server configuration restricts remote opening file (reading files hosted in other server) , this will not work.