Ordinary Web Guy

Simply loving web development goodies

How To (HTTPS) Redirect Signup and Admin Pages Using .htaccess

leave a comment »

“Simple is better than complicated and complicated is better than complex”. I’ve read that quote somewhere in blogosphere and abruptly occupies in my brain. Keeping every logic simple within the code is essential and beneficial not only for a team collaboration setup but also for yourself as a coder. KISS principle could explain it.

I find it pretty simpler and better doing the https/ssl redirect using .htaccess than coding it under your favorite server-side script like PHP, particularly if the application code base is large and has an unorganized lines of code.

With a bit googling skill, below is the formulated code snippet.


RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} signup\.php
RewriteCond %{REQUEST_URI} admin
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain.com/$1 [R=302]

# Redirect non-secured pages to http
RewriteCond %{REQUEST_URI} !signup\.php
RewriteCond %{REQUEST_URI} !admin
RewriteCond %{REQUEST_URI} !\.(gif|jpg|swf|flv|png|js|css) # Consider checking web assets as it should as well redirect back to http
RewriteCond %{HTTPS} on
RewriteRule (.*) http://www.domain.com/$1 [R=302]

Simple right eh?

Written by admin

January 27, 2012 at 5:32 pm

Posted in Apache

Tagged with ,

Compelling Reasons To Use Silverstripe

with 2 comments

Silverstripe is a CMS solution built under sapphire PHP framework. To know more about it please visit http://www.silverstripe.org/.

Now let’s go the main point of this blog post. Here’s the story:

I shouldn’t have been looking for another PHP based CMS solution for my personal projects; totally ditch PHP and try something else like ruby on rails or django. But not until my current company introduces silverstripe, which they extremely use to their prime products and services.

I’ve done several projects using various PHP frameworks like zend framework, codeigniter, symfony and custom one; and also joomla, drupal and wordpress. Believe me or not, silverstripe struck me how compelling it is to work and learn it that I even recommended it to close friends and to the community. It’s like working on ruby on rails (slightly) with the model layer. I’m not going to compare silvestripe with other CMS or any other frameworks out there. I’m just gonna list down here the reasons why you should use it.

1. Framework plus CMS in one equals awesome app.
- Just imagine you got drupal or wordpress built under your favorite PHP framework. Sweet and awesome right? Create and customize functionalities/modules as you’ve used to. And you can also just grab existing solutions http://silverstripe.org/extending-silverstripe/. As perusal, http://silverstripe.org/community-showcase/.

2. OOP Centric / MVC Structured
- Yeah! That’s the buzz word with today’s mainstream frameworks. If you’re already familiar working on with MVC framework, adapting Silverstripe and the learning curve is pretty much the same. Disregarding the setup, installation or configuration. Watch the video here http://vimeo.com/16842606 to fully understand it.

3. Templating
- In relation with item # 2, the separation of concerns; now with the view. The templating system with silverstripe is designed to be as simple as possible. No logics and no complicated statements are allowed on it enforcing those to be in the controller or model because what the view layer should  do is to simply render the html without any complexity. In short, don’t mess with the view. :D

4. Scalability
- Silverstripe cares about the performance of the site specially when it consumes a lot of bandwidth usage from visitors. It’ll not let do the scaling yourself because silverstripe provides caching utilities that should be taken advantage of. They are as follows:

Static publisherhttp://doc.silverstripe.org/sapphire/en/reference/staticpublisher
Template partial caching: http://doc.silverstripe.org/sapphire/en/reference/partial-caching

5. Agile / Test Infected
- The success of this CMS was when they started to implement and support unit testing with the core modules. If you’re not into advocating TDD, silverstripe will transform you into becoming a test infected developer. Get started here: http://vimeo.com/16446690

6. Flexible / Extensible
– Silverstripe has this decorator w/c will extend a certain model or controller class without creating a new subclass of it. This is to primarily avoid hacking/editing directly on modules and core classes. I’m quite guilty about it with some of my past personal projects. Take note that decorator in silverstripe is not the decorator pattern. For reference:
http://doc.silverstripe.org/sapphire/en/reference/dataobjectdecorator
http://api.silverstripe.org/2.4/sapphire/core/Extension.html

7. SEO Support
- Silvestripe doesn’t only helps you develop a site in agile way then scale it easily. It also helps to your site to have a good ranking in google search. Because in the cms backend it encourages one url segment which is actually good in SEO. It also has the googlesitemaps module which included in the default package.

The list above I guess will suffice to some developers to discover those advantages of using this one of a kind, revolutionize and amazing cms. Of course there are still some areas that I don’t like with silverstripe. I’ll be tackling on that into another blog post. What are you waiting? Come on download and try silverstripe. http://www.silverstripe.org/stable-download/

Written by admin

February 11, 2011 at 7:40 pm

Posted in PHP, Silverstripe

Zend_Form a Daunting and Cumbersome Task?

with one comment

Zend_Form is simply the easiest way to generate forms in Zend Framework applications. But what if you have a custom web 2.0 form? Is it still applicable to use? I’ve been into several Zend Framework projects but never came to my mind to utilize Zend_Form. There is a tutorial on how to create custom form decorators but for me it’s a daunting and cumbersome task. But are there still other workaround aside with that tutorial? The answer is “YES” and it’s preposterous that those web projects I made for its forms were made manually specially with the validation. At first place, I’ve never known about it. Sometimes ignorance could lead to catastrophe.

How to do it? See below the trick:

class Application_Forms_ForgetPassword extends Zend_Form {
public function init()
{
$this->setName(‘forgetPasswordForm’);
$this->setMethod(‘post’);
$this->setAction(‘/index/retrieve-password’);

$emailExist = new Zend_Validate_Db_RecordExists(‘users’, ‘email’);
$emailExist->setMessage(‘Email doesn\’t exists.’);

$email = new Zend_Form_Element_Text(‘email’, array(‘size’ => 25));
$email->setLabel(‘Email Address:’)
->setRequired(true)
->addFilter(‘StripTags’)
->addFilter(‘StringTrim’)
->addFilter(‘StringToLower’)
->addValidator($emailExist)
->addValidator(‘NotEmpty’)
->addValidator(‘EmailAddress’);

$this->addElements(array($token, $email));
$this->setDecorators( array( array(‘ViewScript’, array(‘viewScript’ => ‘index/forget-password.phtml’))));
}
}

Here’s only the messy part with view.

<form action=”<?php echo $this->escape($this->element->getAction()); ?>” method=”<?php echo $this->escape($this->element->getMethod()); ?>” id=”forgetPasswordForm”>
<h2>Forgot Password</h2>
<?php echo $this->formLabel($this->element->email->getName(), $this->translate($this->element->email->getLabel())) ?>
<br />
<?php echo $this->formText($this->element->email->getName(), $this->element->email->getValue(), $this->element->email->getAttribs())?>
<div><a href=”#”>Send</a></div>
</form>

So Zend_Form is not daunting and cumbersome task for custom forms it’s indeed a time saver.

Written by admin

September 25, 2010 at 6:40 pm

Posted in PHP, Zend Framework

How to Install Android Applications using Android SDK?

with 2 comments

Yoohooo! Finally! I recently got my android phone (samsung spica) w/ eclair.  One of the cheapest android phones available in the market as of writing this post. I wanted to try something new to learn and develop mobile applications using java then definitely phpforandroid. The whole universe is going through mobile (actually we are now). And sooner or later I’ll might get a job for a mobile company developing mobile applications. Imagine how powerful that tiny piece of object is and what it can do more to alter our daily life.

What will you do first for a new phone? Test the basic functinalities (SMS, MMS and call). Then afterwards install new applications right? The power of android is undeniably great. It’s free w/ a great tool, lots of free apps and you can maximize the services of Google. What could you ask more? I have and it really frustates that I almost regretted buying an adroind phone (but not now). Simply because it can’t detect wifi connections through ad-hoc. I felt that I was hit by a huge stone on my head. Aaarrggghhh!!!! What a pain! But after several keystrokes googling for a solution. I found a way to install new applications on android phones. It’s thru Android SDK.

Here are the steps I did.

1. Download Android SDK. http://developer.android.com/sdk/index.html
2. Extract and click on “SDK Setup.exe” file.
3. Be sure to include installing the usb driver via checking on ‘Usb Driver’.
4. Select “Accept” option then click on “Install” button. (This will take a time).

When done, now it’s time to set the phone.
5. Install the driver that comes in the phone package.
6. Connect the phone to the PC thru USB.
7. In the phone, go to Settings -> Applications -> Development.
8. Check on “USB debugging” (Now the PC will detect the device. Be sure to install the android driver in “/PATH/TO/ANDROID/SDK/usb_driver” path).
9. Download new apk files. You can find some here http://forum.mobiles24.com/forumdisplay.php?f=59.
10. Run cmd, traverse SDK path by typing “cd /PATH/TO/ANDROID/SDK/tools”.
11. Type “adb install /PATH/OF/THE/DOWNLOADED/APK/android_app.apk”. You should now see “Success” message.

Viola! Double check in the phone if it’s installed then have fun.

I will expect that Android OS will do something about the problem detecting wifi connections thru ad-hoc. Hopefully on its next stable release version. iPhone doesn’t have that issue. Also with Nokia and Samsung w/ different mobile OS. So please please please do something with it Android Guys!!!

Written by admin

August 6, 2010 at 6:21 pm

A New Leaf

with one comment

Let me start by defining a leaf. A leaf literally is what trees and plants has. We can identify what kind of a tree/plant by it’s leaf. It could be small,big or long that symbolizes something. Every season, trees/plants start to sprout new leaves. What does it means? It means a fresh new start to deal the whole new around season. To overcome every struggles. The heat of the sun, the wind, the rain, and the storms. And that’s what I am currently at.

But consistently for every two years (unlike trees, they change leaves every year). Yes a new job for every two years. I can’t deny that I’ve learned a lot with my previous company but there are tremendous new stuffs to explore. I am a learner, programmers are learners. I’ll be joining my new company this week. It’ll be a new exciting learning experience to enhance my skill sets through work. To learn with the geekiest people around the company and to also share every bit of knowledge I got.

Here’s are the list I’m expecting to explore more:

  • Automated Testing / Unit testing / JIRA
  • Strict SCRUM Implementation (My previous company uses SCRUM BUT and it sucks)
  • New Framework
  • Coding Standards and Convention
  • and generally adherence of best practices in web development….

I also expect and hope to get a whole two years or more adventures with my new company. Wish me all the luck!

Written by admin

July 11, 2010 at 4:00 pm

Posted in Programming, Self

Will Code for Food and Suck on it

with 4 comments

“When you are trying to make a living, there ain’t no such thing as pride.”

This had been one of my favorite quotes originally from Hasin w/c I could relate much because same as Hasin, I’m also a family man and as a family man I should make a living for the future, for my beloved wife and adorable son.

From almost 5 years professional experience, I’ve been working into 4 different companies. All these companies I’ve been into hell-of-a-maintenance-projects or same-old-projects doing the same projects all over again that felts boring and you-can’t-work-on-it-coz-your-damn-tired. Then the only way you think you can escape w/ it is to explore for a new job. While it’s very true, what if you can’t find any decent job for a long period of time? What you’ll do? Continue to suck at work? Quit? Nah!!! If you look at the brighter side, those acts are such selfish / self-centered, childish and pathetic. Remember that we’re working for that job no matter how exciting or boring the projects are. To avoid those unavoidable acts and my mantra on it, I always keep in my mind “When you are trying to make a living, there ain’t no such thing as pride”. That’s enough for me to do the work done. I’ll code and suck on it for food. Leave that pride behind until you get that right winning job.

Quitting a job without securing for another job is a risk if you don’t have enough funds. Think twice before quitting and in the end still be grateful co’z you still got that paying job even if it sucks. Again, there’s no place for “PRIDE”. Atleast for my situation. :-p

But then again, nothing is much sweeter getting that awesome learning job. Ever imagine that you’re learning while getting paid. FTW! :D

Written by admin

March 30, 2010 at 5:04 am

Posted in Life

Follow me on twitter

leave a comment »

I haven’t blog for so long. For the mean time you can follow me on twitter. :)

http://twitter.com/ordinarywebguy

Written by admin

March 2, 2010 at 5:39 am

Posted in Uncategorized

Zend_Mail attachment missing line

with 3 comments

If you may ever find hard to make it work using Zend_Mail file attachment and following the documentation here http://framework.zend.com/manual/en/zend.mail.attachments.html, there’s a missing line.

$mail = new Zend_Mail();

$at = $mail->createAttachment($myImage);
$at->type = ‘image/gif’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = ‘test.gif’;

$mail->send();

This should be

$mail = new Zend_Mail();

$myImage = file_get_contents($myImagePath);

$at = $mail->createAttachment($myImage);
$at->type = ‘image/gif’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = ‘test.gif’;

$mail->send();

This should work fine now. :)

Written by admin

October 14, 2008 at 3:55 am

Posted in PHP, Zend Framework

Google Map Project

with 7 comments

Just a project bookmark.

My recent project at YW, Google Map API integration. It also utilizes jQuery, Zend_Db and Zend_Paginator.

Check it out here: http://88.191.66.96/index.php

Written by admin

October 13, 2008 at 5:47 pm

Don’t use google chrome to open your google notebook

with 2 comments

Exactly as what the title is “Don’t use google chrome to open your google notebook” if you don’t want to lose data in your google notebook. It just happen to me after a click on my notebook section, the data on it was disappeared. And I can’t find a way how to retrieve it. :(

Google Chrome devs what is this going on? I can’t believe it happens. Errr…

Written by admin

October 13, 2008 at 5:31 pm

Follow

Get every new post delivered to your Inbox.