Mage_Cms_Block_Widget_Interface not found

when I was developing Widget of magento in Magento EE version 1.6 . I have spent lot of time behind to fin it out that Mage_Cms_Block_Widget_Interface is not working with Magento EE 1.6 version and got like this "PHP Fatal error: Interface 'Mage_Cms_Block_Widget_Interface' not found."

After I got information about this interface that It moved Mage_Cms_Block_Widget_Interface to Mage_Widget_Block_Interface in Magento EE version 1.6

Magento Admin login problem


Problem:

I had a new installation of magento. But I was unable to login as an administrator. I went to the admin login page, entered correct username and password but was redirected to the same login page. I could not enter the dashboard page. Error message is displayed when I enter wrong username or password. But nothing is displayed and I am redirected to the same login page when I insert correct username and password.

Solution:

I googled and found these solutions:-

1) Use 127.0.0.1 instead of localhost in your url, i.e. using http://127.0.0.1/magento/index.php/admin instead of
http://localhost/magento/index.php/admin . But this didn’t solve my problem.

2) Since I am using Windows XP, I was suggested to open “host” file from
C:\WINDOWS\system32\drivers\etc and have 127.0.0.1 point to something like magento.localhost or even 127.0.0.1 point to http://www.localhost.com . But this also didn’t work either.

3) This solution finally helped me out of this problem. The solution was to modify the core Magento code. Open app/code/core/Mage/Core/Model/Session/Abstract/Varien.php. Comment out the lines 80 to 83. The line number may vary according to the Magento version. But these lines are present somewhere near line 80. You have to comment the comma (,) in line: $this->getCookie()->getPath()//,

// set session cookie params
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath()//,
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()
);

Well, I am out of this problem. Hope, this solution you also help you.


Barcodes On your Web apps


The bar code is method of automatic identification and data collection.
Their use is widespread and the technology behind barcodes is constantly improving. Almost every item purchased from a grocery store, department store, and mass merchandiser has a UPC barcode on it. Now rarely will one come across any product that doesn’t have a barcode.

Varieties of barcodes
Barcodes bascially come in two main type: linear (1-dimensional) and Matrix (2-dimensional) with each offering a variety of formats, depending on your application purpose

(1) linear (1-dimensional) : The barcodes we usually see on books and other standard products are of the linear type. These only encode data in one dimension, from left to right. The following shows a typical UPC barcode.
(2) Matrix (2-dimensional) : They also come in patterns of squares, dots, hexagons and other geometric patterns within images termed 2D (2 dimensional) matrix codes or symbologies.

It is to use the PEAR::Image_Barcode class in PHP to dynamically create barcodes for Web applications. The backbone to the PEAR::Image_Barcode's ability to produce barcode images is in the GD library,If you haven't already installed PEAR, you will need to do so in order to get this application to work.


Installation
You can install Image_Barcode issuing the following command (as root):
# pear install Image_Barcode

You can get the latest code at the PEAR site:
http://pear.php.net/package/Image_Barcode/


Using Image_Barcode
Creating a barcode is as simple as calling the classes static draw() method.
The method has four parameters:

Text : string that shall be converted into barcode representation.
Type : this parameter determines which driver/type should be used; it is one of: Code39, code128, ean13, int25, postnet or upca.
Imgtype : determines the type of the image that is generated; one of jpg, png and gif.

By default, the image generated by the barcode driver is directly output to the browser. If you do not want this, pass false as fourth parameter and draw() will return the GD image resource object; allowing you to do further things with it.

Example code
A sample code for generating a CODE128 barcode is shown below.

/* Data that will be encoded in the bar code */
$bar_code_data = "TRSD5656";

/* The third parameter can accept any from the following,
* jpg, png and gif.
*/
Image_Barcode::draw($bar_code_data, 'code128', 'png');
?>

Supported Types
The ‘Image_Barcode’ library supports the following barcode types:
* Code 39
* Code 128
* EAN 13
* INT 25
* PostNet
* UPCA

Changing Apache's www root directory

Sometimes it's necessary to change your current www root folder to something else. Maybe you have all your work files on a different partition than where you installed WAMP to or you have several websites you're working on and need to make one of them your primary site for a while (the one that shows up when entering localhost).

Anything that has to do with Apache configuration can be done within a file called httpd.conf.

1. WAMP provides quick access to certain important files, one of them being httpd.conf.
2. Left-click WAMP icon and select Config files › httpd.conf.
3. The file will probably open up in Notepad.
4. Press Ctrl+F and enter documentroot.
5. Make sure case sensitive search is disabled and hit enter.
6. You should find a line that looks like DocumentRoot "C:/Program Files/wamp/www/".
7. Copy that line then put a # in front of it: #DocumentRoot "C:/Program Files/wamp/www/".
8. Paste the copied line just below and adjust it to where your custom root folder is located (e.g. DocumentRoot "C:/my_cool_site/").
9. Resume the search (usually by pressing F3) and you'll find a line like: .
10. Again copy the line, put a # in front, paste copied line below and adjust it (e.g. ).
11. Save and close the file.

Whenever you make a change to httpd.conf you have to restart Apache for it to take effect. The # we've added in front of the old lines turns them into a comment which Apache ignores. We just added them so that we can easily switch back to an old configuration by uncommenting the lines.

1. Left-click the WAMP icon and select Apache › Restart Service.
2. Wait for the icon status to change to white again.

The root directory should now have changed to then one you've entered in httpd.conf. You can test this by entering localhost in your web browser. The index page in that folder (or the lack thereof) should show up now.

How to get the Next Auto Increment ID in Mysql

Two way are there in mysql

1st way :
SELECT Auto_increment FROM information_schema.tables WHERE table_name='%s';"


2nd way using this sql :

$rs = mysql_query("SHOW TABLE STATUS LIKE 'table_name' ");
$row = mysql_fetch_array($rs);
echo $row['Auto_increment'];

PHP Form Validation By Regular Expression ()

(1) PHP check valid url

function valid_url($str)
{
return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $str)) ? FALSE : TRUE;
}

(2) PHP numeric characters validator

function numeric($str)
{
return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE;
}

(3) PHP alpha-numeric characters validator

function alpha_numeric($str)
{
return ( ! preg_match("/^([-a-z0-9])+$/i", $str)) ? FALSE : TRUE;
}

(4) PHP alpha characters validator

function alpha($str)
{
return ( ! preg_match("/^([-a-z])+$/i", $str)) ? FALSE : TRUE;
}

(5) PHP validate ip

function valid_ip($ip)
{
return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE;
}

(6) PHP validate email

function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}

(7) PHP Windows Filename Validation
function is_valid_filename($name) {
$parts=preg_split("/(\/|".preg_quote("\\").")/",$name);
if (preg_match("/[a-z]:/i",$parts[0])) {
unset($parts[0]);
}
foreach ($parts as $part) {
if (
preg_match("/[".preg_quote("^|?*<\":>","/")."\a\b\c\e\x\v\s]/",$part)||
preg_match("/^(PRN|CON|AUX|CLOCK$|NUL|COMd|LPTd)$/im",str_replace(".","\n",$part))
) {
return false;
}
}
return true;
}


Reference from : http://www.roscripts.com/snippets/show/61

important scrips for php (Part -1)

(1) Human readable Sizes

function ByteSize ( $file_size )
{
$file_size = $file_size-1;
if ($file_size >= 1099511627776) $show_filesize = number_format(($file_size / 1099511627776),2) . " TB";
elseif ($file_size >= 1073741824) $show_filesize = number_format(($file_size / 1073741824),2) . " GB";
elseif ($file_size >= 1048576) $show_filesize = number_format(($file_size / 1048576),2) . " MB";
elseif ($file_size >= 1024) $show_filesize = number_format(($file_size / 1024),2) . " KB";
elseif ($file_size > 0) $show_filesize = $file_size . " b";
elseif ($file_size == 0 || $file_size == -1) $show_filesize = "0 b";
return $show_filesize;
}

(2) Remove non alpha numeric characters

function rem_non_alpha_numeric ( $string, $replace )
{
return preg_replace ( '/[^a-zA-Z0-9]/u', $replace, $string );
}

(3) PHP escape for SQL

/**
* Correctly quotes a string so that all strings are escaped. We prefix and append
* to the string single-quotes.
* An example is escape ( "Don't bother",magic_quotes_runtime () );
*
* @param str the string to quote
* @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc().
*
* @return quoted string to be sent back to database
*/
function escape ( $str, $magic_quotes = false )
{
switch ( gettype ( $str ) )
{
case 'string' :
$replaceQuote = "\\'"; /// string to use to replace quotes
if ( ! $magic_quotes ) {

if ( $replaceQuote [ 0 ] == '\\' ){
// only since php 4.0.5
$str = seo_str_replace ( array ( '\\', "\0" ), array ( '\\\\', "\\\0" ), $str );
//$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));
}
return "'" . str_replace ( "'", $replaceQuote, $str ) . "'";
}

// undo magic quotes for "
$str = str_replace ( '\\"','"', $str );

if ( $replaceQuote == "\\'" ) {// ' already quoted, no need to change anything
return "'$str'";
}
else {// change \' to '' for sybase/mssql
$str = str_replace ( '\\\\','\\', $str );
return "'" . str_replace ( "\\'", $treplaceQuote, $str ) . "'";
}
break;
case 'boolean' : $str = ($str === FALSE) ? 0 : 1;
return $str;
break;
case 'integer' : $str = ($str === NULL) ? 'NULL' : $str;
return $str;
break;
default : $str = ($str === NULL) ? 'NULL' : $str;
return $str;
break;
}
}

(4) PHP is keyword in string

function is_keyword_in_string_bol ($keyword, $string)
{
if ( strpos ( $string, $keyword ) === false )
{
return FALSE;
}
else {
return TRUE;
}
}

(5) PHP check url if valid

function is_valid_url ( $url )
{
$url = @parse_url($url);

if ( ! $url) {
return false;
}

$url = array_map('trim', $url);
$url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
$path = (isset($url['path'])) ? $url['path'] : '';

if ($path == '')
{
$path = '/';
}

$path .= ( isset ( $url['query'] ) ) ? "?$url[query]" : '';

if ( isset ( $url['host'] ) AND $url['host'] != gethostbyname ( $url['host'] ) )
{
if ( PHP_VERSION >= 5 )
{
$headers = get_headers("$url[scheme]://$url[host]:$url[port]$path");
}
else
{
$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);

if ( ! $fp )
{
return false;
}
fputs($fp, "HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n");
$headers = fread ( $fp, 128 );
fclose ( $fp );
}
$headers = ( is_array ( $headers ) ) ? implode ( "\n", $headers ) : $headers;
return ( bool ) preg_match ( '#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers );
}
return false;
}

(6) How to extract google search results using PHP




if(!isset($_POST['q']))
{
echo '

';
}
else
{
// this would be the URL if you want the results on page 2, 3 ... where $_POST['p'] is multiple of 10
// $off_site = 'http://www.google.com/search?q='.urlencode($_POST['q']).'&start='.$_POST['p'];
$off_site = 'http://www.google.com/search?q='.urlencode($_POST['q']).'&ie=UTF-8&oe=UTF-8';
$fp = fopen ($off_site, 'r') or die('Unable to open file '.$off_site.' for reading');
while (!feof ($fp))
{
$buf = trim(fgets($fp, 4096));
$pos = strpos($buf,'

');
if($pos !== false)
{
$parts = explode('

',$buf);
$parts2 = explode('http://',$parts[1]);
$parts3 = explode('>',$parts2[1]);
echo ''.$parts3[0].'
';
}
}
}


?>

(7) PHP word wrap

/** * Example usage: *
* // Your text * $text = "This is a sentence which contains some words.";
* * // Or from a database result * $text = $row['text'];
* * // Then put it into the function * $text = word_wrap($text);
* * // Output the result * echo $text; */ function word_wrap($text)
{ // Define the characters to display per row
$chars = "10"; $text = wordwrap($text, $chars, "
", 1);
return $text;
}?>

8) Page load time calculator

// Insert this block of code at the very top of your page:
$time = microtime();$time = explode(" ", $time);
$time = $time[1] + $time[0];$start = $time;
// Place this part at the very end of your page$time = microtime();
$time = explode(" ", $time);$time = $time[1] + $time[0];
$finish = $time;$totaltime = ($finish - $start);
printf ("This page took %f seconds to load.", $totaltime);
?>


(9) PHP limit words

function word_limiter($str, $n = 100, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}

$words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)));

if (count($words) <= $n)
{
return $str;
}

$str = '';
for ($i = 0; $i < $n; $i++)
{
$str .= $words[$i].' ';
}

return trim($str).$end_char;
}

(10) PHP limit characters

function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}

$str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));

if (strlen($str) <= $n)
{
return $str;
}

$out = "";
foreach (explode(' ', trim($str)) as $val)
{
$out .= $val.' ';
if (strlen($out) >= $n)
{
return trim($out).$end_char;
}
}
}

(11) Show page queries

function mysql_query_2($query){
$_SESSION['queries']++;
return mysql_query($query);

// now use mysql_query_2() function in place of mysql_query()
// Each query will execute exactly the same but count up in
// session variable 'queries'

echo "$_SESSION['queries']";

// just output it somewhere like above...

(12) Checks if a path is absolute or relative

function is_absolute($path)
{
return ($path[0] == '/' || (substr(PHP_OS, 0, 3) == 'WIN' && preg_match('#^[a-z]:/#i', $path))) ? true : false;
}