How To (HTTPS) Redirect Signup and Admin Pages Using .htaccess
“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?
Compelling Reasons To Use Silverstripe
1. Framework plus CMS in one equals awesome app.
2. OOP Centric / MVC Structured
3. Templating
4. Scalability
Zend_Form a Daunting and Cumbersome Task?
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.
How to Install Android Applications using Android SDK?
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!!!
A New Leaf
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!
Will Code for Food and Suck on it
“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!
Follow me on twitter
I haven’t blog for so long. For the mean time you can follow me on twitter.
http://twitter.com/ordinarywebguy
Zend_Mail attachment missing line
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.
Google Map Project
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
Don’t use google chrome to open your google notebook
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…

