<?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>testx &#187; php login</title>
	<atom:link href="http://www.testx.ch/tag/php-login/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.testx.ch</link>
	<description></description>
	<lastBuildDate>Wed, 02 Nov 2011 17:54:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP Login mit AJAX</title>
		<link>http://www.testx.ch/2010/01/php-login-mit-ajax/</link>
		<comments>http://www.testx.ch/2010/01/php-login-mit-ajax/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 13:26:43 +0000</pubDate>
		<dc:creator>Fredi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[php login]]></category>
		<category><![CDATA[php tutorial]]></category>

		<guid isPermaLink="false">http://www.testx.ch/?p=760</guid>
		<description><![CDATA[Ich habe bereits in diesem Artikel erklärt, wie man ein PHP Login mit einer MySQL Datenbank erstellt. Nun möchte ich in diesem Artikel erklären, wie man ein PHP Login mit einer schöneren Benutzeroberfläche programmiert. Der Vorteil besteht darin, dass die Seite nicht neu geladen wird, wenn man sich einloggt. Zusätzlich werden wir das Passwort mit [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe bereits in <a href="http://www.testx.ch/2009/05/einfaches-php-login/">diesem</a> Artikel erklärt, wie man ein PHP Login mit einer MySQL Datenbank erstellt. Nun möchte ich in diesem Artikel erklären, wie man ein PHP Login mit einer schöneren Benutzeroberfläche programmiert. Der Vorteil besteht darin, dass die Seite nicht neu geladen wird, wenn man sich einloggt. Zusätzlich werden wir das Passwort mit md5 verschlüsseln, um es nicht einfach so lesbar zu machen.</p>
<p>Für dieses Tutorial hier, brauche ich viele Dinge aus dem, welches ich oben verlinkt habe. Deshalb ist es von Vorteil, wenn man sich das Tutorial bereits durchgelesen hat, bevor man mit diesem hier beginnt.</p>
<p>Als erstes solltet ihr alle Dateien aus dem anderen Tutorial erstellen und testen, ob das ganze so funktioniert. Wenn ihr das getan habt, beginnen wir mit der Verschlüsselung der Daten. Man muss sich das so vorstellen, dass beim Eintragen in der Datenbank nicht das Passwort in Klartext abgelegt wird, sondern nur der Hashwert. Wenn sich nun jemand einloggen will, wird das Passwort zuerst auch zu einem md5 Hash verarbeitet und diese beiden Werte dann verglichen.</p>
<p>Dazu müssen wir in der Login.php folgendes verändern:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connect.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$username</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span><span style="color: #339933;">=</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT username, password FROM users WHERE username ='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;konnte nicht selecten!!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</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: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Username oder Passwort falsch!&quot;</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>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Username oder Passwort falsch!&quot;</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>
<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Du bist erfolgreich registriert!&quot;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Dadurch wird das empfangene Passwort direkt als Hash in der Variable gespeichert. Das dies funktionieren kann, muss das Passwort auch als md5 Hash in der Datenbank vorhanden sein. Da ich hier keine Registrierungsfunktion einbaue, muss man aus dem Passwort manuell den md5 Hash generieren. Im Web gibt es zahlreiche Websiten, die das anbieten. Falls man so etwas selber machen will, reicht dieser kleine PHP Code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php <span style="color: #b1b100;">echo</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Dein Passwort'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> ?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Als nächstes müssen wir die loginform.php anpassen. Zuerst benötigen wir aber <a href="http://jquery.com/">JQuery</a>. Wenn wir es heruntergeladen haben, verschieben wir die Datei ins gleiche Verzeichniss wie die anderen Dateien und verändern die loginform.php folgendermassen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;!</span>DOCTYPE HTML <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>html<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>head<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>title<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>Einfaches Loginscript <span style="color: #339933;">-</span>Tutorial<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>title<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;jquery-1.3.2.min.js&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; 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: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#submit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>click<span style="color: #009900;">&#40;</span><span style="color: #000000; 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: #339933;">.</span>post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;login.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>username<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#username&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> password<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#userdata&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#result&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span>data<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>
<span style="color: #009900;">&#125;</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>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>head<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>body<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;result&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>div<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;userdata&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
Deine Benutzerdaten<span style="color: #339933;">:&amp;</span>lt<span style="color: #339933;">;</span>br<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
Benutzername<span style="color: #339933;">:</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;35&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span>br<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
Passwort<span style="color: #339933;">:</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;35&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span>br<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Login&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>div<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>body<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>html<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Nun sollte man alle Dateien aus dem anderen Tutorial erstellt haben, die Dateien wie hier beschrieben anpassen  und die MySQL Einträge und Konfiguration vornehmen. Wenn das alles getan ist, kann man die Daten auf einen Webserver hochladen und das ganze Testen. Wenn ihr auf Login klickt, sollte die Loginmaske verschwinden und die Erfolgs-, oder Fehlermeldung erscheinen.</p>
<p>Falls ihr einen Fehler entdeckt oder Fragen habt, schreibt doch einfach einen Kommentar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.testx.ch/2010/01/php-login-mit-ajax/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Einfaches PHP Login</title>
		<link>http://www.testx.ch/2009/05/einfaches-php-login/</link>
		<comments>http://www.testx.ch/2009/05/einfaches-php-login/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:30:43 +0000</pubDate>
		<dc:creator>Fredi</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[loginscript tutorial]]></category>
		<category><![CDATA[php login]]></category>
		<category><![CDATA[php tutorial]]></category>

		<guid isPermaLink="false">http://www.testx.ch/?p=519</guid>
		<description><![CDATA[Hallo Ich möchte euch zeigen, wie man mit PHP ein simples Loginscript mit MySQL erstellt. Ich setze voraus, dass ihr ein bisschen PHP und HTML könnt, da es sich sonst sehr in die Länge ziehen würde. Ausserdem übernehme ich keine Garantie und keine Haftung für die Scripte und ihre Sicherheit sowie Funktionsfähigkeit. Unser Script wird [...]]]></description>
			<content:encoded><![CDATA[<p>Hallo</p>
<p>Ich möchte euch zeigen, wie man mit PHP ein simples Loginscript mit MySQL erstellt. Ich setze voraus, dass ihr ein bisschen PHP und HTML könnt, da es sich sonst sehr in die Länge ziehen würde.</p>
<p>Ausserdem übernehme ich keine Garantie und keine Haftung für die Scripte und ihre Sicherheit sowie Funktionsfähigkeit.</p>
<p>Unser Script wird sich in folgende Dateien aufteilen:</p>
<ul>
<li>login.php</li>
<li>loginform.php</li>
<li>checker.php</li>
<li>connect.php</li>
<li>config.php</li>
</ul>
<p>Fangen wir mit der login.php an. Sie soll die Daten von der loginform.php empfangen und überprüfen. Es empfängt die Daten, verbindet sich zur Datenbank, überprüft den Code auf Schadcode und vergleicht die Werte. Wenn sie ok sind, registriert es die Session.</p>
<h4>login.php</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connect.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$username</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT username, password FROM users WHERE username ='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;konnte nicht selecten!!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</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: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Username oder Passwort falsch!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'location:loginform.php'</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>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Username oder Passwort falsch!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'location:loginform.php'</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>
<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Du bist erfolgreich registriert!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Die loginform.php soll die Daten vom User entgegennehmen, also dort, wo man die Daten eingibt.</p>
<h4>loginform.php</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE HTML <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Einfaches Loginscript <span style="color: #339933;">-</span>Tutorial<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
Deine Benutzerdaten<span style="color: #339933;">:&lt;</span>br<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;login.php&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> <span style="color: #339933;">&gt;</span>
Benutzername<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;username&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;35&quot;</span><span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">&gt;</span>
Passwort<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;35&quot;</span><span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Login&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Der checker.php soll auf jeder Seite überprüfen, ob der User bereits eingelogt ist. Wenn nicht, soll er ihn zum Login weiterleiten.</p>
<h4>checker.php</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Du hast keinen Zutritt!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'location:loginform.php'</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>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Die connect.php soll die Verbindung zur Datenbank vereinfachen, in dem sie die Funktion in eine Datei vereint, die jedes Script includen kann ohne den Befehl dauernd wiederholen zu müssen.</p>
<h4>connect.php</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dbhost</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dbuser</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dbpassword</span>&quot;</span><span style="color: #009900;">&#41;</span> OR <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Konnte keine Verbindung aufbauen.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dbdatenbank</span>&quot;</span><span style="color: #009900;">&#41;</span> OR <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Konnte keine Verbindung aufbauen.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Die config.php speichert alle Daten zur Datenbank verbindung ab.</p>
<h4>config.php</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$dbhost</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbuser</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbpassword</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;passwort&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbdatenbank</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Datenbankname&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Nun muss man in der config.php die Daten der MySQL Datenbank angeben. Dann kann man in der Datenbank eine neue Tabelle mit dem Namen users erstellen. In diese gibt man drei Felder ein: id, username und password. Die id stellt man auf Primary Key und auf Auto Increment.</p>
<p>Nun kann man zwei Werte eintragen und sich im loginform.php anmelden. Auf jede zu schützende Seite bindet man als erstes die checker.php ein.</p>
<p>Wenn man das Script ernsthaft verwenden will, muss man unbedingt noch mit einer Verschlüsselung der Daten arbeiten.</p>
<p>Falls es Probleme mit den Scripts gibt oder wenn ihr einen Fehler entdeckt, bitte ich euch einen Kommentar zu schreiben.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.testx.ch/2009/05/einfaches-php-login/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Content Delivery Network via Amazon Web Services: CloudFront: dy8cq650okdxd.cloudfront.net

Served from: www.testx.ch @ 2012-02-04 22:38:16 -->
