Tagged: php

if ($num == (int) $num) {
//It’s whole
}
else {
//It’s not
}

So simple… more here



Put

enctype="multipart/form-data"

in your form tag.

More info

In PHP4, constructor has same name as class:

class Welcome {
function Welcome() {

}}

In PHP5, constructor is always __construct():

class Welcome {
function __construct() {
}}

In PHP4, when you extend you call parent constructor like:

class Welcome extends Parent{

function Welcome() {
parent::Parent();
}}

In PHP 5, you extend like:

class Welcome extends Parent{

function __construct() {
parent::__construct();
}

I am using PHP5 but I was using PHP4 to extend my classes. Lovely!

Since I started working on my project, I have been realizing that I am coding like I did back in college. I am writing everything from scratch. Keeping everything neat and clean as if I will be submitting my project to a professor for a grade. So far I have been working on common tasks like user registration, session control, searching Amazon. I really want to get to exciting parts of programming core logic of my application. But I want to do everything my way. I like simplicity. I don’t want to learn someone else’s library. I guess I don’t mind re-inventing wheel.

IMG_7987

At SXSWi, I discovered Facebook Connect. I fell in in love with it. My target demographics are same as Facebook’s. Facebook Connect can take care of user registration and session management.

Then I started working on Amazon web services part. Getting data from Amazon is easy but exciting. But ten other tasks like input validation, caching, parsing response and other tasks are boring.

Yesterday, somewhere on web I read about CakePHP. Since then I have been looking into different PHP Frameworks. Most of the time I was looking for reasons not to use any Framework. How can I trust someone else’s code. But then I saw this presentation and this convinced me to use frameworks.

Here are 2 main points that convinced me:

  • Do I want to make a wheel or a car? When I have an idea for car why waste time re-inventing wheel. Basically, the awesomest registration system is not my main product. Any generic system customized a little bit to my needs will do.
  • Frameworks will make me organized. Most frameworks use MVC pattern. These frameworks will force you to organize your files better. This will help in long run. For example, if I hire someone, I can tell them to read framework’s documentation. This way I won’t have to explain everything. (I know I should comment my code too).

So which framework to use?

My choice right now is Code Igniter. It is one of the simplest PHP framework. I read documentation, and everything just made sense. Installation seems easy. (I haven’t tested it yet.) There seems to be good community around it. Then it is also one of the lightest and fastest PHP framework. Supposedly, you can use many libraries from other framework with Code Igniter too.

Other frameworks, I want to test out soon are CakePHP and Zend Framework.

Just found out that PHP has totally different variable scope than Java. In PHP you have specify global keyword inside the function not outside. I am so used to Java type variable scope.

For more info read here

Here is some updates: Users can add or update their reviews of stuff. Check it out here: http://chaosplay.com/facebook/Stuff/index.php

It’s still in development, so please excuse any bugs right now.

Thanks

» Continue Reading…

My PHP has gone rusty. I have been spending a quite bit of time research different syntax for PHP. Anyways, now my app has just one basic ability, check to see if user is a new app user, and if so then gather some basic info in the database.

I have set the app in dev mode, so I don’t think anyone can really add it, (other than developers, of course). But here’s the URL anyways: http://chaosplay.com/facebook/Stuff/.

So let me present to you my database structure for now. It is still evolving:

 » Continue Reading...

Well actually it took much longer than 10 minutes because I got into some issues. First check out my app. It doesn’t do much but its the beginning. The end goal being the dating website.

So here is what I ran into. I followed this tutorial. My webserver uses php4 but the tutorial I got from facebook was for php5. PHP4 does not support try… catch blocks. (I didn’t know that). I had to modify the appinclude.php like this:

//catch the exception that gets thrown if the cookie has an invalid session_key in it
if (!$facebook->api_client->users_isAppAdded()) {
$facebook->redirect($facebook->get_add_url());
}

/*Commented out this section, not sure how to deal with this just yet.

{
//this will clear cookies for your application and redirect them to a login prompt
$facebook->set_user(null, null);
$facebook->redirect($appcallbackurl);
}*/

Then like many other’s I had to upload simplexml44-0_4_4 in php4client directory.

After that it worked like a charm.

So that was the first step towards one of my 2008’s objectives.