Coding, content and startups

James Crowley

Running OpenX under IIS with PHP 5.3 – date_default_timezone_get errors

with one comment

I run OpenX (an open source ad serving platform) under IIS and PHP …. but after upgrading to PHP 5.3 noticed the following error appearing in the PHP error logs file (c:\windows\temp\php-errors.log by default).


PHP Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for '1.0/DST' instead in C:\inetpub\wwwroot\openx-2.8.5\www\delivery\spc.php on line 191

The solution to make this error go away is simply to specify a default timezone in the php.ini configuration file. In my case this looked like:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/London"

September 12th, 2010 at 9:50 pm

Posted in Coding,PHP

PHP 5.3 and IIS 7 – beware of MySQL issues with IPv6

without comments

I’ll keep this short and sweet as it’s covered in depth elsewhere. After installing PHP 5.3 suddenly my website stopped working – but instead of throwing errors, it simply sat there and eventually timed out (with no error). Turns out there are issues with both PHP and MySQL around IPv6. The most common solution is “turn off IPv6 support” – not a reassuring answer.

On the PHP front, the issue seems to be around fsockopen which works fine in 5.3.0 but not in 5.3.2. The major issue for most people though is that the MySQL driver doesn’t properly support IPv6 if you’re using a hostname (such as localhost) to connect instead of an IP address, particularly when localhost resolves to “::1″.

I’m not sure what changed in PHP 5.3.2 to bring this to the surface, but the solution is either to switch to using an IP address, for which there are other good reasons to do so, or modify your hosts file (c:\windows\system32\drivers\etc) and change the line the starts with “::1 localhost” to “#::1 localhost”.

Hope this helps someone!

September 6th, 2010 at 8:02 am

Posted in PHP

Beware: Upgrade to ASP.NET MVC 2.0 with care if you use AntiForgeryToken

with 3 comments

If you’re thinking of upgrading to MVC 2.0, and you take advantage of the AntiForgeryToken support then be careful – you can easily kick out all active visitors after the upgrade until they restart their browser. Why’s this?
For the anti forgery validation to take place, ASP.NET MVC uses a session cookie called “__RequestVerificationToken_Lw__”.

This gets checked for and de-serialized on any page where there is an AntiForgeryToken() call. However, the format of this validation cookie has apparently changed between MVC 1.0 and MVC 2.0.
What this means is that when you make to switch on your production server to MVC 2.0, suddenly all your visitors session cookies are invalid, resulting in calls to AntiForgeryToken() throwing exceptions (even on a standard GET request) when de-serializing it:

[InvalidCastException: Unable to cast object of type 'System.Web.UI.Triplet' to type 'System.Object[]'.]
System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(String serializedToken) +104

[HttpAntiForgeryException (0x80004005): A required anti-forgery token was not supplied or was invalid.]
System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(String serializedToken) +368
System.Web.Mvc.HtmlHelper.GetAntiForgeryTokenAndSetCookie(String salt, String domain, String path) +209
System.Web.Mvc.HtmlHelper.AntiForgeryToken(String salt, String domain, String path) +16
System.Web.Mvc.HtmlHelper.AntiForgeryToken() +10
<snip>

So you’ve just kicked all your active users out of your site with exceptions until they think to restart their browser (to clear the session cookies).

The only work around for now is to either write some code that wipes this cookie – or disable use of AntiForgeryToken() in your MVC 2.0 site until you’re confident all session cookies will have expired. That in itself isn’t very straightforward, given how frequently people tend to hibernate/standby their machines – the session cookie will only clear once the browser has been shut down and re-opened.

Hope this helps someone out there!

March 18th, 2010 at 1:02 pm

Posted in ASP.NET

Including Spark views in VS 2010 web deployments

without comments

Visual Studio 2010 includes much improved deployment tools – but by default it only includes files “needed to run this application”. If you’re using the Spark view engine for ASP.NET MVC, then the Spark views aren’t considered one of them!

The trick is to ensure your .spark views have a build action of “Content” instead of the default “None”. Clearly remembering this each time would get somewhat tedious, so instead you can add the following registry entries:



Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0Projects{F184B08F-C81C-45f6-A57F-5ABD9991F28F}FileExtensions.spark]
"DefaultBuildAction"="Content"

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0Projects{FAE04EC0-301F-11d3-BF4B-00C04F79EFBC}FileExtensions.spark]
"DefaultBuildAction"="Content"

(just add this to a .reg file and run it)

March 17th, 2010 at 7:29 pm

Posted in ASP.NET

developerFusion community relaunches

without comments

As some of you will know, I’ve run the developerFusion community for many years now, as a part-time hobby. Now, some big changes are afoot! 2 months ago I packed in my day job to focus on the site full-time, and have now made the first big step and re-launched the site.

You can check it out at http://www.developerfusion.com/.

This is just the first step along the road, but an exciting one (for me at least!). The new site is going to make it even easier for developers around the world to connect with each other, and discover what’s going on in their local area – be that events, user groups, blogs or just general discussion. We’ll also be bringing a wider range of technical articles and focused developer news.

If you have any feedback, feel free to get in touch – the site is here for you! If you twitter, stay tuned at http://twitter.com/developerfusion for more updates.

October 4th, 2008 at 10:12 pm

Posted in Coding

UrlRewriting, .NET 2.0 SP1 and Search Engines

without comments

Having been caught out by this issue once again this weekend, I thought I’d better blog about it so I don’t scratch my head searching around again for a third time!

If you’ve been getting some wierd “Cannot use a leading .. to exit above the top directory.” exceptions occuring on your site (you *do* log those, don’t you?), that you can’t reproduce in the browser, stay tuned. The issue crops up with URL Rewriting in .NET 2 SP1 – and the reason I’ve hit this again is when our production server was upgraded to .NET 3.5… evidentally this installed the service pack as a side-effect. So much for our patching strategy.

Anyway, this triggered a flow of errors for “Cannot use a leading .. to exit above the top directory.”, all stemming back to a call to System.Web.Util.UrlPath.ReduceVirtualPath – but apparently only for particular visitors to the site – specifically search engine bots, including Googlebot. The issue occurs, as far as I understand, because .NET is specifically targeting code to particular browsers – in this case, I believe the issue results because it knows the user-agent doesn’t support cookies, and is therefore trying to work accordingly.

There are two workarounds out there.

1. In your web.config,add the following:

<authentication mode="Forms">
            <forms cookieless="UseCookies" />
</authentication>

This will bypass the issue entirely – by telling .NET to always use cookies for authentication – but if you require forms authentication to work in a cookie-less scenario,then this won’t work. So, on to option number 2

2. Create a .browser file to match the user agents that are causing the issue. Check out this article that describes how.
 

May 26th, 2008 at 5:05 pm

Posted in Uncategorized

MasterPages, ViewState and web.config files

without comments

protected override void OnInit(EventArgs e)
        {
            // we use this so that we can set the enableViewState property in the web.config
            // although it sets it at the page level, it doesn’t pass it on to the master page
            this.EnableViewState = this.Page.EnableViewState;
            base.OnInit(e);
        }

February 5th, 2008 at 1:04 pm

Posted in Uncategorized

Get your tech events featured on MSDN UK and TechNet UK!

without comments

This announcement is well overdue, but better late than never!


After much hard work by the DPE team at Microsoft in the UK – thanks in particular go out to Clare – we’ve now integrated the Developer Fusion events feed with the Microsoft UK community pages. This means that anyone who submits a Microsoft technology-related event to Developer Fusion will also automatically appear on the MSDN and TechNet community pages too – talk about some great free exposure!


Any events on Developer Fusion also get automatically posted to Upcoming.


I’m also working with the larger user groups in the UK to ensure we can automatically pull in their events through the same feed format. If anyone would like more info on this, just get in touch.

January 26th, 2008 at 4:14 pm

Posted in Uncategorized

Gotcha: "The specified metadata path is not valid." with ADO.NET Entities on Vista x64

with 4 comments

For those of you foolhardy enough to be running Vista x64 (myself included!), VS 2008, and the latest build of the ADO.NET Entities framework… you may well hit the following error message:


The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension ‘.csdl’, ‘.ssdl’, or ‘.msl’, or a URI that identifies an embedded resource.

The catch is that apparently the designers are not supported on 64-bit machines. The workaround is to copy two files from %windir%Microsoft.NETFramework64v3.5 to %windir%Microsoft.NETFrameworkv3.5:


  • Microsoft.Data.Entity.Build.Tasks.dll


  • Microsoft.Data.Entity.targets

then restart Visual Studio and rebuild your solution.


Thanks to Tommy Williams @ MSFT (found on the forums)

January 26th, 2008 at 4:09 pm

Posted in Uncategorized

Shared Printers across Windows Vista and Windows XP

with 7 comments

Since getting a shiny new machine running Vista, I’d been having a bit of grief trying to get it to print to my Canon i6500 printer shared through another Windows XP machine. Vista has built-in support for the printer (running locally), but when trying to add it across a network, as the XP machine could not supply the correct 64bit Vista drivers, the Vista machine wasn’t too happy – pointing to the correct location of the local device drivers didn’t help either!


After sifting through various solutions – this was the one that worked for me.


On the Vista machine, 


- Choose to add a local printer
- Create a new local port, and set its name so it matches the network share (\servername)
- Manually select the appropriate printer driver from the automatically supported set (or select an appropriate vista driver)


This then tricks Vista into thinking we have a local printer – so it can install the correct drivers – that actually redirects to the network printer.


I think this should work in the reverse direction too, if Windows XP is geting upset printing to a device shared through Vista.


Hope this helps someone!

October 28th, 2007 at 2:50 pm

Posted in Uncategorized