<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>AG Prime Blog &#187; tips&amp;tricks</title>
	<atom:link href="http://blog.ag-prime.com/tag/tipstricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ag-prime.com</link>
	<description>Afla ce idei ne-au mai venit...</description>
	<lastBuildDate>Thu, 15 Dec 2011 10:55:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Stiati ca? Nu poti defini constante array in PHP!</title>
		<link>http://blog.ag-prime.com/2008/12/stiati-ca-nu-poti-defini-constante-array-in-php/</link>
		<comments>http://blog.ag-prime.com/2008/12/stiati-ca-nu-poti-defini-constante-array-in-php/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 15:31:54 +0000</pubDate>
		<dc:creator>gabriel.ungureanu</dc:creator>
				<category><![CDATA[Stiati ca?]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://blog.ag-prime.com/?p=66</guid>
		<description><![CDATA[Ciudat, interesant totusi ca in PHP se folosesc foarte des array-urile. Oricum ideea e ca nu poti defini constante in PHP, adica asa: 1 2 3 // it will not work like this define&#40;'MY_ARRAY', array &#40;'one', 'two', 'three'&#41;&#41;; echo MY_ARRAY&#91;0&#93;; // undefined index 0 Dar sunt vreo doua variante prin care poti face asta. Una [...]]]></description>
			<content:encoded><![CDATA[<p>Ciudat, interesant totusi ca in PHP se folosesc foarte des array-urile.</p>
<p>Oricum ideea e ca nu poti defini constante in PHP, adica asa:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// it will not work like this</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MY_ARRAY'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'two'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'three'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> MY_ARRAY<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// undefined index 0</span></pre></td></tr></table></div>

<p>Dar sunt vreo doua variante prin care poti face asta. Una ar fi sa salvezi de exemplu un string in constanta:</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: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MY_ARRAY'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'one,two,three'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$my_local_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span>MY_ARRAY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_local_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// it will work</span>
<span style="color: #666666; font-style: italic;">// result: one</span></pre></td></tr></table></div>

<p>sau poti sa serializezi obiectul (cea mai recomandata), astfel poti sa salvezi array-uri sau orice alte obiecte complexe:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// va recomand aceasta varianta, e cea mai simpla si are cea mai larga aplicabilitate</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;one&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;two&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;three&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// variabila de definit</span>
&nbsp;
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MY_ARRAY'</span><span style="color: #339933;">,</span><span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// salvam obiectul serializat</span>
<span style="color: #000088;">$my_local_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span>MY_ARRAY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// il deserializam pentru a-l putea folosi</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_local_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// and there you go :)</span>
<span style="color: #666666; font-style: italic;">// result: 1</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.ag-prime.com/2008/12/stiati-ca-nu-poti-defini-constante-array-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP header() and then die()</title>
		<link>http://blog.ag-prime.com/2008/12/php-header-and-then-die/</link>
		<comments>http://blog.ag-prime.com/2008/12/php-header-and-then-die/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 18:25:24 +0000</pubDate>
		<dc:creator>gabriel.ungureanu</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://blog.ag-prime.com/?p=46</guid>
		<description><![CDATA[Usualy, header() function can be used to change page headers, linke header(&#8220;Content-type: jpg&#8217;); But, a most use case is, for example when you want to check user login: 1 2 3 4 5 6 7 8 9 &#60;?php &#160; if &#40;!$user-&#62;isLogged&#40;&#41;&#41; &#123; &#160; header&#40;&#34;Location: login.php&#34;&#41;; &#160; &#125; &#160; ?&#62; The problem is, there are some [...]]]></description>
			<content:encoded><![CDATA[<p>Usualy, <em>header()</em> function can be used to change page headers, linke <em>header(&#8220;Content-type: jpg&#8217;);</em></p>
<p>But, a most use case is, for example when you want to check user login:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isLogged</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>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: login.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The problem is, there are some cases when the script continues to run after header(&#8220;Location: &#8220;), and you should allways die() after the header(&#8220;Location: &#8220;).<br />
Like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isLogged</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>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: login.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</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;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.ag-prime.com/2008/12/php-header-and-then-die/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

