thecodify.com

Random Thoughts, Ideas, and Help Tips - From a PHP Developer

PhoneGap / Cordova 2.0

I recently developed an Android app using PhoneGap.  Although, my ultimate goal is to develop native Java code for android and native objective-c for iOS apps, PhoneGap allowed for a very quick and easy way to develop an application to hook up to an existing web service for user login authentication and much more.

PhoneGap is a free and open source framework that allows you to create mobile apps using standardized web APIs for the platforms you care about. — phonegap.com

This app does not take full advantage of all the device features like the camera, GPS, and others, however it does utilize the push notification system, which is a great way to keep your users engaged in what you offer.  I have plans to implement features like camera, contacts, compass, and more.

My overall experience with PhoneGap itself has been fine.  The issues I’ve been running into are the PhoneGap plugins, which are created by other developers. Nearly every plugin I’ve installed was developed prior to PhoneGap / Cordova 2.0.  In the newer release of Cordova 2.x they changed a decent amount on how plugins are called.

Example:
The main class to extend when developing a plugin in earlier versions was called “Plugin”, now it’s called “CordovaPlugin”.  So of course, I don’t like to see deprecated messages with my code, I start converting over all the code to be updated to the newest version, which means I’m re-writing a lot of code.  The way I look at it, it’s giving me good experience developing native code :)

In the end, I’m happy to finish the application and plan on writing more with PhoneGap in the future.  Only time will tell when I write my first full application in pure native code.

Posted in: Android, CSS, iOS, Javascript & Jquery, Mobile

Leave a Comment (0) →

Where does time go?

Wow, it’s been a long time again.  It’s amazing how fast time goes when you are busy, not to mention having four children :)

There’s not much to report other then I’m still here, still programming, but way too much going on :)

Posted in: Miscellaneous

Leave a Comment (0) →

Twitter Bootstrap

Once again, I’m always looking for cool tools and resources out there to help make my life easier.  A buddy of mine mentioned Twitter Bootstrap a couple days ago, and of course I go and download it and begin testing it out.  It took me all but 15 minutes or so to have a functional layout in place which had responsive CSS already in place.  Of course that 15 minutes includes just using their sample template with no customizations done to it.

I can see how it can speed things up A LOT, once you get to know all their class names.  Their class names are the driving force behind the entire thing.

This page here: http://twitter.github.com/bootstrap/scaffolding.html sums it up very nice.  Overall, I’ll continue to use Twitter Bootstrap so my next project I can make an educated decision on what layout/template/css route I would like to take, right now I’m leaning towards Bootstrap :)

Go To Twitter Bootstrap

Posted in: CSS, Javascript & Jquery

Leave a Comment (2) →

MongoDB vs MySQL – My Personal Thoughts

In the past year or so, I’ve been really trying to open my mind to other languages and technologies available. Today, I started taking a course on MongoDB.  Initially, I thought, what a great concept… I get all the scalability and it’s all JSON based.  The more I courses I took, I thought of a lot of different ways to use MongoDB.

I thought to myself, ok what are the downsides, so I started doing some Google searches and sure enough I found some really interesting debates on MongoDB vs Mysql.  Overall, what I found and agree with is depending on the scope of your project and what it’s needs are will decide what option you would choose.  Although, in my personal opinion MySQL is good for both small and very large projects.

A big downside for me between the 2 is the fact that MongoDB does not support transactions.  It’s said that MongoDB is MUCH, MUCH faster then MySQL, however they meet those impressive benchmarks with a possibility of something going wrong.  I don’t know about you, but I like the idea of a nice stable transactional system like MySQL.

It could simply be that I am not experienced enough with MongoDB yet,  I’m simply reporting what the majority of the research showed me.

I’ll continue to learn MongoDB, it’s always good to expand knowledge into other areas.

Posted in: MySQL, PHP

Leave a Comment (0) →

EZ Staff List 0.6 Released!

I know, I know, it’s about time!  Sorry for the delay, I’ve been pretty busy lately and just recently found the time to make some important and much needed updates.

Here are the recent changes:

  • NEW – Added functionality to not display the the hours for a staff member. Just leave the field blank to not show on the site
  • NEW – Choose number of columns to display staff under the “Layout Options”
  • NEW – Added color pickers for background color, border color, and font color under the “Layout Options” menu.
  • NEW – Added “Update Order” message
  • FIXED – Fixed bug when trying to remove staff members
  • UPDATED – Updated Framework Version

Download Latest Version Here

Posted in: EZ Staff List, Wordpress Plugins

Leave a Comment (4) →

Importing CSV file into mysql table

I had a few problems when trying to import a CSV file which had quotes for the fields. It was inserting each quote as part of the value.  I know you can get around that with msyql, but there is a way to search and replace the quotes with nothing with the following linux command:

sed s/\"//g file_name.csv > new_file_name.csv

Once you are done with that, then you can log into your mysql server via shell then run the following command:

LOAD DATA LOCAL INFILE 'new_file_name.csv' INTO TABLE {yourtablename} FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (yourfield1,yourfield2);

 

That’s it.

Posted in: MySQL

Leave a Comment (0) →

php curl Request Entity Too Large

Just thought I would throw this one out there.  I was currently working on a PHP 5.3+ install on my mac OSX Lion and experience the following error:

The_requested_resource does_not_allow_request_data_with_POST_requests,
_or_the_amount_of_data_provided_in the_request_exceeds_the_capacity_limit_

I did some research to find a solution, and there were a few of them out there, but nothing that was helping me.

Here’s what my cURL looked like:

$ch = curl_init($process_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$results = @curl_exec($ch);

Typically I pass in some $_POST vars, but this time I was only using $_GET query string.  So, I simply removed this line:

curl_setopt($ch, CURLOPT_POST, 1);

Then it worked!  I hope this helps someone in the future.

Luke

Posted in: Linux - Apache, PHP

Leave a Comment (1) →

How to secure and block others from using and viewing your CSS styles

So I recently found out that another website out there was setting up a phishing site which looked identical to one of my other sites.  So of course, the first thing I did was changed my CSS files to another file name, but kept the old one and ONLY had the following definition in there:

body:before {
   content: 'This website is a scam!';
}

body {
   display: none;
}

 

So that took care of that… but now on to the part where we get secure…

Follow the following steps to setup your secure CSS styles:

  1. Create a php script (I called my get_styles.php) and put the following code in there:
    header("Content-type: text/css");
    
    $allowed_servers = array('http://yourdomain.com');
    
    $status_array = array();
    if (!empty($_SERVER['HTTP_REFERER']))
    {
    	foreach($allowed_servers as $server)
    	{
    		if (contains($server, $_SERVER['HTTP_REFERER']))
    		{
    			$status_array[] = 'ok';
    		}
    	}
    }
    
    if (!in_array('ok', $status_array))
    {
    	print "
    		body { display: none !important; }
    	";
    	exit;
    }
    
    // load the base / core files no matter what
    // These are the files which you want to load on a global level
    // A lot of sites typically have only one file called "styles.css" 
    // or something along those lines
    // I recommend calling it something else, most people would guess that
    // I called my below "global_styles.css"
    // Note: This script assumes it's located in the same directory as your CSS files
    $core_files = array('global_styles.css');
    foreach($core_files as $file)
    {
    	// get the contents
    	print file_get_contents(dirname(__FILE__) . '/' . $file) . "\n";
    }
    
    /**
    * Checks to see of a string contains a particular substring.
    *
    * @param $substring the substring to match
    * @param $string the string to search
    * @return true if $substring is found in $string, false otherwise
    */
    function contains($needle, $haystack)
    {
    	if (empty($needle)) { return false; }
    	$pos = strpos($haystack, $needle);
    	if($pos === false) { return false; }
    	else { return true; }
    }

     

  2. Once you have your script setup above, then next step is pretty simple.  Call your CSS file which you created above…
    <link href="/css/get_styles.php" rel="stylesheet" type="text/css" media="all" />

     

  3. If you try to access http://mydomain.com/css/get_styles.php you will find there are no css styles from being displayed.

Please note: There are still ways for people to find the generated styles by using developer tools such as Firebug.  I have some javascript which will detect if the Firebug consule is open and if it use, clear the body.  Contact me if you’d like that code too.

You may also want to require Javascript in order to load your CSS file as well.  Contact me on how to do this too :)

 

Posted in: CSS, PHP

Leave a Comment (0) →

How to Debug MySQLi Bind Parameters

Using MySQLi and bind parameters were a little bit of a change for me as I’m sure it was for others as well.  Once you understand how it works, it’s not really too bad.

One thing I’ve found while doing some research, I’ve noticed a lot of others wondering how to output the “old style” SQL statement when using bind parameters.  See the 2 functions below to do just that :)

 

<?php

$sql = "SELECT * FROM contacts WHERE email_address IN (?,?) AND group = ? ";
$email1 = 'luketesting@gmail.com';
$email2 = 'luketesting2@gmail.com';
$group = 2;
$bind_params = array('ssi', &$email1, &$email2, &$group);

print display_bind_params_sql($sql, $bind_params);

/**
* Returns an "old style" sql statment from an incoming bind params / prepared sql statment
*
* @param string $query The prepared sql statement with the ? in place
* @param array $bind_params The bind params array
*/
function display_bind_params_sql($query, $bind_params)
{
    // Get the data types...
    $data_types = $bind_params[0];
    array_shift($bind_params);

    foreach($bind_params as $key => $param)
    {    
        switch($data_types[$key])
        {
            case 'i':
                $query = str_replaceFirst('?', $param, $query);
                break;

            default:
                $query = str_replaceFirst('?', "'" . $param . "'", $query);
                break;
        }
    }
    return $query;
}

/**
* Replace the first occurance in a string
*
* @param string The string to replace
* @param string The string to replace with
* @param string The string we are checking
*/
function str_replaceFirst($s,$r,$str)
{
    $l = strlen($str);
    $a = strpos($str,$s);
    $b = $a + strlen($s);
    $temp = substr($str,0,$a) . $r . substr($str,$b,($l-$b));
    return $temp;
}

?>

I hope this helps someone looking for a little more “familiar” debugging information.

 

 

Posted in: MySQL, PHP

Leave a Comment (0) →
Page 1 of 2 12