Bookmark and Share

Home Page in Blogger

How to Make a Post or Page Your Homepage in Google Blogger
The question gets asked sometimes on Google Blogger tips sites, how to make a specific page your homepage for Blogger. You can do it with a bit of Javascript. What you do is:
In Blogger design mode, go to Settings, Edit HTML.
In this example I am going to use a homepage, the final part of which is /p/map.html. You need to substitute your own required tail of the url, in place of /p/map.html.
Locate the line in Blogger Edit HTML that begins <title> and on the line following that one insert this:
<script type="text/javascript"> if(window.location.href.substr(7, window.location.href.length-8).indexOf(&quot;/&quot;)==-1) {var v=window.location.href.substr(8)+&quot;/p/map.html&quot;; window.location.href=window.location.href.substr(0,8)+v.replace(/\/\//g,&quot;/&quot;)} </script>
Remember, substitute the tail of the page url you want, in place of /p/map.html
Looks more complicated than it is, what we are doing is:
We’re looking at window.location.href which is the current url.
The first part of window.location.href is likely to be http:// or https:// therefore we start looking at the url from the eighth character because we’re looking for the first occurrence of a slash (/).
Also we want to ignore any slash character that is at the end of the string. So for example if the url is http://myblog.blogspot.com/ we want to see whether there are any slashes, excluding the three that are in that string.
We therefore look at the url, from the eighth character until the final character minus one. If what we find contains no slashes, then we assume that it is just the base blogger url that has been typed, and not a specific page.
if(window.location.href.substr(7, window.location.href.length-8).indexOf(&quot;/&quot;)==-1)
does just that; starting from the eighth character (character 7) for the length of the url minus eight characters, i.e. the seven before the one we’re starting at plus one at the end, we look for the index character of a slash. If there is none, Javascript will reply with -1.
Right, so if that condition is true, i.e. the result is -1, we do the next bit in two stages so as to make the code a little bit clearer to read than it would be if it were in one. First, we set a variable, v, to the url from its eighth character to its end, and we tag onto the end of it the page we want to be our home page. In the example it is /p/map.html
var v=window.location.href.substr(8)+&quot;/p/map.html&quot;;
Then we get Javascript to set the current url to the existing one for its first eight characters, followed by what we’ve set in variable v, but replacing any occurrence of double slashes by a single slash. We do this replace because if our url was myblog.blogspot.com/ with a slash at the end as opposed to myblog.blogspot.com without one, then by taking on /p/map.html we would get a double slash. Actually, that would probably be OK, but we may as well make it nice and neat.
window.location.href=window.location.href.substr(0,8)+v.replace(/\/\//g,&quot;/&quot;)
The string v.replace(/\/\//g,&quot;/&quot;) uses a regular expression to do a global replace (which again is belt and braces but then why not?) and since the delimiter character for a regular expression is a slash, we have to escape the slashes within it, hence /\/\// which looks like an attempt to make a picture, but works, trust me.
I hope that’s clear. In any case it works, you just have to substitute your required homepage for /p/map.html – I have used /p/map.html solely as an example.

PHP ftp on Shared Servers

To Avoid the Wrong Domain
A ftp connection in PHP can be made to a different domain from the one you are currently working on. But sometimes you can think you are connecting to domain a, when in fact the connection is to domain b.
It happens like this: aaa.com and bbb.com are on the same server, and your PHP script is in aaa.com, and you put for example ftp.aaa.com as your ftp server, but instead of the username and password for aaa.com you accidentally put the username and password for bbb.com, then although the ftp server you specified was aaa.com, you will actually get a connection to bbb.com.
I cannot say for sure that this happens on every server, as I cannot test every server, it certainly seems to happen on some, including some running Apache.
What we need, then, is some code in PHP to check that the server we are connected to for ftp is the same one that the scripts are running on, and so ensure that if you upload a file, say, then your scripts can access it in the place they think it is going to be. We need a check to make sure that the username and password used for ftp are the correct ones for where we want to be.
One way of doing this, that you see recommended sometimes, is to do a ftp_rawlist or ftp_nlist, and if these return an empty array (ftp_rawlist) or false (ftp_nlist) then you are on the wrong server. The trouble with this method is that ftp_rawlist and ftp_nlist are unreliable, they don’t work on some configurations, so their returning an empty array or false does not necessarily mean that it is the wrong server, it may mean something else is wrong.
The method I use is this:
$servername= the ftp server name, eg. ftp.aaa.com
$ftpconx= ftp stream as in PHP documentation
$username= the ftp user name
$initial_directory= our initial directory for ftp
$slash='/'; // or whatever the path separator is
$srvOK=!check_server_problem($servername, $ftpconx, $username, $initial_directory, $slash);
if(!$srvOK){
echo $srvOK; // we've identified a problem
}
function check_server_problem($servername, $ftpconx, $username, $initial_directory, $slash){
$md=@ftp_chdir($ftpconx,$initial_directory);
if(!$md){
return 'Initial directory not found';
}
$stamp=time();
$rl=@ftp_mkdir($ftpconx, 'tmp_try'.$stamp); // we try making a directory in the current ftp directory
if($rl===false){
return 'Write permission not set on '.$servername;
/* If the ftp user does not have write permission to the current directory or in the unlikely event that a file or directory called tmp_trynnnnn already exists, then ftp_mkdir will fail and 'Write permission not set' be returned. The code could be made more elaborate here, to check what is the real reason for ftp-mkdir failing. This code is kept a bit simpler than the belt-and-braces version would be. */
}
$lookerdir=$_SERVER['DOCUMENT_ROOT'];
if(substr($lookerdir,strlen($lookerdir)-(strlen($initial_directory)))==$initial_directory){
$lookerdir=substr($lookerdir,0,strlen($lookerdir)-strlen($initial_directory));
}
if((substr($lookerdir,strlen($lookerdir)-1)!=$slash) && (substr($initial_directory,0,1)!=$slash)){
$lookerdir.=$slash;
}
$lookerdir.=$initial_directory;
if(substr($lookerdir,strlen($lookerdir)-1)!=$slash){
$lookerdir.=$slash;
}
/* we should now have $lookerdiv set to the system path that matches our ftp directory */
$dir_exists = file_exists($lookerdir.'tmp_try'.$stamp);
$rl=ftp_rmdir($_SESSION['wa66_ftp_conx'], 'tmp_try'.$stamp); // remove the directory we just made
if($!dir_exists){
return ' Username '.$username.' seems not to belong to '.$servername;
}
return '';
}
And if there is a better method than this, then I would be delighted to know what it is.

Multiple URL Icons in Windows 7 Taskbar

It Should Be Easy, Seeing As It’s the Sort of Thing Lots of People Might Want to Do, But Then It Is Windows I Suppose
Microsoft Windows used to be pretty intuitive, but ever since Vista it has become more and more obtuse. Have they been using Focus Groups or something? Probably.
Anyway, when asked how you put a number of different icons in the Windows 7 Taskbar for different urls, i.e. an icon for one-click access to a web page www.a.com and another icon for web page www.b.com, I thought: seems a sensible question, since that makes for easier usage, an interface design enhancement on the desktop. This is using Firefox and Chrome, it may be straightforward with IE – I have not tested that as I was asked about using Firefox and Chrome as the web browsers. I’ll refer to Firefox throughout this page, but the principle applies to any browser, probably. I expect that IE is no different in this respect, and if it is, it shouldn’t be.
You cannot just drag a tab from the browser to the Taskbar, as Microsoft web advice says you can. Or rather you can for the first instance, but subsequent instances do not create another icon in the Taskbar, they simply replace the default url for the existing icon. The way I found of creating multiple icons is as follows. Really user-friendly you’ll think, when you have got to the end. Bleagh!
Step 1. Click the Windows icon in the bottom left corner of the screen, and then in the Search box type cmd .
Step 2. A panel should appear, at the head of which shows cmd.exe, or else a little icon with C:/ in it and 'cmd' next to it.
Step 3. Right-button click on 'cmd' and select 'Run as Administrator'. This will only work if you are logged into windows as a user with Administrator privileges. You can find out whether you are from Control Panel, Users and Accounts.
Step 4. If you are not logged in as a user with Administrator privileges, then there is no point continuing. If you are though, then:
Step 5. A MSDOS window will appear as a result of selecting Run as Administrator on cmd.exe. Leave that there for the moment.
Step 6. You need to find where the Mozilla Firefox executable is located. It will be somewhere like C:\Program Files\Mozilla Firefox\, or on the computer I have been working on it is in C:\Program Files (x86)\Mozilla Firefox\ – something like that.
Step 7. When you have located where the Mozilla Firefox executable is, go back to the MSDOS-like cmd window and if your Mozilla Firefox is located in the same place as mine, type:
cd "C:\Program Files (x86)"
Press Enter to accept the command. You need to include the double-quotes because of the spaces – this is so that the character string does not get evaluated as C:\Program, with 'Files' and '(x86)' as parameters. If Firefox.exe on your computer is located in a differently-named folder to mine, adjust the cd command accordingly.
This changes the current directory to one level above where the browser program is located, so if Firefox.exe is in C:\Program Files (x86)\Mozilla Firefox\ you want to be one level above, i.e. in my case: C:\Program Files (x86)\. Clear? Good.
Step 8. Type:
mklink /D "Mozilla Firefox Link 1" "Mozilla Firefox"
This creates a symbolic link called Mozilla Firefox Link 1. It actually creates a little folder (or directory, whichever term you wish) which you can see in the files Explorer (Computer, My Computer – whatever stupidly unclear name has replaced the old Windows Explorer).
Mozilla Firefox Link 1 can actually be any name you want, you can call it Glory Hallelujah if you like, but probably something a bit meaningful might be clearer later on, as you may want to be creating a number of these. Anything, that is, provided it is a name that is a valid folder name and that does not exist already in the current directory. You can delete this virtual folder whenever you wish, just as you would delete any folder. Though be careful doing that once you have finished with the following steps.
Step 9. In the Computer explorer list, locate Microsoft Firefox executable under the \Mozilla Firefox folder (perhaps C:\Program Files\Mozilla Firefox\ or C:\Program Files (x86)\Mozilla Firefox\ . Right-button click on the executable – i.e. the program in the files list on screen – and select 'Create Shortcut' .
Step 9. A message appears saying that a shortcut cannot be created there and would you like to put it on the Desktop instead. Answer OK.
Step 10. On the desktop there should now be a just-created shortcut to Mozilla Firefox. Right-button click on it and select 'Properties'
Step 11. Under the ‘Shortcut’ tab of the ‘Properties’ dialog box are two boxes: ‘Target’ and ‘Start In’. Both will contain the same path. In the first, i.e. in Target, after the end of the text string, that is after
firefox.exe"
first change the path so that where it says, say: . . .\Program Files (x86)\Mozilla Firefox\Firefox.exe" . . . change that to your symbolic link, e.g. . . .\Program Files (x86)\Mozilla Firefox Link 1\Firefox.exe" . . . and then:
At the end of that line, after . . . Firefox.exe" , type a space followed by the url you want, e.g. "http://www.xxxx.com" I think that if you don’t put the quotes around the url then Windows does it for you after you have clicked OK, but don’t click OK just yet.
Step 12. In the second box, the one labelled 'Start in', change the folder /Mozilla Firefox/ in the same way that you did under ‘Target’ I am not quite sure what effect this has if any, you may be able to leave 'Start in' just as it is.
A note as an aside: I have found that sometimes this technique works if you change just the ‘Start in’ and leave the path unchanged in ‘Target’. Quite what conditions this simplified method works or does not work in I have not yet discovered, so to be on the safe side I have tended to change both.
Step 13. It might be a good idea to change the icon, so that when the new item is in the Taskbar you can distinguish it from other items. I have found that when you click 'Change Icon' in the 'Properties' dialog you only get a few to choose from,
however if you click 'Browse' and then locate a folder that has some files in, and then select 'All Files' from the dropdown box,
and then select a file that is not an icon and click OK, you get an error message
and after clicking OK to that you are then presented with a lot more icons to choose from.
This is an impressively intuitive Windows feature isn’t it?
Select an icon from this more comprehensive set and click OK.
Step 14. Click on the ‘General’ tab in the Properties dialog and in the first box, which is unlabelled, where it probably says something like ‘Mozilla Firefox (shortcut)’, change that to a description of your url, i.e. to whatever description you want for what you are trying to put in the Taskbar.
Step 15. Click OK on the 'Properties' dialog to apply your changes and close the box.
Step 16. Right-button click on your newly modified icon on the Desktop and select ‘Pin to Taskbar’ and lo! It creates a new item in the Taskbar.
Step 17. Repeat steps 8 to 16 for each icon you want to put in the Taskbar, changing the symbolic link name each time, e.g. you could do the next one as ‘Mozilla Firefox Link 2’ in place of ‘Mozilla Firefox Link 1’. Whatever, the name of the symbolic link pseudo-folder can be any legal folder name.
Step 18. Remind yourself next time to buy a Mac.
Some things are as easy or easier on pc than on a Mac and some vice-versa, but few could argue that this is a selling point for a pc. On the Mac you simply save the url with Save As from the browser, then locate where you have saved it in Finder and drag the item down to the Dock, next to the Recycle Bin icon. Just in case anyone argues that doing this would be just as hard on a Mac, well they’re wrong, that short sentence is how, or one way how.
WARNING! Multiple icons in the Windows Taskbar work fine using symbolic links as defined above, but they seem to upset Windows’ idea of what the default browser is. So let’s say your default browser is Firefox, when you use an icon with a symbolic link, if it is a different symbolic link to the one you last clicked on; and if the link is going to open in a new window, as opposed to a new tab – and when is which is at the moment a mystery to me, I can only say, ‘Don’t ask!’ then you will get the warning message, ‘Firefox is not currently set as your default browser. Would you like to make it your default browser?’
This is an especially annoying message, as Firefox IS your default browser. Whether you click Yes or No to this makes little difference, just remind yourself that you could design a better system than Microsoft bloody Windows if only someone would ask, and see step 18.
I have referred throughout to Firefox above, the same principle will work for any browser, or should do. And of course I may be missing something much more straightforward, and if so I would delighted to hear what it is and will take back some of my disdain for Microsoft’s user-interface design, er, experts.