<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>stuntSnippets</title>
	
	<link>http://stuntsnippets.com</link>
	<description />
	<lastBuildDate>Fri, 09 Dec 2011 14:54:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/stuntsnippets" /><feedburner:info uri="stuntsnippets" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Validate Select Field in Zend Form</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/bTSD9of1T3w/</link>
		<comments>http://stuntsnippets.com/validate-select-field-in-zend-form/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 14:54:16 +0000</pubDate>
		<dc:creator>Darjan Vukusic</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[Validate Select Field in Zend Form]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Form]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend Select]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1146</guid>
		<description><![CDATA[When setting your Zend Form with Select field you don&#8217;t always wish to have label on that filed but rather “Select one” as a first option. Setting the required flag on Zend Select, or adding notEmpty validator won&#8217;t always work especially if your box is being populated dynamically. Let&#8217;s say you have something like this: [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fvalidate-select-field-in-zend-form%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fvalidate-select-field-in-zend-form%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When setting your Zend Form with Select field you don&#8217;t always wish to have label on that filed but rather “Select one” as a first option.</p>
<p>Setting the required flag on Zend Select, or adding notEmpty validator won&#8217;t always work especially if your box is being populated dynamically.</p>
<p>Let&#8217;s say you have something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;select name=&quot;example&quot;&gt;
    &lt;option value=&quot;Select one&quot;&gt;Select one&lt;/option&gt;
    &lt;option value=&quot;value1&quot;&gt;value1&lt;/option&gt;
    &lt;option value=&quot;value2&quot;&gt;value2&lt;/option&gt;
    &lt;option value=&quot;value3&quot;&gt;value3&lt;/option&gt;
&lt;/select&gt;</pre></div></div>

<p>You could easily validate this by adding Zend_Validate_Regex and passing any pattern to it<br />
as follows in snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_Regex<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'/[^Select\sone]/'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addErrorMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You need to select one value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This one will check if the value is not &#8220;Select one&#8221; and let your user pass validation only in that case.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/validate-select-field-in-zend-form/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=bTSD9of1T3w:46-5c86ziIM:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=bTSD9of1T3w:46-5c86ziIM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=bTSD9of1T3w:46-5c86ziIM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=bTSD9of1T3w:46-5c86ziIM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=bTSD9of1T3w:46-5c86ziIM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/bTSD9of1T3w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/validate-select-field-in-zend-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/validate-select-field-in-zend-form/</feedburner:origLink></item>
		<item>
		<title>PHP fluent interface</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/5r60SBD9C4E/</link>
		<comments>http://stuntsnippets.com/php-fluent-interface/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 10:01:02 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[fluent interface]]></category>
		<category><![CDATA[PHP fluent interface]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1134</guid>
		<description><![CDATA[PHP fluent interfaces have been around for quite some time. They are often used just for chaining methods of an object so that we get nice readable code. Good fluent interface takes a while to build, and will take some planning to make object methods work seamlessly. However, if you still haven&#8217;t experienced the PHP [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fphp-fluent-interface%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fphp-fluent-interface%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>PHP fluent interfaces have been around for quite some time. They are often used just for chaining methods of an object so that we get nice readable code.</p>
<p>Good fluent interface takes a while to build, and will take some planning to make object methods work seamlessly. However, if you still haven&#8217;t experienced the <strong>PHP fluent interface</strong>, there is a good way to start, just check out the following snippet.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Php_Fluent_Interface_Demo <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_first</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_second</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_third</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setFirst<span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstVal</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_first <span style="color: #339933;">=</span> <span style="color: #000088;">$firstVal</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setSecond<span style="color: #009900;">&#40;</span><span style="color: #000088;">$secondVal</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_second <span style="color: #339933;">=</span> <span style="color: #000088;">$secondVal</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setThird<span style="color: #009900;">&#40;</span><span style="color: #000088;">$thirdVal</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_third <span style="color: #339933;">=</span> <span style="color: #000088;">$thirdVal</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You have noticed that all setters have one line in common <strong>return $this;</strong> and this is how you set your methods to be able to chain. Example of usage follows in next snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$phpFluentInterface</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Php_Fluent_Interface_Demo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$phpFluentInterface</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirst</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSecond</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setThird</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope that this simple example is enough to get you started if you still haven&#8217;t tried PHP fluent interface. Good luck!</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/php-fluent-interface/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=5r60SBD9C4E:ukT3lLDgtec:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=5r60SBD9C4E:ukT3lLDgtec:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=5r60SBD9C4E:ukT3lLDgtec:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=5r60SBD9C4E:ukT3lLDgtec:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=5r60SBD9C4E:ukT3lLDgtec:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/5r60SBD9C4E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/php-fluent-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/php-fluent-interface/</feedburner:origLink></item>
		<item>
		<title>Zend Framework CSRF protection</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/Bzn7ex6T3EU/</link>
		<comments>http://stuntsnippets.com/zend-framework-csrf-protection/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 17:23:20 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CSRF]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1126</guid>
		<description><![CDATA[CSRF or Cross-Site Request Forgery is basically a way of requesting an unauthorized commands from a website by using an authorised user. For example: Let&#8217;s assume that you are logged in on your blog and I know that. I could then send you an e-mail with following content: &#60;img src=&#8221;http://yoursite.com/?action=delete-article&#038;id=12&#8243; /&#62;. Although you wouldn&#8217;t see [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fzend-framework-csrf-protection%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fzend-framework-csrf-protection%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>CSRF or Cross-Site Request Forgery is basically a way of requesting an unauthorized commands from a website by using an authorised user.</p>
<p>For example: Let&#8217;s assume that you are logged in on your blog and I know that. I could then send you an e-mail with following content: &lt;img src=&#8221;http://yoursite.com/?action=delete-article&#038;id=12&#8243; /&gt;.</p>
<p>Although you wouldn&#8217;t see the image &#8211; request for deleting article with id 12 would be sent. This can be prevented by setting up a hidden input in your Zend Framework form with a value that will be posted with your request and validated when request is sent in order to prevent possible CSRF attack.</p>
<p>It is quite easy in Zend Framework to set CSRF protection and here is the snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hash'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'csrf_token'</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'salt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'stunt@c0d3rs~!'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In order to see a full example of <strong>Zend Framework CSRF protection</strong> I have prepared an example of simple form with no elements on it.</p>
<h3>Zend Framework CSRF protection</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Stunt_Form <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hash'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'csrf_token'</span><span style="color: #339933;">,</span>
                    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'salt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'stunt@c0d3rs~!'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/zend-framework-csrf-protection/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=Bzn7ex6T3EU:8ZktQFly6og:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=Bzn7ex6T3EU:8ZktQFly6og:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=Bzn7ex6T3EU:8ZktQFly6og:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=Bzn7ex6T3EU:8ZktQFly6og:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=Bzn7ex6T3EU:8ZktQFly6og:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/Bzn7ex6T3EU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/zend-framework-csrf-protection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/zend-framework-csrf-protection/</feedburner:origLink></item>
		<item>
		<title>CSS horizontal menu</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/cKnei_KuKPg/</link>
		<comments>http://stuntsnippets.com/css-horizontal-menu/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 20:38:48 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS horizontal menu]]></category>
		<category><![CDATA[CSS menu]]></category>
		<category><![CDATA[horizontal]]></category>
		<category><![CDATA[menu]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1103</guid>
		<description><![CDATA[This is a snippet of simple CSS horizontal menu. First of all &#8211; we&#8217;re going to create a HTML structure for our CSS horizontal menu. Here it is: &#60;ul id=&#34;nav&#34;&#62; &#60;li&#62;&#60;a href=&#34;#&#34;&#62;Magazine&#60;/a&#62;&#60;/li&#62; &#60;li class=&#34;active&#34;&#62;&#60;a href=&#34;#&#34;&#62;Snippets&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#34;#&#34;&#62;Portfolio&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#34;#&#34;&#62;Contact&#60;/a&#62;&#60;/li&#62; &#60;/ul&#62; Now &#8211; our CSS horizontal menu it looks like a regular list so let&#8217;s style [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fcss-horizontal-menu%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fcss-horizontal-menu%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is a snippet of simple <strong>CSS horizontal menu</strong>. First of all &#8211; we&#8217;re going to create a HTML structure for our <strong>CSS horizontal menu</strong>. Here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;ul id=&quot;nav&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Magazine&lt;/a&gt;&lt;/li&gt;
    &lt;li class=&quot;active&quot;&gt;&lt;a href=&quot;#&quot;&gt;Snippets&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Portfolio&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></div></div>

<p>Now &#8211; our <strong>CSS horizontal menu</strong> it looks like a regular list so let&#8217;s style it with some CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">48px</span><span style="color: #00AA00;">;</span>
    box-shadow<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#0099cc</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f8f8f8</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.active</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f8f8f8</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#nav</span> a <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Finally &#8211; we got ourselves one nice CSS horizontal menu which we can implement easily to our website. Here is the demo:</p>
<ul id="nav">
<li><a href="http://stuntcoders.com/">Magazine</a></li>
<li class="active"><a href="http://stuntsnippets.com/">Snippets</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="http://stuntcoders.com/contact-us/">Contact</a></li>
</ul>
<style>
#nav {
    min-height:48px;
    box-shadow:0 0 5px #0099cc;
    background: #eee;
    display:block;
    margin:15px 0;
    padding:0 10px;
}
#nav li {
    float: left;
    padding: 15px 20px;
    list-style: none;
    background: transparent;
}
#nav li:hover {
    background: #f8f8f8;
}
#nav li.active {
    background: #f8f8f8;
}
#nav a {
    font-size: 16px;
}
</style>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/css-horizontal-menu/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=cKnei_KuKPg:o7ctveeDMnE:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=cKnei_KuKPg:o7ctveeDMnE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=cKnei_KuKPg:o7ctveeDMnE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=cKnei_KuKPg:o7ctveeDMnE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=cKnei_KuKPg:o7ctveeDMnE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/cKnei_KuKPg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/css-horizontal-menu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/css-horizontal-menu/</feedburner:origLink></item>
		<item>
		<title>CSS3 inner shadow</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/nQrfkYF7XCc/</link>
		<comments>http://stuntsnippets.com/css3-inner-shadow/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 07:22:15 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[CSS3 inner shadow]]></category>
		<category><![CDATA[inner]]></category>
		<category><![CDATA[inner shadow]]></category>
		<category><![CDATA[shadow]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1093</guid>
		<description><![CDATA[Ever wondered how to make CSS3 inner shadow? Quite easy actually! Take a look at this CSS3 inner shadow snippet, and example below it. -moz-box-shadow: inset 0 4px 6px rgba&#40;0,0,0,.4&#41;; -webkit-box-shadow: inset 0 4px 6px rgba&#40;0,0,0,.4&#41;; box-shadow: inset 0 4px 6px rgba&#40;0,0,0,.24&#41;; Example of CSS3 inner shadow CSS3 inner shadow I hope you&#8217;ll enjoy using [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fcss3-inner-shadow%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fcss3-inner-shadow%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Ever wondered how to make <strong>CSS3 inner shadow</strong>? Quite easy actually! Take a look at this CSS3 inner shadow snippet, and example below it.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">4px</span> <span style="color: #933;">6px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.4<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">4px</span> <span style="color: #933;">6px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.4<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">4px</span> <span style="color: #933;">6px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.24<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></pre></div></div>

<h3>Example of CSS3 inner shadow</h3>
<div style="-moz-box-shadow: inset 0 4px 6px rgba(0,0,0,.4);-webkit-box-shadow: inset 0 4px 6px rgba(0,0,0,.4);box-shadow: inset 0 4px 6px rgba(0,0,0,.24);width: 400px;padding:50px 0;text-align:center;background:#f8f8f8;">CSS3 inner shadow</div>
<p>I hope you&#8217;ll enjoy using this snippet to make nice effects with <strong>CSS3 inner shadow</strong> on your website.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/css3-inner-shadow/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=nQrfkYF7XCc:5yuTrFOxzt4:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=nQrfkYF7XCc:5yuTrFOxzt4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=nQrfkYF7XCc:5yuTrFOxzt4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=nQrfkYF7XCc:5yuTrFOxzt4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=nQrfkYF7XCc:5yuTrFOxzt4:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/nQrfkYF7XCc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/css3-inner-shadow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/css3-inner-shadow/</feedburner:origLink></item>
		<item>
		<title>Google Analytics results on your website</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/B1bNQosTlGQ/</link>
		<comments>http://stuntsnippets.com/google-analytics-results-on-your-website/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 15:29:58 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1089</guid>
		<description><![CDATA[Have you ever wondered if you could let user see his website visits on his own admin page without having to leave backend of his system? I have&#8230; Actually &#8211; the CMS I made for my clients (written in Zend Framework) has this option for quite some time, and users love it. So &#8211; in [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fgoogle-analytics-results-on-your-website%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fgoogle-analytics-results-on-your-website%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Have you ever wondered if you could let user see his website visits on his own admin page without having to leave backend of his system? I have&#8230;</p>
<p>Actually &#8211; the CMS I made for my clients (written in Zend Framework) has this option for quite some time, and users love it.</p>
<p>So &#8211; in order to implement this function on your own website (written in Zend Framework) I have shared following code. First &#8211; copy model:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Default_Model_Analytics
<span style="color: #009900;">&#123;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> auth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_email@domain.com&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$passwd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		try <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> Zend_Gdata_ClientLogin<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$passwd</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;analytics&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>catch <span style="color: #009900;">&#40;</span>Zend_Gdata_App_CaptchaRequiredException <span style="color: #000088;">$cre</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'URL of CAPTCHA image: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cre</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCaptchaUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Token ID: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cre</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCaptchaToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Zend_Gdata_App_AuthException <span style="color: #000088;">$ae</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Problem authenticating: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ae</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exception</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdClient</span><span style="color: #339933;">,</span> <span style="color: #000088;">$startDate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'2010-07-01'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$endDate</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ga:region&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ga:city&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$metrics</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ga:visits&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ga:pageviews&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdClient</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$endDate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$endDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		try <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$reportURL</span>	<span style="color: #339933;">=</span>	<span style="color: #0000ff;">&quot;https://www.google.com/analytics/feeds/data?ids=ga:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$yourAccountNumber</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;&quot;</span> <span style="color: #339933;">.</span>
							<span style="color: #0000ff;">&quot;dimensions=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #339933;">@</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;&quot;</span> <span style="color: #339933;">.</span>
							<span style="color: #0000ff;">&quot;metrics=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #339933;">@</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$metrics</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;&quot;</span> <span style="color: #339933;">.</span>
							<span style="color: #0000ff;">&quot;start-date=<span style="color: #006699; font-weight: bold;">{$startDate}</span>&amp;&quot;</span> <span style="color: #339933;">.</span>
							<span style="color: #0000ff;">&quot;end-date=<span style="color: #006699; font-weight: bold;">{$endDate}</span>&amp;&quot;</span> <span style="color: #339933;">.</span>
							<span style="color: #0000ff;">&quot;sort=-ga:visits&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFeed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$reportURL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$titleRow</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// To output a row of column labels</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;table&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$rep</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$titleRow</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">extensionElements</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$elem</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$titles</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$elem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">extensionAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$titles</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$titleRow</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">extensionElements</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$elem</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$elem</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">extensionAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Zend_Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Caught exception: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Message: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Then &#8211; run following code in your controller so user can see Analytics results:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$analyticsModel</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_Analytics<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//get: date start and date end of Analytics results</span>
<span style="color: #000088;">$postParams</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$gdata</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$analyticsModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">auth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$analyticsModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdata</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postParams</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'year1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'-'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$postParams</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'month1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'-01'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postParams</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'year2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'-'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$postParams</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'month2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'-31'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Notice:</em> This is not the proper way to write code in Zend Framework, but is used as an example.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/google-analytics-results-on-your-website/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=B1bNQosTlGQ:FIAi7TdDLzA:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=B1bNQosTlGQ:FIAi7TdDLzA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=B1bNQosTlGQ:FIAi7TdDLzA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=B1bNQosTlGQ:FIAi7TdDLzA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=B1bNQosTlGQ:FIAi7TdDLzA:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/B1bNQosTlGQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/google-analytics-results-on-your-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/google-analytics-results-on-your-website/</feedburner:origLink></item>
		<item>
		<title>JavaScript translate</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/UaWjmy5BvbU/</link>
		<comments>http://stuntsnippets.com/javascript-translate/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 13:18:00 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript translate]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1063</guid>
		<description><![CDATA[When making a multilingual application programmers usually find themselves in a bit of a problem when having need to translate things in JavaScript as those JavaScript files are usually separated from PHP so they can&#8217;t call translate function for this purpose. To solve this problem I have created JavaScript translate class, so please check following [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fjavascript-translate%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fjavascript-translate%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When making a multilingual application programmers usually find themselves in a bit of a problem when having need to translate things in JavaScript as those JavaScript files are usually separated from PHP so they can&#8217;t call translate function for this purpose. To solve this problem I have created <strong>JavaScript translate</strong> class, so please check following snippet to find how to define JavaScript translate class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> javaScriptTranslate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> translations <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
        translate<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> translations<span style="color: #009900;">&#91;</span>text<span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> text<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> translations<span style="color: #009900;">&#91;</span>text<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        init<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>translationArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            translations <span style="color: #339933;">=</span> translationArray<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>After you have defined your JavaScript translate class you need to load list of translations (usually saved as PHP array, and if not &#8211; convert it to PHP array):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">javaScriptTranslate.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;?</span>php echo json_encode<span style="color: #009900;">&#40;</span>$translation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">?&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now &#8211; all you have to do is call function <strong>translate</strong> from <strong>javaScriptTranslate</strong> class and you&#8217;ll find it really easy. See for yourself in following snippet:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>javaScriptTranslate.<span style="color: #660066;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello dear friend - I am JavaScript translate class'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><em>Notice:</em> Your PHP value of variable $translation should be an associative array where key is value you are translating and value is translation of desired value. Example for German translation in this snippet would be following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$translation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'Hello dear friend - I am JavaScript translate class'</span> <span style="color: #339933;">=&gt;</span> 
      <span style="color: #0000ff;">'Hallo lieber Freund - ich bin JavaScript übersetzen Klasse'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/javascript-translate/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=UaWjmy5BvbU:f2ehbjGdkaQ:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=UaWjmy5BvbU:f2ehbjGdkaQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=UaWjmy5BvbU:f2ehbjGdkaQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=UaWjmy5BvbU:f2ehbjGdkaQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=UaWjmy5BvbU:f2ehbjGdkaQ:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/UaWjmy5BvbU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/javascript-translate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/javascript-translate/</feedburner:origLink></item>
		<item>
		<title>Access Magento session from external site</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/pBesSVKHuaQ/</link>
		<comments>http://stuntsnippets.com/access-magento-session-from-external-site/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 21:05:25 +0000</pubDate>
		<dc:creator>Relja Damnjanovic</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1053</guid>
		<description><![CDATA[So, there is a simple way to access the running Magento session from outside the installation folder. The magic happens here: 1 2 3 4 5 6 7 8 9 10 11 12 $mageFilename = realpath&#40;‘mymagentoshop/app/Mage.php’&#41;; require_once&#40; $mageFilename &#41;; umask&#40;0&#41;; &#160; Mage::app&#40;&#41;; Mage::getSingleton&#40;‘core/session’, array&#40;‘name’ =&#62; ‘frontend’&#41;&#41;; $session = Mage::getSingleton&#40;‘customer/session’&#41;; &#160; if&#40;$session-&#62;isLoggedIn&#40;&#41;&#41; echo ‘LOGGED IN’; else [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Faccess-magento-session-from-external-site%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Faccess-magento-session-from-external-site%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>So, there is a simple way to access the running Magento session from outside the installation folder. The magic happens here:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mageFilename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span>‘mymagentoshop<span style="color: #339933;">/</span>app<span style="color: #339933;">/</span>Mage<span style="color: #339933;">.</span>php’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$mageFilename</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span>‘core<span style="color: #339933;">/</span>session’<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>‘name’ <span style="color: #339933;">=&gt;</span> ‘frontend’<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span>‘customer<span style="color: #339933;">/</span>session’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isLoggedIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #b1b100;">echo</span> ‘LOGGED IN’<span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>
   <span style="color: #b1b100;">echo</span> ‘NOT LOGGED IN’<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The line 5 presents the Magento initialization, and from there you can call any Magento core API functions and procedures. In order for session to work properly (as one) in both sites, you need to retrieve it, and that is exactly what is done on the lines 6 (for the core session) and 7 (for the customer session). Later in our example we&#8217;re checking whether the customer is logged in or not, but you can do whatever you want!</p>
<p>Oh yes, on more thing &#8211; <b>Use SID on Frontend</b> setting in the Magento admin (System -> Configuration -> Web -> Session Validation Settings) MUST be set to <b>YES</b>, otherwise it won&#8217;t work.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/access-magento-session-from-external-site/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=pBesSVKHuaQ:UosW3Fd_tq4:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=pBesSVKHuaQ:UosW3Fd_tq4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=pBesSVKHuaQ:UosW3Fd_tq4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=pBesSVKHuaQ:UosW3Fd_tq4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=pBesSVKHuaQ:UosW3Fd_tq4:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/pBesSVKHuaQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/access-magento-session-from-external-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/access-magento-session-from-external-site/</feedburner:origLink></item>
		<item>
		<title>jQuery refresh page</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/FhwB7rtrDK8/</link>
		<comments>http://stuntsnippets.com/jquery-refresh-page/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 15:30:47 +0000</pubDate>
		<dc:creator>Dejan Jacimovic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery refresh page]]></category>
		<category><![CDATA[refresh page]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1049</guid>
		<description><![CDATA[Sometimes you really want to refresh page when using jQuery events. So &#8211; in order to refresh page on event (in this case click) use following snippet and reload current page. 1 2 3 jQuery&#40;'#refresh-link'&#41;.click&#40;function&#40;&#41; &#123; location.reload&#40;&#41;; &#125;&#41;;]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fjquery-refresh-page%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fjquery-refresh-page%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Sometimes you really want to <strong>refresh page</strong> when using jQuery events. So &#8211; in order to refresh page on event (in this case click) use following snippet and reload current page.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#refresh-link'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        location.<span style="color: #660066;">reload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/jquery-refresh-page/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=FhwB7rtrDK8:DjtijK90bcM:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=FhwB7rtrDK8:DjtijK90bcM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=FhwB7rtrDK8:DjtijK90bcM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=FhwB7rtrDK8:DjtijK90bcM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=FhwB7rtrDK8:DjtijK90bcM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/FhwB7rtrDK8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/jquery-refresh-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/jquery-refresh-page/</feedburner:origLink></item>
		<item>
		<title>Put data into Magento session</title>
		<link>http://feedproxy.google.com/~r/stuntsnippets/~3/W1eUB6nNRqU/</link>
		<comments>http://stuntsnippets.com/put-data-into-magento-session/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 09:45:16 +0000</pubDate>
		<dc:creator>Relja Damnjanovic</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://stuntsnippets.com/?p=1045</guid>
		<description><![CDATA[Suppose you have to access your Magento session from outside the Magento system (and it&#8217;s folders), and also, you want to put some relevant data into session and retrieve it on the other side. The following procedure on the Magento side will allow you to do that: 1 Mage::getSingleton&#40;'core/session'&#41;-&#62;setMyData&#40;'exampleString'&#41;; where MyData is the name of [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 10px; clear: both;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstuntsnippets.com%2Fput-data-into-magento-session%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstuntsnippets.com%2Fput-data-into-magento-session%2F&amp;style=normal&amp;service=cli.gs&amp;service_api=b67df0a250a7f070ac77eb0b22b289fc&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Suppose you have to access your Magento session from outside the Magento system (and it&#8217;s folders), and also, you want to put some relevant data into session and retrieve it on the other side. The following procedure on the Magento side will allow you to do that:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMyData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exampleString'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>where MyData is the name of your attribute, and you will retrieve it with getMyData. Here, you can use any name you wish, but try to avoid names which can collide with the existing API and reserved words.</p>
<p>On the other side you can access the session and get the data with the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mageFilename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MageShop/app/Mage.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$mageFilename</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'frontend'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span> <span style="color: #000088;">$session</span> <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMyData</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>On the line 1 the access to the main Magento folder is required, so here you either specify relative or absolute path to the Mage.php. The parameter true on the line 7 function call is the flag for &#8220;retrieve and remove from session&#8221; . </p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin: 10px 0;width:68px;"><g:plusone size="standard" count="1" href="http://stuntsnippets.com/put-data-into-magento-session/"></g:plusone></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=W1eUB6nNRqU:hiTOvpwyetA:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=W1eUB6nNRqU:hiTOvpwyetA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=W1eUB6nNRqU:hiTOvpwyetA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?i=W1eUB6nNRqU:hiTOvpwyetA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stuntsnippets?a=W1eUB6nNRqU:hiTOvpwyetA:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/stuntsnippets?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stuntsnippets/~4/W1eUB6nNRqU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://stuntsnippets.com/put-data-into-magento-session/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://stuntsnippets.com/put-data-into-magento-session/</feedburner:origLink></item>
	</channel>
</rss>

