Thursday, May 11, 2006

AJAX: Back Button Fix with PHP and HTML Frames

UPDATED: 2008-10-02 Working Demo, and refined solution to the AJAX Back Button Fix is now available at zedwood.com.


So your back button is broken in your AJAX/PHP web app. I made a fix using PHP and HTML frames.

Flash developers have had to deal with this issue for a while, and so my fix is a variant. View Robert Penner's flash fix.

Lets say you are at a regular website with 5 pages total. After a user navigates from page1 to page2 he may want to click BACK to change the state of the website from page2 back to page1. Well in AJAX your website is no longer divided up into pages, but you must still use the idea of states that intuitively appears to the user as a different page.

So each AJAX page state is arrived at by executing a javascript function. When you click back, you'll want to execute a previous AJAX function which returns the site to the previous page state. This is accomplished with frames, but this means that if a browser is not enabled to use frames (lynx), the back button will not work. This is okay because no one would use lynx for your website anyway.

No what we have a frame overlay page, with two frames, one sized at 100%,100% and the other as invisible. When we hit a link that we want to store in the page history, we make change the page of the invisible frame to a new page, and pass it a parameter of the real page we wanted to go to. Then in our invisible frame we use that parameter to determine which ajax state to go to in the main page, which we arrive at by executing a javascript function. The effect is that when you hit the back button, it jumps to a previous page in the invisible frame and executes the javascript function associated with it, which changes the page state of the main ajax page.

Allowed Links. There are 3 kinds of links available to use on your site:
1. A HREF with _target='parent', used for external links to jump out of the framed ajax page
2. A HREF with onclick="pagenav('ajaxpagestate')" use this to navigate to a new ajax page state
3. Regular A HREF, do not use, because it will boot up the link within your frame overlay

Files needed for my PROOF-OF-CONCEPT(included below):
index.html- contains 2 frames index.php and redir_ph.php(invisible)
redir_ph.php- invisible frame used for storing page history
index.php- your main ajax app page
ajax.js- contains javascript code for ajax
ajaxfunc.php- ajax access this to returns famous quotes in xml


index.html
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
head>
<
title></title>

<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
/head>

<
frameset rows="*,0" frameborder="NO" border="0" framespacing="0">
<
frame src="index.php?useframes=true" name="realframe" frameborder="NO">
<
frame src="redir_ph.php?p=main" name="historyframe" frameborder="NO">
<
/frameset>

<
noframes>
<
body bgcolor="#FFFFFF">
<
script language="JavaScript">
<!---------
window.location.href='index.php';//index.php defaults to useframes=false
//-------->
<
/script>
<
/body>
<
/noframes>

<
/html>


ajax.js
//--ajax
function createRequestObject() {
if(navigator.appName == "Microsoft Internet Explorer")
return new ActiveXObject("Microsoft.XMLHTTP");
return new XMLHttpRequest();
}

var httpreq = createRequestObject();
function ajaxreq(quote) {
httpreq.open('get', 'ajaxfunc.php?t='+quote);
httpreq.onreadystatechange = ajaxresponse;
httpreq.send(null);
}
function ajaxresponse()
{
if(httpreq.readyState == 4)
{
var xml=httpreq.responseXML;
var node=xml.getElementsByTagName("quote")[0];
var quot=node.firstChild.nodeValue;
document.getElementById('maindiv').innerHTML=quot;
}
}


redir_ph.php
<?php
if ( isset($_REQUEST['p']) )
$pagename= rtrim($_REQUEST['p']);
else
$pagename="";

$jscript="if (parent.realframe.pagenavdone) parent.realframe.pagenavdone('$pagename');";
?>
<
html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
head>
<
title><?php echo $pagename;?></title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</
head>
<
body bgcolor="#000000" text="#FFFFFF">
<?
php echo $pagename;?>
<
script language="JavaScript">
<!---------
<?
php echo $jscript;?>
//-------->
</
script>
</
body>
</
html>


ajaxfunc.php
<?php
if ( isset($_REQUEST['t']) )
$t= rtrim($_REQUEST['t']);
else
$t="";

header('Content-type: text/xml');
echo "<quote>";
if ($t=="money")
echo "I spent 90% of my money on women and drink. The rest I wasted - George Best";
else if ($t=="fire")
echo "Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life. - Terry Pratchett.";
else if ($t=="love")
echo "Love is temporary insanity curable by marriage. - Ambrose Bierce";
else if ($t=="success")
echo "If at first you don't succeed... So much for skydiving. - Henry Youngman.";
else if ($t=="hate")
echo "I am free of all prejudices. I hate everyone equally. - WC Fields";
else
echo
"The first ninety minutes of a football match are the most important. - Bobby Robson";
echo "</quote>";
?>


index.php
<?php
if ( isset($_REQUEST['useframes']) )
$useframes= rtrim($_REQUEST['useframes']);
else
$useframes="false";
?>
<
html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
head>
<
meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<
title>My Main AJAX Page</title>
<
script language="JavaScript" type="text/JavaScript" src="ajax.js"></script>
<
script language="JavaScript" type="text/JavaScript">
<!---------
//--back button
var useframes=<?php echo $useframes;?>;
function pagenav(str)
{
if (useframes)
top.frames["historyframe"].location.href = "redir_ph.php?p="+str;
else
pagenavdone(str);
}
function pagenavdone(pagename)
{
if (pagename=="money_quote_state")
ajaxreq("money");
else if (pagename=="fire_quote_state")
ajaxreq("fire");
else if (pagename=="love_quote_state")
ajaxreq("love");
else if (pagename=="success_quote_state")
ajaxreq("success");
else if (pagename=="hate_quote_state")
ajaxreq("hate");
}
//-------->
</
script>
</
head>
<
body style='font-family:Arial,Geneva,Sans-Serif;font-size:10pt'>

This is my main ajax page 3.
<br>
<
br><a href='http://www.google.com' target='_parent'>
Use this type of A HREF for links external to you AJAX app
</a>
<
br>
<
br>Ajax Page States:
<
br>
<
a href='javascript:void(0);' onclick="pagenav('money_quote_state');">money</a>
| <
a href='javascript:void(0);' onclick="pagenav('fire_quote_state');">fire</a>
| <
a href='javascript:void(0);' onclick="pagenav('love_quote_state');">love</a>
| <
a href='javascript:void(0);' onclick="pagenav('success_quote_state');">success</a>
| <
a href='javascript:void(0);' onclick="pagenav('hate_quote_state');">hate</a>

<
div id='maindiv' style='height:50px;border:1px #000000 solid'></div>

<
br><a href='http://www.google.com'>Do not use a regular A HREF link like this</a>
<
br>If you do , you it display your http://www.mysite.com/index.html in the location bar
but show the content of the site you were trying to reach.
</
body>
</
html>

INSTALL: PHP5+APACHE2+WIN32

Installing php 5, apache 2 in a win32 environment is easy. Sometimes enabling extensions can be difficult, but we will be enabling php_curl.dll, php_mysql.dll, php_mcrypt.dll, and php_mssql.dll.

Download PHP5 zip package
(the .zip with all the extensions, not the .exe installer)
Download Apache2 from http://http.apache.org
(link to 2.2.2 /w no SSL)
Unzip PHP5 to C:\PHP
Run the apache2 installer

if you have a folder named C:\PHP\extensions rename it to C:\PHP\ext
rename C:\PHP\php.ini-recommmended to C:\PHP\php.ini
edit C:\PHP\php.ini,
change the extension_dir to "C:\php\ext" (include quotation marks)
remove the ; from line: ;extension=php_curl.dll
remove the ; from line: ;extension=php_mysql.dll
remove the ; from line: ;extension=php_mcrypt.dll
remove the ; from line: ;extension=php_mssql.dll

edit http.conf, add the following lines to the bottom (default location-
c:\program files\apache group\apache2\conf\http.conf)
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-http-php .php
# configure the path to php.ini
PHPIniDir "C:\php"

Now, right-click on "My Computer", go to "Properties", go to the "Advanced" tab, click on the "Environment Variables" button. Under "System" add ";C:\php;C:\php\ext" to your PATH variable.

create a file called
c:\program files\apache group\apache2\htdocs\phpinfo.php
containing the text
<?php phpinfo(); ?>


When you reboot next, your PATH settings will be available to all programs, your apache2 will load as a service, it will see the new version of the http.conf file with the modifications you made, and will see the new php.ini file with the modifications you made, and when you hit "http://localhost/phpinfo.php" you will see an html version of your php.ini file with all of the settings, and you will see sections for each of the php extensions you have enabled.

C++: How to get the Temp Directory

For the currently logged-in user, you can edit the TEMP and TMP folders. In Windows XP, if your right-click on My Computer, go to Properties, go to the Advanced tab, click on Environment Variables, and you can set TEMP and TMP from here.

But what if you are writing a program that needs to create a temporary file? windows.h provides us with the GetTempPath() function used below. The following program was taken from an MSDN coding example.

code to fetch it: [revised]
#include <windows.h>
#include <stdio.h>
#define BUFSIZE 4096

int main(int argc, char* argv[])
{
DWORD dwRetVal;
DWORD dwBufSize=BUFSIZE; // length of the buffer
char lpPathBuffer[BUFSIZE]; // buffer for path

// Get the temp path.
dwRetVal = GetTempPath(dwBufSize, lpPathBuffer);

if (dwRetVal > dwBufSize)
{
printf ("GetTempPath failed with error %d.\n",
GetLastError());
return (2);
}
printf("GetTempPath returned: %s", lpPathBuffer);
return (0);
}
Originally I had included code for Borland C++ Builder code which went and did a manual fetch from the registry, but a reader posted about GetTempPath. I'm more familiar with borland C++ than I am with ms visual studio and windows API commands, so thanks to kicheck for that.

kichik said...
GetTempPath works "on Windows 9x as well and requires a lot less code. It'll also fallback from TMP to TEMP to USERPROFILE to WINDIR in case any of those don't exist."

Thursday, May 04, 2006

PHP: No input file specified error

Sometimes people get this error when installing php as a CGI Binary, when setting up PHP5 IIS6.0 on Windows Server 2003.

Solution:
Edit php.ini, comment out doc_root, there is a problem with virtual servers.

Helpful Links:
http://www.visualwin.com/PHP/
http://www.peterguy.com/php/install_IIS6.html
http://wordpress.org/support/topic/4243

Thursday, April 13, 2006

MFC: Class Wizard Error "Object Required"

I did a couple google searches and found a few people stuck on this one.

In Visual Studio 2003 C++ you start the Class Wizard by doing [Add Class].

PROBLEM:
From a blank project, often the error 'Object Required' comes up. And nothing happens.

SOLUTION:
I did some google searches and found no answers, only people like me with the same question. I eventually found an answer. It gives an error because it requires stdafx.h. Add stdafx.h as a blank file and it should work okay.

This was discovered trying to do the MFC Tutorial Part 5, step 7:

http://www.codersource.net/mfc_tutorial_Part5.html

Tuesday, March 14, 2006

JAVASCRIPT: Redirect

I keep having to look this one up, so I posted it here so I could always find it.

<button 
onclick="window.location='http://www.mysite.com/';">


this also works:
<button 
onclick= "window.location.href='http://www.mysite.com/';">

Monday, March 13, 2006

HTML: No dotted line on links

In order to get rid of this dotted lines on links, you write code so link says 'when you click on my and therefore focus the cursor on me, then blur me'

<a href=http://www.google.com 
onFocus="if(this.blur)this.blur()">Google</a>

Saturday, March 04, 2006

C++: Edit The Registry in Borland C++ Builder 5


#include <registry.hpp>//put this line in your header file

void MakeSerKey(String gSerial)
{
TRegistry *Reg = new TRegistry();

Reg->RootKey = HKEY_LOCAL_MACHINE;
if(!Reg->KeyExists("SOFTWARE\\TestSoftware"))
{
if(!Reg->CreateKey("Software\\TestSoftware"))
{
ShowMessage("Can't Create Key","Error",MB_OK);
delete Reg;
return;
}

try
{
if(Reg->OpenKey("Software\\TestSoftware",FALSE))
{
Reg->WriteString("SERIAL",gSerial);
Reg->CloseKey();
}
else
{
ShowMessage("Registry RootDir error");
}
Reg->CloseKey();
}
catch(ERegistryException &E)
{
ShowMessage(E.Message);
delete Reg;
return;
}
}
delete Reg;
}

void UpdateSerKey(String gSerial)
{
TRegistry *Reg = new TRegistry();

Reg->RootKey = HKEY_LOCAL_MACHINE;
if(Reg->KeyExists("SOFTWARE\\TestSoftware"))
{
try
{
if(Reg->OpenKey("Software\\TestSoftware",FALSE))
{
Reg->WriteString("SERIAL",gSerial);
Reg->CloseKey();
}
else
{
ShowMessage("Can't open key.");
}
Reg->CloseKey();
}
catch(ERegistryException &E)
{
ShowMessage(E.Message);
delete Reg;
return;
}
}
delete Reg;
}

Wednesday, February 08, 2006

HTML: Remove Margins from web pages

Sometimes making a webpage can be frusterating. You make a table with width and height of 100% for positioning and it still doesn't fill up the whole webpage why? Margins.

Don't forget to set margins in your body tag.

<html>
<
head>
<
title>webpage title</title>
<
/head>

<
body bgcolor="#ffffff" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<
/body>
<
/html>


with CSS:
<style type="text/css">
body
{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
</style>

Tuesday, January 31, 2006

LINUX: SUSE + APACHE2 + PHP + MYSQL + ODBC

SUSE + APACHE2 + MYSQL + PHP + ODBC = SAMPO

SAMPO is a type of LAMP install. The acronmym LAMP comes from Linux + Apache + Mysql + PHP.

I wrote this a while ago while consulting for a company with SAMPO needs. The goal was to host a php website on a linux webserver while the data was hosted on a windows mysql server. Only step 7 is specific to that where you end up pointing to the windows server across the network. Optional points in step 4 are specific to the client I was doing this for.
----------------------------
Meant to be included are a number of files:
testfile.html [inline at end]
phptest.php [inline at end]
mysqltest.php [inline at end]
myodbctest.php [inline at end]
odbc.ini [inline at end]
odbcinst.ini [inline at end]
MyODBC-3.51.11-2.i586.rpm [click to download]

Note:
A. Your linux machine's assumed IP Address is 192.168.0.2
B. commands to be typed at the command prompt start with 'command:' (some may need to be done as root)

1. Install Suse Linux 9.3
-In the screen labelled 'Installation Settings', click on 'Software'
-Make sure you select Standard System w/ KDE
-In the top-left of the screen, under Filter, select 'Search'
-Search and make sure all of the following packages have been selected
-apache2
-apache2-mod_php4
-apache2-prefork
-php4
-php4-bz2
-php4-curl
-php4-ftp
-php4-gd
-php4-mcrypt
-php4-mysql
-php4-session
-php4-unixODBC
-php4-zlib
-mysql
-mysql-client
-mysql-shared
-unixODBC
-openssl
-bison
-libxml2
-readline
-flex


2. Enable apache2 and mysql services
-After booting your system, go to
-Linux 'Start' Menu > System > Yast > Network Services > HTTP Server
-configure the http server
-Linux 'Start' Menu > System > Yast > System > System Services
-enable mysql and apache2 (now they will start when the machine reboots)

3. Test apache2
-Copy testfile.html to /srv/www/htdocs
-test it by viewing http://192.168.0.2/testfile.html

4. Test php
-edit php.ini
-set register_globals to On [optional]
-set display_errors to Off [optional]
-restart web server to apply php changes
-command: rcapache2 restart
-Copy phptest.php to /srv/www/htdocs
-test it by viewing http://192.168.0.2/phptest.php
-ensure phptest.php display information about mcrypt, odbc, and mysql

5. Setup mysql locally (not required but good to test mysql connectivity locally before testing it over the network)
-set mysql root password (below, change 'mysqlrootpassword' to your root password preserving quotes)
-command: /usr/bin/mysqladmin -u root password 'mysqlrootpassword'
-go into mysql and execute the following commands
-command: mysql -u root -p
create database testdb;
use testdb;
create table testtable (item_id char(10), item_desc char(100));
insert into testtable values ('001','This is test data 1');
insert into testtable values ('002','This is test data 2');
select * from testtable;
exit;

-Copy mysqltest.php to /srv/www/htdocs
-modify mysqltest.php to contain a reference to the mysql user and password that you setup (can be root)
-test it by viewing http://192.168.0.2/mysqltest.php

6. Setup unixODBC (best to test with database created in step 5)
-install MyODBC-3.51.11-2.i586.rpm
-as root, command: rpm -iv MyODBC-3.51.11-2.i586.rpm
-Copy odbc.ini and odbcinst.ini to /etc/unixODBC
-modify odbc.ini to contain a reference to the mysql user and password that you setup (can be root)
-test with isql (obviously modify mysqluser and mysqluserpassword to point to the user you setup)
-command: isql testdb mysqluser mysqluserpassword
-Copy myodbctest.php to /srv/www/htdocs
-modify myodbctest.php to contain a reference to the mysql user and password that you setup (can be root)
-test it by viewing http://192.168.0.2/myodbctest.php
-if it doesn't work go to the fix on 6a.

6a. unixODBC fix
-as root (su) execute the following commands at the shell:
-command: cd /usr/lib/php/extensions
-command: sed -i -e 's/libc.so.6/xxodbc.so/' unixODBC.so
-command: cd /usr/lib
-command: ln -s libodbc.so xxodbc.so
-command: rcapache2 restart
6a source: http://susewiki.org/index.php?title=PHP4_ODBC

7. Point to final distination
Now that you have a server with Suse + Apache + PHP + Mysql + unixODBC + MyODBC setup,
-setup odbc.ini and odbcinst.ini to point to a windows mysql server over the LAN
-you may have to open a hole in the windows mysql server firewall at port 3306 to allow mysql connections through

======================================
ATTACHED FILES
======================================
testfile.html
If you can see this in <b>bold</b> your
http server is working.


phptest.php
<? echo phpinfo(); ?>



mysqltest.php
<?php
echo "just checking";
$link = mysql_connect('localhost', 'root', 'r00tpwd') or
die('not connect');

echo "\ngood connect";

mysql_select_db('testdb') or ('not select db');

$query = 'SELECT * from testtable';
$result = mysql_query($query) or die('Query failed');

while($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print_r($line);
}

mysql_free_result($result);

mysql_close($link);
?>



myodbctest.php
<?php echo "just checking";
$conn = odbc_connect('mysqltest', 'root', 'r00tpwd')
or die('error connecting');

echo 'connected successfully';

$sql = "select * from testtable";
$rs = odbc_exec($conn, $sql);
while(odbc_fetch_row($rs))
{
$f1 = odbc_result($rs, 1);
$f2 = odbc_result($rs, 2);

echo "
QUERY RESULTS:" .$f1." ".$f2;
}

?>


odbc.ini
[mysqltest]
Description = MySQL ODBC Database
Driver = MyODBC
Server = localhost
Database = testdb
#Port =
#Socket =
#Opinion =
#Stmt =


odbcinst.ini
[MyODBC]
Description = MySQL ODBC 3.51 Driver DSN
Driver = /usr/lib/libmyodbc3.so
Trace = Off
TraceFile = stderr

[MySQL ODBC 3.51 Driver]
DRIVER = /usr/lib/libmyodbc3.so
SETUP = /usr/lib/libmyodbc3S.so
UsageCount = 1

Thursday, January 26, 2006

INSTALL: Installing CURL for PHP (win32)

Assumptions:
PHP folder is C:\PHP
extension folder is C:\PHP\ext
php.ini found in C:\WINDOWS
system32 is C:\WINDOWS\SYSTEM32
web folder is C:\Apache2\htdocs


1. Create a phpinfo.php file in C:\Apache2\htdocs
2. Write <?php echo phpinfo(); ?> as the text of the file phpinfo.php
3. Verify it works: http://localhost/phpinfo.php (should display readonly php.ini in a table). *This confirms that http server works and php is installed
4. At the DOS/Command Prompt type echo %PATH% to view the current path
5. Put C:\PHP and C:\PHP\ext in your path: Go to My Computer->Advanced->Environment Variables->System Variables, and add C:\PHP;C:\PHP\ext; to the end of your path
6. Download the php .zip archive (with all the extensions in it) that corresponds to your version of php and extract libeay32.dll and ssleay32.dll
7. Put libeay32.dll and ssleay32.dll in your C:\WINDOWS\SYSTEM32 folder
8. Verify php_curl.dll is found in your C:\PHP\ext folder
9. Modify C:\WINDOWS\php.ini
- remove semi-colon from line ;php_curl.dll
- in php.ini, verify that extensions_dir = "C:\PHP\ext"
10. Restart HTTP service if you can't tell it worked.
- Start->Control Panel->Administrative Tools->Services
- right click Apache or HTTP or IIS and select restart
11. Verify by checking http://localhost/phpinfo.php
- Curl should have its own spot

Troubleshooting:
If you get the error...
PHP Warning: Unable to load dynamic library 'C:\PHP\ext\php_curl.dll' - The specified module could not be found. in Unknown on line 0
... at the bottom of your http://localhost/phpinfo.php or at the bottom of any php script, then verify that you followed all the steps.

Also, verify that the php.ini you made changes to is the same one that http://localhost/phpinfo.php displays in the fifth (or so) row down under
"Configuration File (php.ini) Path"

Also, verify that you clicked [Apply] or [OK] after step 5

Keep trying stuff until it works.

Thursday, December 29, 2005

CRYSTAL: EOleSyserror Exception - Class Not Registered

In the Windows environment DLLs consist of two things, classes (blueprints that objects are made from) and functions.

Windows provides a way to register a DLL using C:\WINDOWS\SYSTEM32\REGSVR32.EXE. As I understand it, this makes the classes and functions in that DLL available for use.

Recently I was faced with a problem where there was a delphi application which used Crystal Reports 9.0 which when it was ran on a non-developer machine gave an error: EOleSyserror Exception - Class Not Registered. I did some research and found that the application used the classes CRAXDRT_LIB, OleServer, and OleCtrls. My research also told me that Crystal Reports runtime uses ActiveX Controls and components. I went to the a help pdf on businessobjects.com and found a number of DLLs.

I eventually found that I could fix the problem with the following steps:
1. Find crviewer9.dll on a machine that has crystal reports installed.
2. Copy it into a folder like C:\WINDOWS\SYSTEM32
3. In the Windows Start Menu go to "Run".
4. type "cmd" at the prompt and click Ok.
5. type "C:\WINDOWS\SYSTEM32\REGSVR32.EXE C:\WINDOWS\SYSTEM32\crviewer9.dll"

Solved.

Friday, December 09, 2005

PHP: Hide Progress Bar After Page Fully Loaded

How do you show a progress bar when something has partially loaded, and get rid of it on the same page when it is done loading?

<?php
echo "<div id='a'><center>Processing Data<br>";
echo "<img src='http://www2.bulkregister.com/images/progressbar.gif'">;
echo "</center></div>";
flush();
sleep(5);//do real work or just sleep (for testing)
echo "Afterwords: <br>";
$js="'document.getElementById(\"a\").style.display=\"none\"'";
echo "<img src='http://www.cwts.nl/ed/buttons/completed.gif'
onload='$js'>"
;
?>

Thursday, November 17, 2005

HUMOR: Switch to Linux Cartoon

http://www.ubergeek.tv/article.php?pid=54 has a nice flash cartoon advertising the benefits of linux.

For the true geek/nerd in all of us.

Monday, November 14, 2005

REG: Remove Dangling Shared Folders in XP

Problem:
On my local area network (LAN) in windows, I had shared a folder, then deleted it. From another machine, it still shows that the folder is shared, yet is inaccessible, how can I remove it?

Solution:
Windows settings are in the registry editor. This includes shared folders which are just keys in the registry.

In Windows, in your Start Menu, click on [Run], type "regedit" and click OK. Using the registry key below, you can find your a registry entry for your shared folder. Remove the registry entry/key with your shared folder's name and it will remove the shared folder.

HKEY_LOCAL_MACHINE
\SYSTEM
\ControlSet001
\Services
\lanmanserver
\Shares

Tuesday, November 08, 2005

REG: Missing System Tray Icons in Windows XP

If you google the topic you will find this link:
http://www.techzonez.com/forums/archive/index.php/t-16911.html

It looks all professional, but it isn't actually helpful.

The cause of the problem for me was when I was setting automatic login on my laptop to true (with a password), then later going in and disabling the automatic login.

I did however find a solution.

In your registry editor, search for keys named "NoTrayItemsDisplay", and delete them.
ie:

HKEY_LOCAL_MACHINE
\SOFTWARE
\Microsoft
\Windows
\CurrentVersion
\Policies
\Explorer
"NoTrayItemsDisplay"=dword:00000000

or

HKEY_CURRENT_USER
\SOFTWARE
\Microsoft
\Windows
\CurrentVersion
\Policies
\Explorer
"NoTrayItemsDisplay"=binary:00000000


source: http://www.techzonez.com/forums/archive/index.php/t-16911.html

Wednesday, October 26, 2005

SQL: Migrating MySQL scripts to MS SQL

I had some database table creation scripts to migrate from MySQL to MS SQL.

Primary Key:
MySQL allows a primary key on the either of NULL, and NOT NULL declarations.
MSSQL only allows primary keys on fields that are NOT NULL

Date Fields:
MySQL uses a DATE field
MSSQL uses a DATETIME field

Table Creation with AutoIncrement:
MySQL uses keyword AUTO_INCREMENT
example:
CREATE TABLE mytable (
myfield1 integer(12) NOT NULL AUTO_INCREMENT,
myfield2 CHAR(9) NULL,
myfield3 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


MSSQL uses keyword IDENTITY(1,1)
example:
CREATE TABLE mytable (
myfield1 int IDENTITY(1,1) NOT NULL,
myfield2 CHAR(9) NULL,
myfield3 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


Create Table 'IF NOT EXISTS'
MySQL uses keywords IF NOT EXISTS
example:
CREATE TABLE IF NOT EXISTS mytable (
myfield1 CHAR(9) NOT NULL,
myfield2 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


MSSQL uses a query into a system table
example:
IF NOT EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mytable')
CREATE TABLE mytable (
myfield1 CHAR(9) NOT NULL,
myfield1 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


More information on autoincrement fields in MSSQL can be found at
an article on http://www.databasejournal.com

HUMOR: Anti- telemarketer Strategy (Counterscript)

http://www.xs4all.nl/~egbg/counterscript.html

A script to use vs. telemarketers calling to harrass you.

Monday, October 24, 2005

CSS: Force a Fixed Width HTML Webpage

Cross-browser content layout fix for variable-length content using CSS

BACKGROUND:
Firefox browser page has no vertical scrollbar unless the content exceeds the browser window height. IE always has a vertical scrollbar, it is merely greyed out when the content doesn't exceed the browser window height.

PROBLEM:
This can be a problem if you have some centered content in pages with the same layout but some content fits in the browser window and on other pages the content is taller than the window. Navigating from one page to the other appears as if the centered content is misaligned.

SOLUTION:
Include this stylesheet in your html code of the webpage to force a scrollbar even when its not necessary, for regular width pages.

<style type="text/css">
html { height: 100.1%; }

</style>

Friday, October 21, 2005

JAVASCRIPT: Make a pop up window

The following HTML code:

<form><input type=button value="Open new window"
onClick="myRef = window.open(self.location,'mywin',
'left=20,top=20,width=800,height=500,toolbar=1,
resizable=0');myRef.focus()"
></form>


Generates this: