Entries Tagged as 'Coding'

PHP header redirect

Something to remember when using header location to redirect a page from a server-side script.  The output is redirected to the new page, but the logic on the original file will continue to execute.  Therefore, if there are database calls the changes to the data will still be made even though a header redirect was issued.

To solve the problem, make sure to issue an exit() command after a header location command.

Google Earth / Map Implementation Problem

One thing that was not documented fully at Google for integrating Google Earth into Google Map is that the function, getEarthInstance, is only available in the newest version of the Map API. I could not find exactly which version so the best way is to use v=2.x like in “http://maps.google.com/maps?file=api&v=2.x&key=yourkey” instead of specifying an exact version. Have fun with this new feature.

php strip_tags problem

I found that using php function, strip_tags, does not remove all the markup elements correctly from the subject content.  First of all, if an anchor link includes a line break, it will not be removed correctly.  Also, the style information is not properly removed as well.  In the following script, I also added in the regex to remove any content in between script tags, but that may or may not be necessary.

function strip_all_tags($content)
{
$content = preg_replace(’/\n/’,’ ‘,$content);
$content = preg_replace(’/<script.*<\/script>/U’,’ ‘,$content);
$content = preg_replace(’/<style.*<\/style>/U’,’ ‘,$content);
$content = strip_tags(strtolower($content));
return $content;
}

The function will remove all line breaks so strip_tags will not have problems with finding all markups.  Since strip_tags does not remove <style> tags, the new function will remove them using regex.

.NET Error “The password provided is invalid. Please enter a valid password value.”

Using the SqlMembershipProvider, you may encounter the error message, “The password provided is invalid. Please enter a valid password value. “, which is not very clear as to the exact problem. Apparently, the default setting in the .net membership configuration requires a password with a minimum of eight character and at least one non alpha numeric character such as “!@#$%^&*()”.

asp:HyperLink With Dynamic URLs

Much headache to get this to work. The following format will allow dynamic url with multiple variables in the query string in a itemtemplate.

<asp:HyperLink ID=”HyperLink1″ runat=”server”
Text=”Link Text”
Target=”_blank”
NavigateUrl=’<%# “~/mypage.aspx?var1=”+ Eval(”Var1″) + “&var2=” + Eval(”var2″)%>’>
</asp:HyperLink>

NOTE: Make sure any literal between <%# and %> uses double quotes NOT single quotes.

Other methods for handling dynamic NavigateUrl

Zencart and Ultimate URL - 1054 Unknown column ‘c.parent_id’ in ‘on clause’

Configuration:

Linux
Apache 1.3
Mysql 5
PHP 5
Zencart 1.3.5
Chemo Ultimate URL for Zencart 1.3.5

Problem:

After installation, the error message
1054 Unknown column ‘c.parent_id’ in ‘on clause’
shows up on any page in the catalog.

Fix:

Make the following change to /include/classes/seo.url.php
Original:

SELECT c.categories_id as id, c.parent_id, cd.categories_name as cName, cd2.categories_name as pName
FROM “.TABLE_CATEGORIES.” c,
“.TABLE_CATEGORIES_DESCRIPTION.” cd
LEFT JOIN “.TABLE_CATEGORIES_DESCRIPTION.” cd2
ON c.parent_id=cd2.categories_id AND cd2.language_id=’”.(int)$this->languages_id.”‘
WHERE c.categories_id=cd.categories_id
AND cd.language_id=’”.(int)$this->languages_id.”‘”;

Change:

“SELECT c.categories_id as id, c.parent_id, cd.categories_name as cName, cd2.categories_name as pName
FROM
“.TABLE_CATEGORIES_DESCRIPTION.” cd,
“.TABLE_CATEGORIES.” c
LEFT JOIN “.TABLE_CATEGORIES_DESCRIPTION.” cd2
ON c.parent_id=cd2.categories_id AND cd2.language_id=’”.(int)$this->languages_id.”‘
WHERE c.categories_id=cd.categories_id
AND cd.language_id=’”.(int)$this->languages_id.”‘”;

Zen Cart New Product Type Using Ultimate SEO URL Package

This post is to help those who are using Zen Cart and are using new product types with Ultimate SEO URL package installed. There are a couple of things to change in order to make everything work together as it took me a couple of hours to figure out. I hope this will help others save these couple of hours of hair pulling.

Prerequisite:

Zen Cart installed
New product type added
Ultimate SEO URL package installed
Goal:

Have the URLs for the products using the new product type show URLs in this format.

http://www.domain.com/[product name]-p-[product id].html

Changes Required:

NOTE: [handler_name] is the new product type name added.

  1. File - seo.url.php
    Original:
    $seo_pages = array(
    FILENAME_DEFAULT,
    FILENAME_PRODUCT_INFO,
    FILENAME_POPUP_IMAGE,
    FILENAME_PRODUCT_REVIEWS,
    FILENAME_PRODUCT_REVIEWS_INFO,
    );Result:

    $seo_pages = array(
    FILENAME_DEFAULT,
    FILENAME_PRODUCT_INFO,
    FILENAME_POPUP_IMAGE,
    FILENAME_PRODUCT_REVIEWS,
    FILENAME_PRODUCT_REVIEWS_INFO,
    FILENAME_[handler name]_INFO
    );
  2. File - seo.url.php
    Original:
    $this->reg_anchors = array(
    ‘products_id’ => ‘-p-’,
    ‘cPath’ => ‘-c-’,
    ‘manufacturers_id’ => ‘-m-’,
    ‘pID’ => ‘-pi-’,
    ‘products_id_review’ => ‘-pr-’,
    ‘products_id_review_info’ => ‘-pri-’,Result:
    $this->reg_anchors = array(
    ‘products_id’ => ‘-p-’,
    ‘cPath’ => ‘-c-’,
    ‘manufacturers_id’ => ‘-m-’,
    ‘pID’ => ‘-pi-’,
    ‘products_id_review’ => ‘-pr-’,
    ‘products_id_review_info’ => ‘-pri-’,
    ‘[handler name]_id’ => ‘-pji-’,

  3. File - seo.url.php -> function parse_parameters
    Find “case ‘products_id’:”
    Within this case statement, add the following.case ($page == FILENAME_[handler name]_INFO):
    $url = $this->make_url($page, $this->get_product_name($p2[1]), ‘[
    handler_name]_id’, $p2[1], ‘.html’, $separator);
    break;
  4. File - [webroot]/includes/filenames.php
    Add the following definition.define(’FILENAME_[handler name]_INFO’, ‘[handler name]_info’);
  5. File - [webroot]/.htaccess
    Add the following rewrite rule.RewriteRule ^(.*)-pji-(.*).html$ index\.php?main_page=[
    handler_name]_info&products_id=$2&%{QUERY_STRING} [L]

Fatal error: Cannot use string offset as an array in …

PHP5 Error message that is caused by attempting to assign a value to an array element of a variable that is declared as a string.

Example that generates error:
$foo=’bar’;
$foo[0]=’bar’;
Get error message Fatal error: Cannot use string offset as an array in …

Explanation
$foo was declared as a string in $foo=’bar’.
$foo[0] is trying to append an element onto a string variable.

Example that does not generate error:
$foo[0]=’bar’;
$foo=’bar’;
Does NOT generate error.

Explanation
$foo[0]=’bar’ instantiates variable $foo as array since it has not been instantiated. Then assigns ‘bar’ to element $foo[0].
$foo=’bar’ implicitly re-declares $foo as a string and assigns ‘bar’ to it.

Example that does not generate error:
$foo=’bar’;
$foo=array();
$foo[0]=’bar’;

Explanation
$foo=’bar’ implicitly declares $foo as a string variable then assigns ‘bar’ as the value.
$foo=array() explicitly re-declares $foo as an array.
$foo[0]=’bar’ can now be executed as $foo is declared as an array.

Let me know if this helped you or if I am not clear on anything. Thanks.