|
Blog > PHP Calculating world times for PHP scripts
Posted on March 30, 08 @ 12:22 am under PHP and has no comments.
Some websites show timings of different places all over the world. This improves user interface. Often programmers find this tricky. So I thought to articulate this for future references.
Calculating time differences is done in two steps.
1. Calculating the time difference between the server zone and the GMT.
2. Calculating the time difference between GMT and requested place.
Suppose this server is in Arizona, i.e -7:00 Hrs from GMT. So first the difference needs to be calculated.
$gmt=time() + 25200;
The value 25200 comes from 7 x 1hrs (60 mins) = 420mins x 60sec/min = 25200 secs. Now this value is added to current time on server, got by time(). Now the GMT time (in secs) is calculated.
Next, we need to add/subtract the required location from the GMT time. The final time would be our required time.
Here are some of the examples and their difference (in seconds) from GMT .
$hawaii=$gmt-36000;
$alaska=$gmt-32400;
$arizona=$gmt-25200;
$mexico=$gmt-21600;
$santiago=$gmt-14400;
$indiana=$gmt-18000;
$brasilia=$gmt-10800;
$london=$gmt;
$paris=$gmt+3600;
$cairo=$gmt+7200;
$moscow=$gmt+10800;
$kabul=$gmt+16200;
$karachi=$gmt+17000;
$india=$gmt+19800;
$bangkok=$gmt+25200;
$singapore=$gmt+28800;
$hongkong=$gmt+28800;
$sydney=$gmt+36000; 
Using FCKEditor in PHP websites
Posted on March 30, 08 @ 12:21 am under PHP and has no comments.
Many times, especially when it comes to content management systems, FCKEditor will be a useful thing. It generates html, that can be directly inserted into database, and can be displayed in relevant pages. This will be a reference of how to use FCKEditor in websites.
<strong>Compacting the FCK editor </strong>
The version supplied by the fckeditor.net contains other scripts for asp, cfm, etc. and language related messages contained in javascripts. The whole turns out to be around 3 mb or so. You can delete all these extra files and compact the editor, to be easily uploaded into FTP. For this, you can delete
- Other than PHP scripts in the fckeditor folder.
- Language messages other than English, located in editor/lang folder.
- Delete other than PHP connectors in editor/filemanager/connectors
- You may also want to keep only one theme which you like in editor/skins. I prefer the silver theme.
Now the folder size comes down around 1.8 MB, and its reasonable.
<strong>Knowing the files to be used</strong>
FCK can be centrally included by including fckeditor/fckeditor.php. The FCK object becomes available then and you can directly use it.
<code>include('fckeditor/fckeditor.php'); </code>
<strong>Creating the Editor</strong>
Once the environment is setup, you need to start using the FCKE. For this, just create an object, show the base path to fckeditor folder, and create() it. You can give the instance a name, while instantiating the object. In this case, myFCKE is the name given.
<code>
$fcke = new FCKeditor('myFCKE') ;
$fcke -> BasePath = 'fckeditor/';
$fcke -> Create() ;
</code>
Giving the Basepath relative to the fckeditor.php is a must, or else the icons will not be shown. This will generate the iframe window with necessary elements in it.
<strong>Uploading the files via FCKE</strong>
While inserting images, you may want to upload the newer ones via fck, for this, you need to enable this configuration in editor/filemanager/connectors/php/config.php. In this file, turn on the config by giving true for $Config['Enabled'].
<code>
$Config['Enabled'] = true ;
</code>
But be careful. Turning this On on a publicly accessible FCKE opens a risk of file uploads by anonymous users. It is recommended to login control the FCKE after enabling this.
Next you need to specify where the uploaded files reside. You can specify the path relative to document root in $Config['UserFilesPath'];
<code>
$Config['UserFilesPath'] = '/FCKEFiles/' ;
</code>
Note: The directory specified here must be writeable.
<strong>Using images and other objects in FCKE</strong>
The images uploaded via FCKE can be accessed at the time of inserting images.
<strong>Storing the value in database</strong>
The output of FCKE will be posted back as a normal form post, along with the other form fields, if any. You can capture this value from $_POST['myFCKE']. This value contains the html code with properly escaped quotes and other things. So you can directly put in database.
<strong>Getting back the FCKE value</strong>
For displaying in HTML
As the output of FCKE is HTML itself, the value retrieved form database can be directly echoed on the HTML page.
For editing back in FCKE
The HTML generated by FCKE can be understood by FCKE, so this HTML can be directly assigned to the $Value property of the object before create()ing it.
<code>
$fcke -> Value = $db->rows[0]['Content'];
$fcke -> Create();
</code>
Once the editing is finished, it can be directly inserted into database as briefed out previously. 
PHP Interview Questions
Posted on December 25, 07 @ 09:49 pm under PHP and has no comments.
People who are attending interviews on PHP can find these links useful.
http://www.geekinterview.com/Interview-Questions/Programming/PHP
http://www.kyapoocha.com/category/php-interview-questions/
http://www.allinterview.com/Interview-Questions/PHP.html
http://blog.assembleron.com/2007/05/23/php-interview-questions-from-yahoo/
http://www.devbistro.com/tech-interview-questions/Web-Dev.jsp

Interop b/w PHP and windows
Posted on November 20, 07 @ 05:14 am under PHP and has no comments.
I found this PHP video, which is a Powerpoint narration of PHP on windows. The presenter is in Microsoft and focuses on different points, which i thought, would be helpful for people working on php-windows.
http://asp.net/learn/videos/video-31.aspx
The video is wmv file with 8MB in size. It is worth seeing and knowing good things.
The narrator also shows how PHP will work with ASPX. Though they are too basic, you might get some ideas while implementing. 
PHP Applications
Posted on October 20, 07 @ 01:03 am under PHP and has no comments.
Little list of available PHP softwares
Framework:
Cakc PHP: Popular light-weight PHP - www.cakephp.org
Zend Framework: Sizes around 70MB. - framework.zend.com
CodeIgniter: www.codeigniter.com
Symfony: www.symfony-project.com/
Prado: Event driven framework - www.pradosoft.com
Forums:
phpBB: PHP forum, which supports themes. Has lot of developers worldwide. - www.phpbb.com
PubBB: Lightweight PHP forum like, phpBB. www.punbb.org
CMS:
XOOPS: Content management system. www.xoops.org
PHP Nuke: www.phpnuke.org
Blogs:
Wordpress: So popular - www.wordpress.org

Uploading files using php on windows
Posted on October 20, 07 @ 12:59 am under PHP and has no comments.
<?php
//file uploads
$uploaddir=’uploads/’;
if($_POST)
{
$uploadfile = $uploaddir . basename($_FILES[’userfile’][’name’]);
if (move_uploaded_file($_FILES[’userfile’][’tmp_name’], $uploadfile)) {
echo “File is valid, and was successfully uploaded.n”;
} else {
echo “Possible file upload attack!n”;
}
}
?>
<form enctype=”multipart/form-data” action=”" method=”POST”>
<!– Name of input element determines name in $_FILES array –>
Upload file: <input name=”userfile” type=”file” />
<input type=”submit” value=”Upload File” />
</form>

Pages: [1]
|