How to manage Session in Magento

Session in Magento can be implemented and managed by one of the following way

  1. File system.
  2. Database.
  3. Memcached.
  4. tmpfs Filesystem.

Out of these 4 options, 2 options are available while installing Magento from which File system is by default selected.

How to Add, Retrieve and Delete (unset) a Magento session?

  1.  Add.
    Syntax to add Magento session

    Mage::getSingleton(‘{{type}}/session’) ->set{{SESSION_NAME}}(‘VALUE’);

    For  e.g.

    Mage::getSingleton(‘core/session’) ->setCompanyName(‘Trimantra’);

    Here type can be core, customer, checkout… Etc.

  2. Retrieve.
    Syntax to get/retrieve Magento session

    Mage::getSingleton(‘{{type}}/session’) ->get{{SESSION_NAME}}();

    For  e.g.

    Mage::getSingleton(‘core/session’) ->getCompanyName ();

    Here type can be core, customer, checkout… Etc.

  3. Delete / Unset Session.
    Syntax to delete / unset Magento session

    Mage::getSingleton(‘{{type}}/session’) ->uns{{SESSION_NAME}}();

    For  e.g.

    Mage::getSingleton(‘core/session’) ->unsCompanyName ();

    Here type can be core, customer, checkout… Etc.

Rakesh Gangani
Magento  Developer

Working with SharePoint Search with Form Based Authentication

When you configure form based authentication sometime is is need that  you disable Integrated Windows Authentication. By doing so search does not work as per expectation and you may face error. If you check in crawl log you will saw following notification error message.

Error:

Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has “Full Read” permissions on the SharePoint Web Application being crawled. ( HttpStatusCode Unauthorized The request failed with HTTP status 401: Unauthorized. )

Reason:

This error will occur, when search engine tries to crawl the content using the URL but as there is a change in user identity server is unable to access database and server will reject the request.

Solution:

For SharePoint Search you need Integrated Windows Authentication for crawling the content database. To resolve this issue we need to create extended website. Follow below steps to extend

  1. Go to Central Administration and select your Form Based Authentication website and extend your website with integrated windows authentication enabled. Note, when you extend website you have different site in IIS.
  2. Now modify your search service application’s content source and in content source give your extended website URL instead of live site url(Form-based authenticated site).
  3. Once you do that, click on content source and start full crawl. After crawl completes you will not face above error and search result is coming.
  4. If you check in your site now you may observe that search result is coming with extended site URL not with live site URL. To display live site URL open your Search Service Application and in the crawling section click on Server Name Mappings.
  5. From Server Name Mappings click on New Mapping.
  6. “In Address in index” give your extended site URL and “In address in search results” give your live site URL and click on Ok.
  7. Now once again click on content source and start full crawl. Now result will come with your live site URL.

 

Shraddha Shah
SharePoint Developer

Create a Custom config file for Codeigniter

By default, CodeIgniter has one primary config file, located at “application/config/config.php
What if we want to have a custom configuration file? What if we want to create custom config array with desired name?
Codeigniter allows a developer to create custom file but developer has to define values with $config array developer cannot define a custom variable or array inside this new file and use it

$this->message->item(‘msg_cn_welcome’);

By doing this developer will get an error – “application/config/custom.php file does not appear to contain a valid configuration array.

Well to over come with this, I have created a customized message configuration file that will store all messages at one place. This article will help you to create your own custom config files.

At the end of this article downloadable packages are available for complete codeigniter v2.1.4 with customized files and only customized files.

Step 1: Create your config file.

I have created a file called message.php in “application/config/” directory. This file contains a config array named “message”. Define as much as data in $message array, that you would like to access.

$message[‘msg_cn_welcome’] = “Welcome to CodeIgniter!”;

Step 2: Create a Class

Create a Message Class in “/system/core/ “. This is going to be a core class as it will be auto loaded. Define a Method inside this class to perform a desire action. With respect to Message class, I have define a method calleditem. Item function will get the value from $message array and will return it to the caller function.
<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
/**
* CodeIgniter
*/
class CI_Message { var $message = array();
var $is_loaded = array();function CI_Message()
{
$this->message =& get_message();
log_message(‘debug’, “Message Class Initialized”);
}

function item($item, $index = ”)
{
if ( ! isset($this->message[$item]))
{
return FALSE;
}

$pref = $this->message[$item];

if ( isset($index) OR is_array($index))
{
if(is_array($index))
{
for($i=1; $i <= sizeof($index); $i++)
{
$pref = str_replace(‘%V’.$i,$index[$i-1],$pref);
}
}
else
{
$pref = str_replace(‘%V’,$index,$pref);
}
}
return $pref;
}
}

Step 3 : Create a reference function to load this new config file.

Now create a reference function get_message in “Common.php” file located at “/system/core/ “.
This function will be responsible to load message.php config file and read $message array and its values. Here is the code block.
/**
* Loads the main message.php file
* Added By : Pinal Desai
* @access private
* @return array
*/
function &get_message()
{
static $main_msg; if ( ! isset($main_msg))
{
if ( ! file_exists(APPPATH.’config/message’.EXT))
{
exit(‘The configuration file message’.EXT.’ does not exist.’);
}require(APPPATH.’config/message’.EXT);

if ( ! isset($message) OR ! is_array($message))
{
exit(‘Your Message file does not appear to be formatted correctly.’);
}

$main_msg[0] =& $message;
}
return $main_msg[0];
}

Step 4 : Load the Class

Now one thing is remaining, which is; to load a Message class. To load this customized class; add following code block to “CodeIgniter.php” file located at “/system/core/ “.

/*
* ——————————————————
* Load the Message class
* ——————————————————
*/

$EMSG =& load_class(‘Message’, ‘core’);

Step 5: Use the custom cofig file

Ready to use newly created config file and array. Following code will show the simple usage.

echo $this->message->item(‘msg_cn_welcome’);

Download DEMO Package:

Complete Codeigniter v2.1.4: Download Now
Only Customized Code and Files : Download Now

Article by: Pinal Desai

How to Recover Truncated Table and Recover Deleted Rows or Table

I want to introduce new thing to recover “Truncated” or “Deleted” record from MS SQL Server. This is very simple way to recover our data without any cost. I have tired this with SQL server 2008, 2010 and 2012.
Note : If you want to recover your data, please do not perform any operation after “Truncate” or “Delete” operation.
Before performing any operations please run stored procedures, which I have attached at the end of the post.
Sample table with same data:
1) Create Table
CREATE TABLE [dbo].[User](
[Id] [int] NULL,
[Name] [varchar](50) NULL
) ON [PRIMARY]
Now I will enter some test data in the new table
2) Insert Record
INSERT INTO [USER] VALUES (1,‘User1’)
INSERT INTO [USER]VALUES (2,‘User2’)
INSERT INTO [USER] VALUES (3,‘User3’)
INSERT INTO [USER]VALUES (4,‘User4’)
INSERT INTO [USER] VALUES (5,‘User5’)
INSERT INTO [USER]VALUES (6,‘User6’)
Now I will delete some data so that we can try recover deleted data
3) Delete Record
DELETE from [User] where Id between 4 and 6
Now you can see that record from 4 to 6 are deleted
Now to recover the deleted data I did following step
4) Run Command for Recover Deleted data with required field
EXEC Recover_Deleted_Data_Proc‘DBName’,‘dbo.Table name’
You can also pass data range from and to. Date format should be yyyy/mm/dd.
You see in the attached screen shot that records are recovered once executed the stored procedure
Then I did following steps to recover truncated table
Note that You can also pass data range from and to. Date format should be yyyy/mm/dd.
Run Command for Recover Truncated data with required field
Truncate table [User]
Now I executed following command to Recover Truncated table with required field
EXEC Recover_Truncated_Data_Proc‘DBName’,‘dbo.Table name’
Click to view Stored procedure To Recover Truncated Data

How to Speed Up a web site and increase Google pagerank

Hi,

I would like to introduce that how to speed up your page/web site and increase Google page speed rank. This will also help you in SEO.

To check you page speed and Analyze your web site online use following tool

  1. https://developers.google.com/speed/pagespeed/
  2. http://gtmetrix.com/

Main Points for Speed up web sites

  • Make Fewer HTTP Requests
  • Use a Content Delivery Network
  • Add an Expires Header
  • Gzip Components
  • Put Stylesheets at the Top
  • Put Scripts at the Bottom
  • Avoid CSS Expressions
  • Make JavaScript and CSS External
  • Reduce DNS Lookups
  • Minify JavaScript
  • Avoid Redirects
  • Remove Duplicate Scripts
  • Configure ETags
  • Make AJAX Cacheable

Apply following configuration for increase page spped

  1. Compression of JS file and CSS file

    http://refresh-sf.com/yui/#output

     

  2. HTML Code Compression

    http://www.textfixer.com/html/compress-html-compression.php

     

  3. Images Compression

    http://www.smushit.com/ysmush.it/

     

Add this in your web.config (if you have web.config file in your site folder structure)

<system.webServer>

<modules runAllManagedModulesForAllRequests=”true”>

<add type=”CompressionModule” name=”CompressionModule”/>

<add type=”ETags” name=”ETags”/>

<add name=”ScriptModule” preCondition=”managedHandler” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>

</modules>

<httpCompression directory=”%SystemDrive%inetpub tempIIS Temporary Compressed Files”>

<scheme name=”gzip” dll=”%Windir%system32inetsrvgzip.dll”/>

<dynamicTypes>

<add mimeType=”text/*” enabled=”true”/>

<add mimeType=”message/*” enabled=”true”/>

<add mimeType=”application/javascript” enabled=”true”/>

<add mimeType=”*/*” enabled=”false”/>

</dynamicTypes>

<staticTypes>

<add mimeType=”text/*” enabled=”true”/>

<add mimeType=”message/*” enabled=”true”/>

<add mimeType=”application/javascript” enabled=”true”/>

<add mimeType=”*/*” enabled=”false”/>

</staticTypes>

</httpCompression>

<staticContent>

<clientCache cacheControlMode=”UseMaxAge” cacheControlMaxAge=”365.00:00:00″/>

</staticContent>

<httpProtocol>

<customHeaders>

<add name=”ETag” value=”&quot;&quot;” />

</customHeaders>

</httpProtocol>

</system.webServer>

 

Kushal S. Vora