Yii 2 – Fix weird page navigation with # (hash) symbol as you go to a new page

By | October 12, 2014

I ran into an issue with Yii 2 where I would click a link, it would go to that link but at the same time on the URL a little # symbol would appear then dissapear. It looks like this causes no issues until you try to navigate back. When you hit back, the page wouldn’t load but the URL would go back. Refreshing would fix it but that still isn’t good.

I figured out that this happened when using Pjax. Make sure that any links in a Pjax block have the data-pjax=”0″ parameter. So the URL would need to be like:

<a href=”/site/home” data-pjax=”0″>Home</a>

This is actually documented in the Yii 2.0 manual so if you are looking for more information you can check there.

Get & Send iPhone Location to Server via JSON with iOS 7

By | October 14, 2013

I recently made an app that gets a user’s location and sends it to our server. The app will update every 1000 meters when it is active and will update only during major changes when it is inactive. The location will not always been 100% correct or up to date (depending on a lot of circumstances) but if you’re wanting to get an approximate location of your users, this should work pretty well.

This code lives in my AppDelegate since I want it to run no matter what they’re doing in my app.

- (void)applicationDidBecomeActive:(UIApplication *)application
// Start location services
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

// Only report to location manager if the user has traveled 1000 meters
locationManager.distanceFilter = 1000.0f;
locationManager.delegate = self;
locationManager.activityType = CLActivityTypeAutomotiveNavigation;

[locationManager stopMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

// Check if running in background or not
BOOL isInBackground = NO;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
isInBackground = YES;
NSLog(@"Location Manager isInBackground: %hhd", isInBackground);

if (isInBackground) {

// If we're running in the background, run sendBackgroundLocationToServer
         [self sendBackgroundLocationToServer:[locations lastObject]];
     } else {
         // If we're not in the background wait till the GPS is accurate to send it to the server
if ([[locations lastObject] horizontalAccuracy] < 100.0f) {
             [self sendDataToServer:[locations lastObject]];


-(void) sendBackgroundLocationToServer:(CLLocation *)location
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
         [[UIApplication sharedApplication] endBackgroundTask:bgTask];

     // Send the data
     [self sendDataToServer:location];

     if (bgTask != UIBackgroundTaskInvalid) {
         [[UIApplication sharedApplication] endBackgroundTask:bgTask];
         bgTask = UIBackgroundTaskInvalid;

-(void) sendDataToServer:(CLLocation *)newLocation
    NSLog(@"Sending Data to Server");
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // I also want to send the battery level to the server. Get battery level
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
    float batteryLevel = [[UIDevice currentDevice] batteryLevel];

    float lat = newLocation.coordinate.latitude;
    float lng = newLocation.coordinate.longitude;
    NSLog(@"Accuracy: %f", newLocation.horizontalAccuracy);
    NSString *userId = [[NSUserDefaults standardUserDefaults] stringForKey:@"userId"];

    // This is the data I am sending to the server
    // I am sending a userID that the server recognizes
    // I am sending the latitude and longitude of the user as well as their speed course and battery life
    // I am also sending the horizontal & vertical accuracy so I can see how accurate the gps location was
    NSString *post = [[NSString alloc] initWithFormat:@"login_id=%@&latitude=%f&longitude=%f&speed=%f&course=%f&battery_level=%f&horizontal_accuracy=%f&vertical_accuracy=%f",
       [newLocation speed],
       [newLocation course],

     NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

     NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
     NSString *urlstring = [NSString stringWithFormat:@"%@webservice/post_logins_location.php", kBaseURL];
     [request setURL:[NSURL URLWithString:urlstring]];
     [request setHTTPMethod:@"POST"];
     [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
     [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
     [request setHTTPBody:postData];

     NSError *error;
     NSURLResponse *response;
     NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

     if (!error) {
         jsonResults = [NSJSONSerialization JSONObjectWithData:urlData options:kNilOptions error:&error];
         NSLog(@"GPS Send results: %@", jsonResults);
    } else {
         NSLog(@"Error sending GPS data to server");

- (void)applicationDidEnterBackground:(UIApplication *)application
    NSLog(@"Went to Background");
// Only monitor significant changes
    [locationManager startMonitoringSignificantLocationChanges];

I chose to use startMonitoringSignificantLocationChanges when in the background. From what I’ve read this only updates when the phone changes radio towers and is not very accurate. For my purposes, this was fine. I’m just trying to get an idea on where the phone is.

And that should do it. Please let me know if I have any syntax errors (I’m sure I do).

Error 691 when connecting through VPN on Windows 8

By | January 22, 2013

After upgrading to Windows 8, I ran into an issue where I couldn’t VPN into my old Windows Server 2003 machine anymore. I kept getting this error:

Error: 691: The remote connection was denied because the user name and password combination you provided is not recognized, or the selected authentication protocol you selected is not permitted on the remote access server.

I know that my username and password is correct so I figured it must be something else. Turns out, it’s an easy fix.

  1. Open your VPN connections properties.
  2. Go to the security tab
  3. Check “Allow these protocols” and make sure “Microsoft CHAP Version 2″ is checked

    Fixing VPN Error 691 in Windows 8

    Select the radio button for “Allow these protocols”

  4. That’s it

I’m guess this is a bug of some sort. Once you select one of the two radio buttons, you can’t deselect them which leads me to believe that it is a bug. Hopefully this will be fixed in an upcoming Windows update.

Java not working in Chrome on OS X (Lion)

By | August 19, 2012

If you have upgraded your browser to Lion, you have probably noticed that Java doesn’t run in your browser anymore. From what I can tell, it doesn’t run in any browser. It’s a pretty easy fix.

Open terminal and type:

/Applications/Utilities/Java\ Preferences.app/Contents/MacOS/Java\ Preferences
 This will downloading some files and do an installation. Once it is complete, the Java Preferences will appear. In Java preferences, check the box that says “Enable applet plug-in and Web Start applications.”
Click "Enable applet plug-in and Web Start application"

Click “Enable applet plug-in and Web Start application”

Once you do this, Java should be working in your browsers.

WordPress hack that only displays for Google

By | May 28, 2012

It took me a minute to figure out this one. I noticed when I searched for my blog in Google and it returned no results. So I searched for “site:www.keithslater.com” and it brought up my site however it was showing a lot of results for “Amoxicillin.” Obviously I don’t talk about amoxicilin so I figured it was hacked.

Amoxicillin results from Google

The interesting thing about this hack is, it only displays the amoxicillin results for Google. When I, or anyone else goes to the blog, it displays everything correctly.

Fixing this hack was really simple. All I had to do was upgrade WordPress to the newest version. Now I just have to wait for Google to re-crawl my site and it should be back to normal. Luckily this is just my personal blog and not a client’s site. On a client’s site I do make sure to upgrade WordPress as frequently as possible.