Category Archives: Web Development

Vars from PHP to JS and Back

The easy part is to add a js variable from php.
<html>
<?php
$MyVar3 = “Something in PHP”;
?>
<script language=”JavaScript”>
alert(<?php print “‘”.$MyVar3.”‘”; ?>);
</script>
</html>

The hard part is to take values from Javascript to PHP

<html>
<script language=”JavaScript”>
var JSVar = ‘something from JS code’;
</script>
<?php

$MyVar1 = “?><script language=javascript>document.write(‘Something you want’);</script><?php”;
$MyVar1 = str_replace(“?>”, “”, $MyVar1);
print $MyVar1.”<br><br>”;

$MyVar2 = “?><script language=javascript>document.write(JSVar);</script><?php”;
$MyVar2 = str_replace(“?>”, “”, $MyVar2);
print $MyVar2;
?>
</html>

Check if Cookies are Enabled

If cookies are needed you can make a page load check adding this javascript to your page !!!

<script type=”text/javascript”>
// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure
Set_Cookie( ‘test’, ‘none’, ”, ‘/’, ”, ” );
// if Get_Cookie succeeds, cookies are enabled, since
//the cookie was successfully created.
if ( Get_Cookie( ‘test’ ) )
{
document.write( ‘cookies are currently enabled.’ );
/*
this is an example of a set cookie variable, if
you want to use this on the page or on another script
instead of writing to the page you would just check that value
for true or false and then do what you need to do.
/*
cookie_set = true;
// and these are the parameters for Delete_Cookie:
// name, path, domain
// make sure you use the same parameters in Set and Delete Cookie.
Delete_Cookie(‘test’, ‘/’, ”);
}
// if the Get_Cookie test fails, cookies
//are not enabled for this session.
else
{
document.write( ‘cookies are not currently enabled.’ );
cookie_set = false;
}
</script>

Maximize the maximum values in php scripts

In some cases you need to make a custom script for uploading files or even update / synchronize two databases.  The php execution time has some restrictions, for security reasons. If a scripts takes more than apache server expects to take the whole procedure stops and your update script does not complete what its meant to do. In those cases you can actually do some changes like this

Find the php.in (in case you run a script in your local server). In a case you have to change tha php.ini in a hosted site, some hosters do give you this option.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
max_execution_time = 240     ; Maximum execution time of each script, in seconds
max_input_time = 240    ; Maximum amount of time each script may spend parsing request data
memory_limit = 20M      ; Maximum amount of memory a script may consume (8MB)

if you post many data change this line (as you need to)

; Maximum size of POST data that PHP will accept.
post_max_size = 30M

If you need to upload file more than tha default (2M – 10M)

; Maximum allowed size for uploaded files.
upload_max_filesize = 25M

Add a custom favicon to your site

Mysteries Of The Favicon.ico — How To Create A Favicon In Photoshop

A Favicon is a little custom icon that appears next to a website’s URL in the address bar of a web browser. They also show up in your bookmarked sites, on the tabs in tabbed browsers, and as the icon for Internet shortcuts on your desktop or other folders in Windows. And when I say little, I mean 16 pixels by 16 pixels. So if you like a good design challenge try your hand at this one.

All you need to add a Favicon to your site is a Windows Icon (.ico) file usually called favicon.ico that you upload to the main directory of your website. Nowadays, most browsers besides Internet Explorer can use a GIF (including animated ones) or PNG (including full transparency) instead. But since all browsers including IE understand the .ico format, and because it’s got a lot of intriguing features that GIFs and PNGs don’t, read on to find out how to make one.

Download The Plugin

You’ll need the Windows Icon (ICO) file format Photoshop Plugin to export to the .ico file format. You can download the plugin from Telegraphics. The plugin reads and writes ICO files in 1, 4 and 8-bit Indexed and 24-bit RGB modes, and also reads and writes 32-bit “XP” icons (with 8-bit alpha channel). Make sure to install the plugin before you begin this tutorial.

Let’s Begin
Because 16 x 16 is such a small canvas area, it can be very difficult to be creative. So instead start your project with a canvas set at 64 x 64 (always use even multiples when you plan on resizing files). Do this by selecting File>New, and opening a new canvas that is 64 x 64 pixels in size.
Adobe Photoshop tutorial - Favicon.ico — How To Create A Favicon In Photoshop
The Design
If you already have a logo you should reduce it to the 16 x 16 size to see if it holds up. If it doesn’t look good at this size, work with the 64 x 64 canvas and try creating a simple design that incorporates colors from your website’s palette.

When you’re ready to test the design select Image>Image Size menu and enter 16 x 16. Click on Resample Image and choose “Bicubic Sharper” from the drop-down menu (CS only for this step). This is the best setting for making sure that an image doesn’t blur as it’s being resized. If it’s still not sharp enough, go back and oversharpen, oversaturate and/or heighten the contrast of the original image and then resize it again.

If you feel the icon is not quite what you wanted, just keep tweaking it until it is perfect. At this tiny size it can take a few tries before you get it right.

Saving The Custom Icon
Adobe Photoshop tutorial - Favicon.ico — How To Create A Favicon In Photoshop
Go to File>Save As and make sure you name the file favicon.ico. Under Format you must choose Windows Icon (ICO) from the pulldown menu. This format will only be available in Photoshop after you download and install the plugin. In the next step you’ll need to upload this new file to the root folder of your website, so it’s a good idea to navigate and save it to that location on your hard drive now.

Uploading The Favicon.ico File
Connect to your server and upload your Favicon.ico file to your website. You must place it into the same directory as your home (index) page, and leave it loose, making sure not to put it in an images directory or other folder. The standard location is the “root” folder of your site, which is same directory as your home (index) page, not inside an images directory or other folder. If you put it there (and name it favicon.ico), most browsers will find it automatically.

Some browsers will look for a direct link in the HTML source code to your site’s favicon.ico file. You can help these browsers by adding this link in the head section of each page on which you want the Favicon.ico to appear.
Here is the link code to include: <link rel=”Shortcut Icon” href=”/favicon.ico”>
Once you’ve added this code, upload all of your modified pages.

(Some people suggest that the following is actually more correct: <link rel=”icon” href=”/favicon.ico” type=”image/x-icon”> You can use both if you want!)

If you want to use a GIF or PNG instead, use this format instead (just remember that it won’t work in IE):
<link rel=”icon” href=”/favicon.png” type=”image/png”> or
<link rel=”icon” href=”/favicon.gif” type=”image/gif”>

Testing
If your new Favicon does not show up right away, try refreshing the page or clearing your cache — or put a ‘?’ at the end of the url, which will trick a browser into thinking the page is new and not cached.

jQuery a great tool for any ServerSide Scripting Language

logo

One of the most used framework for making your web application more live, interactive. There is been a while since I run into it, but recently I decided to use it. Main reason is when i saw the sits that actually use the jQuery framework. Take a look here and you ll be suprised by the big company names.

Continue reading jQuery a great tool for any ServerSide Scripting Language