In PHP coding, we spend most of the time for debugging. Either we use echo, print_r or var_dump to check variable values or check whether a particular function is executing or not.

These all things are outputting something to browser. This is not applicable in case of redirection, or image processing (GD) or sometimes with callback url for Payment integrations.

header(Location: etc);may cause Warning : header is already sent , if you put an echo or debug and you cannot  see the output, since it redirects into some other page.

Here is your remote debugging console to solve these problems. http://vardump.it

remote-console

Copy the url from the site and use that url for your debugging purpose and keep the console open in another tab.

eg:

<?php

file_get_contents(‘http://vardump.it/253522/inserted-into-database’);  // last part of this url is your debugging message

?>

You can see these messages from your remote console http://vardump.it/253522 (last numbers are your unique key)

The debug url is formatted in this way: http://vardump.it/debug-id/your message here

Email me for more details.

More features like watch, break etc are under development

Tags: , , , , ,

· · · ◊ ◊ ◊ · · ·

multi-language-interface

If you aim to create a multi-language  website using PHP + Mysql , remember the following tips.

  • You can use mysql database for this purpose rather than using separate language files as usual content management system does.
  • You can create a table with following structure for this purpose.Table: muli-lang
    string_id:
    page_id:
    en:
    arb:
    fr:
  • Here string_id is the code for getting content  eg: welcome_message
    page_id is for saving in which page the content belongs to.  eg: home_page, login_page etc
    In field en, you have to enter the message in english,eg: Welcome to my website
    In arb field you can enter the corresponding translation in arab. eg: مرحبا بكم في موقعي
  • If you need to add more languages, it is just adding one more column to this table and put all translated values.
  • Write a class or functions in PHP to retrieve all the informations.
    eg: function get(language_id, page_id) returns corresponding message
  • Use session to save lang value. For example if you switch to french, set a variable lang= fr and use this variable to decide which column is to access from multi-lang table.eg: the sql will be , SELECT $lang FROM multi-lang WHERE string_id = ‘welcome_message’
  • For some string fragment like about_us, contact_us etc, it has global scope; then leave page_id as blank
  • To avoid multiple calling of functions to get translation, write a common function to get all translation for a particular page_id as array, and use this array all through the page. Thus you can avoid mysql query multiple times.
    eg: function get_all($page_id) returns array, say $Translate of all strings replacement. $Translate['login_message'], $Translate['login_error']
  • Additional things to remember:
  • Use this meta tab in html header
    <meta http-equiv=”Content-Type” content=”text /html; charset=UTF-8” />
    to show all languages
  • Create my_sql table in UTF-8 format
  • Execute the following query before executing any retrieval queries. Otherwise you may get ????? for language like Arabic, Hindi, Chinese etc.
    mysql_query(“SET CHARACTER SET ‘utf8′”, $link);

I hope these information may help you when you develop a multi-langauge support website

Thank you
Sajith

Tags: , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·