<?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>Side Notes &#187; session</title>
	<atom:link href="http://blog.snaky.org/tag/session/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.snaky.org</link>
	<description>Relax, its only ONES and ZEROS!</description>
	<lastBuildDate>Sun, 11 Oct 2009 12:20:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
<link>http://blog.snaky.org</link>
<url>http://blog.snaky.org/wp-content/plugins/maxblogpress-favicon/icons/favicon-26.ico</url>
<title>Side Notes</title>
</image>
		<item>
		<title>Doppelposting vermeiden</title>
		<link>http://blog.snaky.org/2009/08/13/doppelposting-vermeiden/</link>
		<comments>http://blog.snaky.org/2009/08/13/doppelposting-vermeiden/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 15:00:04 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[doppel]]></category>
		<category><![CDATA[double]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://blog.snaky.org/?p=110</guid>
		<description><![CDATA[<img src="http://blog.snaky.org/wp-content/uploads/2008/07/php_16.png" width="16" height="16" alt="" title="PHP" /><br/>Das aktualisieren der Seite wird oftmals von Besuchern auch nach einem Forumular benutzt. Damit jedoch kein Doppelposting entsteht erkläre ich kurz eine Funktion. Hierzu muss bereits am Anfang der php-Datei eine Session mit session_start(); gestartet werden. Zusätzlich muss in das Formular ein zusätzliches Feld hinzugefügt werden. Der name kann natürlich Frei gewählt werden. echo &#34;&#60;input [...]]]></description>
			<content:encoded><![CDATA[<img src="http://blog.snaky.org/wp-content/uploads/2008/07/php_16.png" width="16" height="16" alt="" title="PHP" /><br/><p>Das aktualisieren der Seite wird oftmals von Besuchern auch nach einem Forumular benutzt. Damit jedoch kein Doppelposting entsteht erkläre ich kurz eine Funktion.</p>
<p>Hierzu muss bereits am Anfang der php-Datei eine Session mit session_start(); gestartet werden.<br />
Zusätzlich muss in das Formular ein zusätzliches Feld hinzugefügt werden. Der name kann natürlich Frei gewählt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input name='rft' type='hidden' value='&quot;</span><span style="color: #339933;">.</span>random_form_token<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Bei der Verarbeitung des Formulars muss nun nurnoch vor dem Speichern dies hier abgeprüft werden.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>random_form_token<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rft'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Schreiben</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Doppelposting erkannt</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Und nun hier noch die Funktion selbst.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> random_form_token<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">NULL</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;">$value</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$token</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sha256&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;tanzmal&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><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: #009900;">&#91;</span><span style="color: #0000ff;">'random_form_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$token</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$token</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'random_form_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'random_form_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.snaky.org/2009/08/13/doppelposting-vermeiden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
