Pages

Saturday, November 26, 2011

Wamp server change port

open apache
C:\wamp\bin\apache\Apache2.2.21\httpd.conf

than change port

Listen 80 replace with Listen 8080
 and
ServerName localhost:80 replace with ServerName localhost:8080

After this restart your wamp server

than open your browser and type localhost:8080








Tuesday, October 18, 2011

PHP Paging script

$page = isset($_REQUEST['page_no']) ? $_REQUEST['page_no'] : 1;
$show = 10;
$start = ($page - 1) * $show;

$result = mysql_query("SQL QUERY");

$total = mysql_num_rows($result);
$total_page = ceil($total / $show);

$res = mysql_query("SQL QUERY limit $start,$show");

$first = $start + 1;
$last = $first + $show;
if($last > $total)
{   
    $last = $total;
}
if(mysql_num_rows($res) > 0)
{
    while($row = mysql_fetch_array($res))
    {   }
}

/**********     Page Links  **********/
<?php   
    $width = 4;
    if($total > $show)
    {
    if($page >= 1){
    print " <a href='YOURPAGE.php?page_no=1' class='page-numbers' >First</a> ";}
       
    if(($page-$width) > 1)
    {       
            for($i=($page-$width); $i<$page ;$i++)
            {
                print " <a href='YOURPAGE.php?page_no=$i' class='page-numbers' >$i</a> ";
            }
    }
    else
    {
                for($i=1; $i<$page ;$i++)
            {
                print " <a href='YOURPAGE.php?page_no=$i' class='page-numbers' >$i</a> ";
            }
        }
    print "<span class='page-numbers current'  >".$page."</span>";
    if(($page+$width) < ($total_page-1))
    {
        for($i=($page+1); $i<= ($page + $width); $i++)
        {
            print " <a href='YOURPAGE.php?page_no=$i' class='page-numbers' >".$i."</a> ";
        }       
    }
    else
    {
        for($i=($page+1); $i<= ($total_page); $i++)
        {   
            print " <a href='YOURPAGE.php?page_no=$i' class='page-numbers' >".$i."</a> ";
                  }   
    }
   
    if($page < $total_page)
    print "<font size='2'><a href='YOURPAGE.php?page_no=$total_page' class='page-numbers' >Last</a></font> ";
    else
    print "<font size='2'>Last</font>";
    }
    ?>
</div>






Saturday, September 3, 2011

IIS7 Url Rewrite Rules - solved

First create "httpd.conf" file on your root.
Than add the following code to the "httpd.conf" file.


RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#Perform rewriting
RewriteRule ^(.*)$ index.php?p=$1 [NC,L]

Now You can write RewriteRule in the .htaccess file

Friday, August 12, 2011

web.config Index Redirect

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Imported Rule 1" stopProcessing="true">
                  <match url="^(.*)$" ignoreCase="false" />
                  <conditions>
                    <add input="{HTTP_HOST}" pattern="^testdomain\.com$" />
                  </conditions>
                  <action type="Redirect" redirectType="Permanent" url="http://www.testdomain.com/{R:1}" />
                </rule>  
                <rule name="CanonicalHostNameRule1" stopProcessing="true">
                    <match url="index\.htm(?:l)?" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="testdomain\.com$" />
                        </conditions>
                        <action type="Redirect" url="http://www.testdomain.com/" />
                </rule>

            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Saturday, April 16, 2011

Constant contact integrate using CURL


<?php

//Constant Contact//

$emailaddress = trim("email");

/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////
$UN = "un";
$PW = "pw";
$Key = "api";
$entry = '<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>' . date('c') . '</updated>
<author></author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>' . $emailaddress . '</EmailAddress>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/1" />' // Do this for all the lists you want to add to
. '
</ContactLists>
</Contact>
</content>
</entry>';
// Initialize the cURL session
$request ="https://api.constantcontact.com/ws/customers/" . $UN . "/contacts";
$session = curl_init($request);
// Set up digest authentication
$userNamePassword = $Key . '%' . $UN . ':' . $PW ;
// Set cURL options
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS , $entry);
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); // If you set this to 0, it will take you to a page with the http response
// Execute cURL session and close it
$response = curl_exec($session);
curl_close($session);

?>

Saturday, April 9, 2011

Create cookie



<script type="text/javascript">
<!--

/* COOKIES */

var Cookies = {
init: function () {
var allCookies = document.cookie.split('; ');
for (var i=0;i<allCookies.length;i++) {
var cookiePair = allCookies[i].split('=');
this[cookiePair[0]] = cookiePair[1];
}
},
create: function (name,value,hours) {
if (hours) {
var date = new Date();
date.setTime(date.getTime()+(hours*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
this[name] = value;
},
erase: function (name) {
this.create(name,'',-1);
this[name] = undefined;
}
};
Cookies.init();

function saveIt(name) {
var x = document.forms['cookieform'].cookievalue.value;
if (!x)
alert('Please fill in a value in the input box.');
else {
Cookies.create(name,x,1);
alert('Cookie created');
}
}

function readIt(name) {
alert('The value of the cookie is ' + Cookies[name]);
}

function eraseIt(name) {
Cookies.erase(name);
alert('Cookie erased');
}


var x = Cookies['jaycookie'];
if (x) alert('Cookie jaycookie \nthat you set on a previous visit, is still active.\nIts value is ' + x);


// -->
</script>


</head>

<body>

<form name="cookieform" action="#"><p>
The value of the cookie should be <input name="cookievalue" />
</p></form>

<p><a href="javascript:saveIt('jaycookie')" class="page">Create cookie 1</a><br />
<a href="javascript:readIt('jaycookie')" class="page">Read cookie 1</a><br />
<a href="javascript:eraseIt('jaycookie')" class="page">Erase cookie 1</a>.</p>

Monday, April 4, 2011

csv import - Export -- mysql


CSV IMPORT

ini_set('auto_detect_line_endings',1);

$handle = fopen('city.csv', 'r');

while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) {
  
FIELDVALUE1 = str_replace("`","", mysql_real_escape_string($data[0]));
FIELDVALUE2 = str_replace("`","", mysql_real_escape_string($data[1]));

mysql_query("INSERT INTO `TABLE_NAME` (`FIELDNAME1`,`FIELDNAME2`) VALUES ('FIELDVALUE1','FIELDVALUE2')");
 

    $result = (mysql_insert_id()> 0) ? 'Pass' : 'Fail' ;
 
    $output[$result]++;

}

CSV EXPORT



$filename = 'test.csv';
$csv_terminated = "\n";
$csv_separator = ",";
$csv_enclosed = '"';
$csv_escaped = "\\";
$out  = "";
$mystr = "";

$out .= '"FIELDNAME1";"FIELDNAME2";"FIELDNAME3";"FIELDNAME4"';
$out .= $csv_terminated;

$sql_query = "select * from TABLE_NAME  where CONDITION";
$sqlFreetrail = mysql_query($sql_query);

while ($user = mysql_fetch_assoc($sqlFreetrail))
{
$FIELDVALUE1 = $user["FIELDNAME1"];
$FIELDVALUE2 = $user["FIELDNAME2"];
$FIELDVALUE3 = $user["FIELDNAME3"];
$FIELDVALUE4 = $user["FIELDNAME4"];


$mystr .= '"'.$FIELDVALUE1.'";"'.$FIELDVALUE2.'";"'.$FIELDVALUE3.'";"'.$FIELDVALUE4.'"';

$mystr .= $csv_terminated;
}

$out  = $out.$mystr;

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($out));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=$filename");
echo $out;
exit;

Monday, February 7, 2011

How to create page in the zencart?

1. write define(‘FILENAME_DEFINE_YOURPAGENAME’, ‘define_yourpagename’); in the "includes\filenames.php"

2. create language file

\includes\languages\english\yourpagename.php



3. create a page in this directory
\includes\languages\english\html_includes\define_yourpagename.php

Its not necessary but If you want to use this page as define pages in this case you must create this page

4. create a folder and page in this directory (directory name is 'yourpagename')

\includes\modules\pages\yourpagename\header.php

in this page write below code
notify('NOTIFY_HEADER_START_SITE_MAP');
/**
* load language files
*/
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
$breadcrumb->add(NAVBAR_TITLE);
// include template specific file name defines
$define_page = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/', FILENAME_DEFINE_YOURPAGENAME, 'false');

?>

5. create a page

\includes\templates\template_default\templates\tpl_yourpagename_default.php

in this page write your content.

If you want to use this page as define page you can use below code.

You can edit define page content from 'Admin Panel >> Tools >> Define page editor'

Tuesday, January 4, 2011

RSS feed reader - PHP

$url = "web url";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);


$xml = simplexml_load_string($result);

$xml is your array