.htaccess: Invalid command ‘Header’

If you’re getting this message on your Apache installation, coupled with a 500 Internal Server Error message, it means you’ve used the Header command in an .htaccess file or in the apache2.conf (or httpd.conf) file without first including the Headers module in your Apache configuration file. Fortunately it’s an easy fix, especially on Ubuntu systems:

Simply run as root:

   ln -s /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/

Then restart apache:

   service apache2 restart

Ubuntu Configure Sphinx Search

Install Sphinx Search

sudo apt-get install sphinxsearch

Configure Sphinx Search

cd /etc/sphinxsearch/

cp sphinx.conf.sample sphinx.conf

The conf file consists out of four parts:

source: data source definition

index: index settings for your data source

indexer: consists out of indexer settings (cause path, charset and so on)

searchd: searchd settings

Note that the original contents of the fields are not stored in the Sphinx index. The text that you send to Sphinx gets processed, and a full-text index (a special data structure that enables quick searches for a keyword) gets built from that text. But the original text contents are then simply discarded. Sphinx assumes that you store those contents elsewhere anyway.

 

how to handle CHybridAuth – Oophs. Error! – access denied

When you make the user login to your website via a social network like facebook and the user is directed by CHybridAuth to the social network (facebook). Then the user has two choices to either allow or cancel the access to your app. If the user happens to cancel the access then the class Endpoint in CHybridAuth throws an exception (like Oophs. Error! – access denied ) which is not useful for users and looks not so nice.

To handle this I simply added the following code to actionEndpoint:

  // my updated version of actionEndpoint()
  public function actionEndpoint(){
    if (isset($_GET['error']) && $_GET['error']=='access_denied') {
    	throw new CHttpException(403,'Access denied');
    	return;
    }
    Yii::app()->hybridAuth->endPoint();
  }

This has been implemented on site fillup.se

How to save Swedish Characters in MySQL using PHP and display it on Web Page

How to save Swedish Characters in MySQL using PHP and display it on Web Page

It was a headache and wastage of time when I came across the situation when I saw strange Swedish characters on one of my clients web page and its MySQL database. After googling I found several suggestions but no one was clearer unless I experience my self and rectified the problem.

Basically there are three places that need to be handled to display Swedish characters correcly on a site that uses PHP and MySQL.

1. HTML Side 2. PHP Side 3. MySQL table structure

Lets talk about each of the above one by one.

1. HTML Side

You have to make sure that html encoding is set to UTF-8. In other words simply add the following to the head section of your html document. Please also make sure to save the webpage in utf-8 format by using notepad++ for example. To do it in notepad++ open the webpage in notepad++ and click menu Encoding-> Convert to utf-8 ( to troubleshoot just create a new document in notepad++ and copy your webpage to it and now click Encoding-> Convert to utf-8).

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />

2. PHP Side

To save data to MySQL use PHP function utf8_encode. This mean if you want to save some data to MySQL say ‘åöä’ , you should assign it to a variable like this:

$tmp = utf8_encode(‘åöä’);

and now you can use $tmp in your update or insert MySQL Query.

3. MySQL table structure

The last step that you must do is to goto the table where you are supposed to save data that contains Swedish characters. Click structure of that table (in phpmyadmin) and click ‘change’ in front of the field that will save data with Swedish characters. Simple change the collation to utf8_swedish_ci

 

You are done.

PHP Frame Works

There are several frameworks in PHP. Recently I have the chance to work with Code Igniter and Symfony and therefore I searched the web to find some expert view and facts about these.

I found a nice comparison here:

 

 

 

Here is another nice overview about which framework to use:

 

How to save Swedish Characters in MySQL using PHP and display it on Web Page

It was a headache and wastage of time when I came across the situation when I saw strange Swedish characters on one of my clients web page and its MySQL database. After googling I found several suggestions but no one was clearer unless I experience my self and rectified the problem.

Basically there are three places that need to be handled to display Swedish characters correcly on a site that uses PHP and MySQL.

1. HTML Side 2. PHP Side 3. MySQL table structure

Lets talk about each of the above one by one.

1. HTML Side

You have to make sure that html encoding is set to UTF-8. In other words simply add the following to the head section of your html document. Please also make sure to save the webpage in utf-8 format by using notepad++ for example. To do it in notepad++ open the webpage in notepad++ and click menu Encoding-> Convert to utf-8 ( to troubleshoot just create a new document in notepad++ and copy your webpage to it and now click Encoding-> Convert to utf-8).

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />

2. PHP Side

To save data to MySQL use PHP function utf8_encode. This mean if you want to save some data to MySQL say ‘åöä’ , you should assign it to a variable like this:

$tmp = utf8_encode(‘åöä’);

and now you can use $tmp in your update or insert MySQL Query.

3. MySQL table structure

The last step that you must do is to goto the table where you are supposed to save data that contains Swedish characters. Click structure of that table (in phpmyadmin) and click ‘change’ in front of the field that will save data with Swedish characters. Simple change the collation to utf8_swedish_ci

 

You are done.

How to setup PHP debugging in Eclipse – xDebug

The following video tutorial shows how to configure Xdebug delivered with XAMPP and how to use Eclipse PDT for debugging a sample php
project. The video is covered by the written instructions below, see them as addition, the video should be enough. One note to the end of the
video: The debugging is started twice, in the first debug pass you will see, that the website is not redirected to the php script receiving the
form data. That sometimes just happens, seems to be some kind of bug. On the second attempt everything works.


The tutorial uses XAMPP 1.7.3, Xdebug 2.0.6-dev, Eclipse PDT 2.2.0 All In Ones and Windows 7. It however should work the same on future
versions of the mentioned software. The written instructions assume that you install XAMPP to C: (the default suggested by the installer). Note
that the installer then creates C:xampp automatically.

1) Get XAMPP (the basic package, only this package includes Xdebug) from
http://www.apachefriends.org/en/xampp-windows.html. Install it to C:,
the installer will then automatically create C:xampp

2) After XAMPP has
been installed, open C:xamppphpphp.ini and perform the following
replacements:

replace
;zend_extension = “C:xamppphpextphp_xdebug.dll”
with
zend_extension = “C:xamppphpextphp_xdebug.dll”

replace
;xdebug.remote_enable = 0
with
xdebug.remote_enable = 1

3) (Re)start the apache webserver using the XAMPP Control Panel.

4) Get Eclipse PDT All In Ones from
http://www.eclipse.org/pdt/downloads/ and extract it to a folder of your choice. Start Eclipse and make sure to select C:xampphtdocs as workspace, else your files won’t be available to the apache webserver and therefore you can’t execute them. In the Eclipse menu choose Window
– Preferences, then PHP – Debug. Change the PHP Debugger from Zend Debugger to XDebug and uncheck “Break at First Line”. Click Apply and
then OK. The debugger is now set up. Time to use it! IMPORTANT: If you already had any debug configuration for a PHP project, make sure to
delete it, so that a new configuration with the new settings is created the next time you debug a php script! Debug configurations you’ve
created before changing the settings in this step won’t be automatically updated! This is a common source of errors!

5) (For this step I recommend you have a look at the video, it is easy but complex to describe).
If you haven’t already done it, choose the most right symbol with the arrow (Workbench) in the Eclipse welcome screen. In the Eclipse menu choose File – New – PHP Project. Enter a name for your project e.g. WebDebugTest and click Finish. Now download http://download.boulder.ibm.com/ibmdl/pub/software/dw/opensource/os-php-eclipse-pdt-debug_source.zip
, it includes a sample project (not done by me, it is from [1]) called “webDebugExample”. Select the three files from this folder and add them to your Eclipse project by using e.g. Drag&Drop (maybe have a look at the video if you don’t know how to do that). The file one should start from when using this sample is “enterGreeting.php”. This script then sends the data you input to its form to “results.php”. Set a breakpoint in the “results.php” on line 8, then make sure to select “enterGreeting.php” in eclipse and debug the project as PHP Web Page. After you have entered something in the form and choosen submit, the debugger should start. The debugger is used like the other typical debuggers you may know. If you want to see the output of the script, you have to continue it using the arrow symbol in the debugger. Note, that in some cases the displayed website won’t change from the input form to the output. This is why the debugging process is run twice in the video. This seems to be a bug using Eclipse PDT and XDebug.