Larry Brouwer

…just my technology sandbox …for my personal amusement only!

Browsing Posts in Daily Log

PHP Random Key Generator

No comments

Yesterday, I needed a way to generate a random alpha-numeric key of various lengths using PHP for a project that I’m currently working on. I didn’t find any built-in functions, so after some Googling, I decided to implement my own version.

    private function generateRandomKey($len)
    {
        $chars = array('1','2','3','4','5','6','7','8','9','0',
        'a','b','c','d','e','f','g','h','i','j','k','l','m',
        'n','o','p','q','r','s','t','u','v','w','x','y','z',
        'A','B','C','D','E','F','G','H','I','J','K','L','M',
        'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        $min = 0;
        $max = sizeof($chars)-1;
        $key = "";

        for ($i=0;$i<$len;$i++) {
            $key .= $chars[mt_rand($min,$max)];
        }
        return $key;
    }

Let me know if anyone has a better suggestion?

Today, I’m attempting to install OpenCart, an open source ecommerce package. OpenCart was chosen as the runner-up of the 2010 Open Source Awards as published by Packt Publishing.

I first looked through the OpenCart Online Documentation. The most current stable release as of this writing is OpenCart v1.4.9.3. OpenCart requires PHP, and MySQL. I currently have both installed on my Windows Server 2008 platform. It should also work fine running  under Windows IIS 7.

As a side note, the OpenCart Tools section outlines some great suggestions for free tools. I use some of them, like Jing, others I’m excited to check out.

Installation is pretty straight forward. First, download the software. I usually download to an install directory whereby I can easily start over if necessary. I then used MySQL Workbench to create an “opencart” schema and user.

Next, I created a root folder for the opencart Web Site application to reside. I then copied the contents from the “install\opencart\upload” folder to the “www\opencart” folder.

I then went into the IIS7 Manager and added the new Web Site to port 8002. I also added a binding for the local IP address “192.10.11.21”. I then opened port 8002 on the firewall.

At this point, I pointed my browser to the OpenCart Web Site and with through the installation instructions. This was a simple one step process of entering the database connection and admin account credentials. The last step is to delete the installation folder. I was unable to do this as it was in use. So I shut down the Web Server, renamed the folder, then started it back up again.

The installation should now be complete, however, when I browse to the site, it still attempts to take me to the installation page. After looking at the index.php file, I’ve noticed that it’s looking for a variable ‘DIR_APPLICATION’. This variable should be defined in the config.php file. However, when I look at the config.php file, it’s empty. So there is a problem with the installation.

I immediately think it’s a permission problem. After doing some Googling, I found several posts discussing similar issues, but nothing that definitively solving the problem. I then Googled on ‘ii7 php file permissions’ and the first result answered my question. To implement the solution, I created a “temp” folder under my “www” folder, and then altered the PHP.ini file’s “upload_tmp_dir” variable to point to the new temp file location. I then used file explorer and gave IIS_IUSRS; Read; Write’; List folder contents; Read & execute permissions to the “www” folder and sub-folders. To the “temp” folder, I gave IIS_IUSRS; Full control.

Using MySQL Workbench, I dropped and recreated the “opencart” schema. Using IIS7 Manager, I stopped the Web Service, and deleted the contents of the opencart folder and re-copied the contents back from the install\upload folder. I then re-started the Web Server, and re-ran the installation. This time, it worked fine, and the installation was complete.

After confirming I was able to browse the site, I created a robots.txt file in the root directory to prevent this site from being spidered by Google’s WebBot. Here’s the file:

# go away
User-agent: *
Disallow: /

 

My next hurdle was gaining access to the site administration. The username and password I provided upon installation didn’t seem to work. So I went into MySQL Workbench and looked at the “user” table, in my case the “oc_user” table. I ran a quick update as follows:

use opencart;
update oc_user set password=md5('admin')

That fixed it! I am now able to get signed on to the system. I then began to configure it. That was easy!

I’ll update this post with additional findings as I continue to work with OpenCart.

You’re welcome to view my OpenCart demo site here. It will most likely only be available during the day when I’m at my desk working. If you should need help with your installation, drop me a line. I’d be happy to assist you! Good luck!

I’ve been creating a new Web Site for one of my clients, Clear Lake Auto Service, using WordPress, and the client is wanting to see statistics regarding Web Site traffic. My first thought is to add Google Analytics to the site. Here are the steps I took to get analytics up and running for him.

First, I logged into the WordPress site, and installed the Google Analytics for WordPress v4.0.9.

Second, I created a new Google Analytics account under his Google mail id.

Third, I activated the WordPress plugin, selecting his new account. The plugin automatically verified the Account and Profile to use.

Forth, added my email account as an Administrator to the profile.

That’s it!

I’ve been using Windows Live Writer to create my blog posts, and I’ve just stumbled upon the plugins site for Live Writer, here. I’ll add more to this post as I get more experience with them.

I’ve installed the following plug-ins:

Insert Code for Windows Live Writer

Code Snippet plugin for Windows Live Writer

Today, I discovered that my SmarterMail is acting up again. When I attempted to check my emails, I get a really nice aspx error page.

My first thought is that someone has hacked my mail system, and is sending out spam again. I’ve had this problem before, and outlined the steps I undertook in order fix the problem in my post entitled, SmarterMail Security Lockdown Prodecures.

I shut down the SmarterMail Service and started looking at the mail logs, and event logs. I can see the out of memory errors, but I still don’t know what’s causing the problems.

I then restarted the SmarterMail Service and logged into my account to look at the reports being generated. There is nothing in the reports that are out of the ordinary.

My next thought was to see if I could check out what the overall network traffic looks like. I did a Google search on “network traffic monitor open source”, and I stumbled upon ntop. I installed the demo version, ntop v4.0.3. I wasn’t able to get ntop to work. After some additional research I discovered ntop-extra, but that has been discontinued. I uninstalled ntop and looked for something else.

I next installed, WireShark v1.4.3. After running the program for over an hour, I didn’t see suspicious network traffic. However, I did notice that the SmarterMail MailService.exe program was taking up to 45% CPU and ever increasing amounts of memory (now at 78MB).

At this point, I decided it was time to upgrade to the latest release of SmarterMail. I followed the upgrade instructions by first backing up the data files, then uninstalling the software, then running the installation program.

I am now running SmarterMail v7.4.3995. I will update this post if I continue to have problems. Otherwise, consider this issue resolved for now!

2011-01-14 – Update

The MailService.exe is still gobbling up lots of memory. I’ve verified that the mail system isn’t sending out spam emails, so I’m now looking into possible memory leak issues. I installed the Microsoft Windows SDK for Windows 7 and .NET Framework 4 debugging tools to see if I can spot any problems.

I finally got around to setting up a Microsoft Azure service for doing some cloud test development this afternoon.

After logging into my MSDN account a activating my Azure service, I went into VS 2010 and installed the Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio (November 2010). There are several downloads available.

I had the pleasure of refreshing the development instance of the Harris County Master Gardener’s database this morning. Basically, Dev was getting too old to conduct testing on, so took the most recent Production backup (from last night), and using MS SSMS I was able to restore the database without much incident.

However, my troubles then began when I attempted to pull up the Development Web Site. The application couldn’t connect to the database. I’ve had this type of thing happen in the past, but as usual, I’ve forgotten how to fix it.

After some researching on the Web, I came up with a Microsoft Support Article entitled, Troubleshooting Orhpaned Users, and I was able to fix the problem with relative ease. Look under the section “Steps to Resolve Orphaned Users”.

The following are the steps I undertook:

1. Using MS SSMS, connect to the Sql Server instance where the copied database exists.

2. Open a New Query window and enter: Use DataB go sp_change_users_login ‘report’

3. The stored procedure will display output for all of the affected login’s

4. Open a New Query window and enter: Use DataB go sp_change_users_login ‘update_one’, ‘test’, ‘test’ for each login.

That should fix the problem!

Installed Silverlight 4 Training

Installed Microsoft Silverlight 4 Offline Documentation

Installed WCF RIA Services Offline Documentation

Installed WCF RIA Services Toolkit May 2010

Installed Microsoft Silverlight 4 Tools for Visual Studio 2010

Installed Microsoft Silverlight PivotViewer

Installed Fiddler

While setting up a client for remote desktop using Windows XP Pro to remotely access Windows Server 2008, I discovered that the clients local printers weren’t accessible by the server. After much Google searching, I discovered that (mstsc.exe) RDS 7.0 is now available for XP. This solves the problem with RDS Easy Print. The latest RDS 7.0 is available here.

Here’s a great post that describes Windows Terminal Services Easy Print in detail.

Good troubleshooting tips are provided at Remote Desktop Services troubleshooting.

Update. The client was able to initially print to the local printer after installing the update. However, it was not reliable and the printer did not always show up.

To solve the problem I actually physically connected the printer to the server and installed the drivers from the originally installation disk. The driver downloaded off the Canon website would not install without the printer being physically installed.

After doing this, the printing now works great from Server 2008 to Windows XP Home.

Beginning to learn MVVM.

Installed Reactive Extensions for .Net 4 v1.0.2563.0