Archive for the 'php' Category

Tips of the Day: phpinfo(), Code That Shouldn’t Show To Public

I notice that most of the programmer love to do phpinfo() on info.php, info.html page. But they do not know that such information may vulnerable to attacker. Some even have it as apache’s default DocumentRoot.

If you want like to use phpinfo(), it’s advice to use a random name for php filename. For example infoxxxxx.php, noinfo123123aa.php, testinfo123213.php. Beside that, you can remove the code immediately after you got what you want.

symfony / propel with RAND()

previously mentioned, symfony framework is really cool. Lately I am working on a simple online test system which doesn’t take up much of my to write the code from scratch. One of my favorite is using propel to generate the admin panel, it’s so easy, quick and code management is clean and neat.

i have a set of questions, for example 100 security related questions but some of the engineer may only need to answer 20 out of 100. And each engineer shouldn’t get the same question and using RAND() is easier for me in order to write - less code.

here is an example how you select random questions from database using propel;

$c = new Criteria();
$c->addAscendingOrderByColumn(’rand()’);
$c->setLimit(20);

start having fun coding with symfony framework.

symfony in a freebsd box

Fast and easy symfony framework installation in your FreeBSD would be through pear. Pear doesn’t bundle with FreeBSD apache + php installation from port installation. To roll pear in FreeBSD box,

cd /usr/ports/devel/pear
make install clean distclean

p/s: if you having problem with core dump 6, try doing this

After pear is installed, do this

pear channel-discover pear.symfony-project.com
pear install symfony/symfony

Check your symfony version

symfony -V
> symfony version 1.0.5

MySQL Cannot Connect with PHP in OSX

I think some of you might have problem connecting to MySQL with PHP(mysql_connect) in Max OS X if you configured MySQL5 with Darwin Ports. Most probably you will get these error message;

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (13) in /Users/paulooicongjen/myproject/web/info.php on line 10
Could not connect: Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (13)

The error message is caused by the folder mode created by MySQL installation by default. To solve this problem, change your folder mode to 755 and restart apache.

cd /opt/local/var/run
sudo chmod 755 mysql5
sudo apachectl restart

It should works now!

TextMate: Creating New Project in Shell Instantly

Been using TextMate recently, really loving it like hell. There is a best part of TextMate that you can create a New Project instantly from your www folder. But first and foremost you got to create symlink to /bin.

To create a symlink, do this

sudo ln -s /Applications/TextMate.app/Contents/Resources/mate /bin/mate

After you have created the symlink, change directory to your www folder for example

cd /opt/local/apache/htdocs/myproject

And run the command mate .

mate .

Congrat, new project has been created with Text Mate, just save it with shortcut key Ctrl + Command + S

Next Page »