cvs: peardoc /en/package/authentication/auth intro.xml
| From: | Martin Jansen | Date: | Sat, 29 Mar 2003 14:22:29 +0000 |
| Subject: | cvs: peardoc /en/package/authentication/auth intro.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-558@lists.php.net to get a copy of this message | ||
mj Sat Mar 29 09:22:29 2003 EDT
Modified files:
/peardoc/en/package/authentication/auth intro.xml
Log:
* Revamping big parts of the Intro
Index: peardoc/en/package/authentication/auth/intro.xml diff -u peardoc/en/package/authentication/auth/intro.xml:1.4 peardoc/en/package/authentication/auth/intro.xml:1.5 --- peardoc/en/package/authentication/auth/intro.xml:1.4 Sat Mar 29 09:11:18 2003 +++ peardoc/en/package/authentication/auth/intro.xml Sat Mar 29 09:22:29 2003 @@ -1,23 +1,22 @@ -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="package.authentication.auth.intro"> - <refnamediv> - <refname>Introduction</refname> - <refpurpose>A usage example</refpurpose> - </refnamediv> - <refsect1 id="packages.authentication.auth.intro.example"> - <title>Auth tutorial</title> - <simpara> - Our goal during this "mini tutorial" is to set up a system that - secures your site with an easy to use authentication mechanism. - </simpara> - <para> - At the top of the site to secured, place the - following code snippet: - </para> - <example> - <title>Typical usage example for <classname>PEAR::Auth</classname></title> - <programlisting role="php"> - <![CDATA[ + <refnamediv> + <refname>Introduction</refname> + <refpurpose>A usage example</refpurpose> + </refnamediv> + <refsect1 id="packages.authentication.auth.intro.example"> + <title>Auth tutorial</title> + <simpara> + Our goal during this "mini tutorial" is to set up a system that + secures your site with an easy to use authentication mechanism. + </simpara> + <para> + At the top of the site to secured, place the following code snippet: + </para> + <example> + <title>Typical usage example for <classname>PEAR::Auth</classname></title> + <programlisting role="php"> + <![CDATA[ require_once "Auth/Auth.php"; function loginFunction() @@ -34,7 +33,6 @@ } $dsn = "mysql://user:password@localhost/database"; - $a = new Auth("DB", $dsn, "loginFunction"); $a->start(); @@ -44,30 +42,33 @@ * The output of your site goes here. */ } - ]]> - </programlisting> - </example> + ]]> + </programlisting> <para> This few lines of code instantiate the authentication system. </para> <para> The first line in the above script includes the file from your PEAR directory. It contains all the necessary code to run - PEAR::Auth. Next, we define a function to display the login form - which the visitor of your page has to use to enter his login - data. You can change all the HTML formating in this function. - </para> - <warning> - <simpara> - You can change all the HTML formatting in the function, but you - cannot change the names of the input boxes in the form. They have - to be "username" and "password". - </simpara> - </warning> + <classname>PEAR::Auth</classname>. Next, we define a function + to display the login form which the visitor of your page has to + use to enter his login data. You can change all the <acronym>HTML</acronym> + formatting in this function. + </para> + <para> + <warning> + <simpara> + You can change all the HTML formatting in the function, but you + cannot change the names of the input boxes in the form. They have + to be <literal>username</literal> and <literal>password</literal>. + </simpara> + </warning> + </para> <para> Since we want to use a database to verify the login data, we now - create the variable $dsn, it contains a valid DSN string that will - be used to connect to the database via PEAR::DB. For the default + create the variable <varname>$dsn</varname>, it contains a valid + DSN string that will be used to connect to the database via + <link linkend="package.database.db">PEAR::DB</link>. For the default database table schema or to use a different storage container, please see below for more information. </para> @@ -82,50 +83,52 @@ </para> <para> Now our authentication object is initialized and we need to check - if the user is logged in. This is done via the function + if the user is logged in. This is done via the method <function>getAuth</function>. If it returns true, we can pass the content of our page to the user. </para> - <warning> - <para> - For now one cannot use - <programlisting role="php"> - <![CDATA[ -$auth = new Auth(...); - ]]> - </programlisting> - with register_globals=on, because $auth is also the name of - the session variable, that is used by PEAR::Auth. - </para> - </warning> - <para> - <example> - <title>Using optional authentication</title> - <programlisting role="php"> - <![CDATA[ + <para> + <warning> + <para> + For now one cannot use + <programlisting role="php"> + <![CDATA[ + $auth = new Auth(...); + ]]> + </programlisting> + with <literal>register_globals=on</literal>, because + <varname>$auth</varname> is also the name of the session variable, + that is internally used by <classname>PEAR::Auth</classname>. + </para> + </warning> + </para> + </example> + <example> + <title>Using optional authentication</title> + <programlisting role="php"> + <![CDATA[ require_once "Auth/Auth.php"; function loginFunction() { - /** - * Change the HTML output so that it fits to your - * application. - */ - echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?login=1\">"; - echo "<input type=\"text\" name=\"username\">"; - echo "<input type=\"password\" name=\"password\">"; - echo "<input type=\"submit\">"; - echo "</form>"; + /** + * Change the HTML output so that it fits to your + * application. + */ + echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?login=1\">"; + echo "<input type=\"text\" name=\"username\">"; + echo "<input type=\"password\" name=\"password\">"; + echo "<input type=\"submit\">"; + echo "</form>"; } if ($_GET['login'] == 1) { - $optional = true; + $optional = true; } else { - $optional = false; + $optional = false; } $dsn = "mysql://user:password@localhost/database"; - $a = new Auth("DB", $dsn, "loginFunction", $optional); $a->start(); @@ -133,25 +136,26 @@ echo "Everybody can see this text!<br />"; if (!isset($_GET['login'])) { - echo "<a href=\"test.php?login=1\">Click here to log in</a>\n"; + echo "<a href=\"test.php?login=1\">Click here to log in</a>\n"; } if ($a->getAuth()) { - echo "One can only see this if he is logged in!"; + echo "One can only see this if he is logged in!"; } ]]> - </programlisting> - </example> - This is a pretty nice example for the optional login feature: The - last parameter <parameter>$optional</parameter> can be either true - or false. If it is false, the login form is not shown and the user - only sees the text "Everybody can see this text!". If he clicks on - the link above this text, he gets the same page but with the GET - parameter "login=1". Now he can enter his login information in the - login form. If he successfully logs in, he can then see the text - "Everybody can see this text!" and the text "One can only see this - if he is logged in!". - </para> + </programlisting> + <para> + This is a pretty nice example for the optional login feature: The + last parameter <parameter>$optional</parameter> can be either true + or false. If it is false, the login form is not shown and the user + only sees the text "Everybody can see this text!". If he clicks on + the link above this text, he gets the same page but with the GET + parameter "login=1". Now he can enter his login information in the + login form. If he successfully logs in, he can then see the text + "Everybody can see this text!" and the text "One can only see this + if he is logged in!". + </para> + </example> <example> <title>Logout functionality</title> @@ -169,37 +173,32 @@ </programlisting> </example> - <para> - In the following passages we cover more detailed information about - the functions of PEAR::Auth. - </para> - <para> - This SQL statement creates a table usable under the default - database authentication scheme using MySQL: - </para> - <programlisting role="sql"> + <para> + In the following passages we cover more detailed information about + the functions of <classname>PEAR::Auth</classname>. + </para> + <para> + This SQL statement creates a table usable under the default + database authentication scheme using MySQL: + </para> + <programlisting role="sql"> <![CDATA[ CREATE TABLE auth ( - username VARCHAR(50) default '' NOT NULL, - password VARCHAR(32) default '' NOT NULL, - PRIMARY KEY (username), - KEY (password) + username VARCHAR(50) default '' NOT NULL, + password VARCHAR(32) default '' NOT NULL, + PRIMARY KEY (username), + KEY (password) ); - ]]> - </programlisting> - <para> - These are the table and field names necessary for working - authentication. The password column must be at least 32 characters - long because we store passwords encrypted using md5() and that is - the length of the values returned by md5(). - </para> - <para> - This next feature is useful for sites which provide some services - to all users that visit the sites and some services only to users - that are logged in, such as portals. - </para> - </refsect1> - </refentry> + ]]> + </programlisting> + <para> + These are the table and field names necessary for working + authentication. The password column must be at least 32 characters + long because we store passwords encrypted using md5() and that is + the length of the values returned by md5(). + </para> + </refsect1> +</refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml
Index: peardoc/en/package/authentication/auth/intro.xml diff -u peardoc/en/package/authentication/auth/intro.xml:1.4 peardoc/en/package/authentication/auth/intro.xml:1.5 --- peardoc/en/package/authentication/auth/intro.xml:1.4 Sat Mar 29 09:11:18 2003 +++ peardoc/en/package/authentication/auth/intro.xml Sat Mar 29 09:22:29 2003 @@ -1,23 +1,22 @@ -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="package.authentication.auth.intro"> - <refnamediv> - <refname>Introduction</refname> - <refpurpose>A usage example</refpurpose> - </refnamediv> - <refsect1 id="packages.authentication.auth.intro.example"> - <title>Auth tutorial</title> - <simpara> - Our goal during this "mini tutorial" is to set up a system that - secures your site with an easy to use authentication mechanism. - </simpara> - <para> - At the top of the site to secured, place the - following code snippet: - </para> - <example> - <title>Typical usage example for <classname>PEAR::Auth</classname></title> - <programlisting role="php"> - <![CDATA[ + <refnamediv> + <refname>Introduction</refname> + <refpurpose>A usage example</refpurpose> + </refnamediv> + <refsect1 id="packages.authentication.auth.intro.example"> + <title>Auth tutorial</title> + <simpara> + Our goal during this "mini tutorial" is to set up a system that + secures your site with an easy to use authentication mechanism. + </simpara> + <para> + At the top of the site to secured, place the following code snippet: + </para> + <example> + <title>Typical usage example for <classname>PEAR::Auth</classname></title> + <programlisting role="php"> + <![CDATA[ require_once "Auth/Auth.php"; function loginFunction() @@ -34,7 +33,6 @@ } $dsn = "mysql://user:password@localhost/database"; - $a = new Auth("DB", $dsn, "loginFunction"); $a->start(); @@ -44,30 +42,33 @@ * The output of your site goes here. */ } - ]]> - </programlisting> - </example> + ]]> + </programlisting> <para> This few lines of code instantiate the authentication system. </para> <para> The first line in the above script includes the file from your PEAR directory. It contains all the necessary code to run - PEAR::Auth. Next, we define a function to display the login form - which the visitor of your page has to use to enter his login - data. You can change all the HTML formating in this function. - </para> - <warning> - <simpara> - You can change all the HTML formatting in the function, but you - cannot change the names of the input boxes in the form. They have - to be "username" and "password". - </simpara> - </warning> + <classname>PEAR::Auth</classname>. Next, we define a function + to display the login form which the visitor of your page has to + use to enter his login data. You can change all the <acronym>HTML</acronym> + formatting in this function. + </para> + <para> + <warning> + <simpara> + You can change all the HTML formatting in the function, but you + cannot change the names of the input boxes in the form. They have + to be <literal>username</literal> and <literal>password</literal>. + </simpara> + </warning> + </para> <para> Since we want to use a database to verify the login data, we now - create the variable $dsn, it contains a valid DSN string that will - be used to connect to the database via PEAR::DB. For the default + create the variable <varname>$dsn</varname>, it contains a valid + DSN string that will be used to connect to the database via + <link linkend="package.database.db">PEAR::DB</link>. For the default database table schema or to use a different storage container, please see below for more information. </para> @@ -82,50 +83,52 @@ </para> <para> Now our authentication object is initialized and we need to check - if the user is logged in. This is done via the function + if the user is logged in. This is done via the method <function>getAuth</function>. If it returns true, we can pass the content of our page to the user. </para> - <warning> - <para> - For now one cannot use - <programlisting role="php"> - <![CDATA[ -$auth = new Auth(...); - ]]> - </programlisting> - with register_globals=on, because $auth is also the name of - the session variable, that is used by PEAR::Auth. - </para> - </warning> - <para> - <example> - <title>Using optional authentication</title> - <programlisting role="php"> - <![CDATA[ + <para> + <warning> + <para> + For now one cannot use + <programlisting role="php"> + <![CDATA[ + $auth = new Auth(...); + ]]> + </programlisting> + with <literal>register_globals=on</literal>, because + <varname>$auth</varname> is also the name of the session variable, + that is internally used by <classname>PEAR::Auth</classname>. + </para> + </warning> + </para> + </example> + <example> + <title>Using optional authentication</title> + <programlisting role="php"> + <![CDATA[ require_once "Auth/Auth.php"; function loginFunction() { - /** - * Change the HTML output so that it fits to your - * application. - */ - echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?login=1\">"; - echo "<input type=\"text\" name=\"username\">"; - echo "<input type=\"password\" name=\"password\">"; - echo "<input type=\"submit\">"; - echo "</form>"; + /** + * Change the HTML output so that it fits to your + * application. + */ + echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?login=1\">"; + echo "<input type=\"text\" name=\"username\">"; + echo "<input type=\"password\" name=\"password\">"; + echo "<input type=\"submit\">"; + echo "</form>"; } if ($_GET['login'] == 1) { - $optional = true; + $optional = true; } else { - $optional = false; + $optional = false; } $dsn = "mysql://user:password@localhost/database"; - $a = new Auth("DB", $dsn, "loginFunction", $optional); $a->start(); @@ -133,25 +136,26 @@ echo "Everybody can see this text!<br />"; if (!isset($_GET['login'])) { - echo "<a href=\"test.php?login=1\">Click here to log in</a>\n"; + echo "<a href=\"test.php?login=1\">Click here to log in</a>\n"; } if ($a->getAuth()) { - echo "One can only see this if he is logged in!"; + echo "One can only see this if he is logged in!"; } ]]> - </programlisting> - </example> - This is a pretty nice example for the optional login feature: The - last parameter <parameter>$optional</parameter> can be either true - or false. If it is false, the login form is not shown and the user - only sees the text "Everybody can see this text!". If he clicks on - the link above this text, he gets the same page but with the GET - parameter "login=1". Now he can enter his login information in the - login form. If he successfully logs in, he can then see the text - "Everybody can see this text!" and the text "One can only see this - if he is logged in!". - </para> + </programlisting> + <para> + This is a pretty nice example for the optional login feature: The + last parameter <parameter>$optional</parameter> can be either true + or false. If it is false, the login form is not shown and the user + only sees the text "Everybody can see this text!". If he clicks on + the link above this text, he gets the same page but with the GET + parameter "login=1". Now he can enter his login information in the + login form. If he successfully logs in, he can then see the text + "Everybody can see this text!" and the text "One can only see this + if he is logged in!". + </para> + </example> <example> <title>Logout functionality</title> @@ -169,37 +173,32 @@ </programlisting> </example> - <para> - In the following passages we cover more detailed information about - the functions of PEAR::Auth. - </para> - <para> - This SQL statement creates a table usable under the default - database authentication scheme using MySQL: - </para> - <programlisting role="sql"> + <para> + In the following passages we cover more detailed information about + the functions of <classname>PEAR::Auth</classname>. + </para> + <para> + This SQL statement creates a table usable under the default + database authentication scheme using MySQL: + </para> + <programlisting role="sql"> <![CDATA[ CREATE TABLE auth ( - username VARCHAR(50) default '' NOT NULL, - password VARCHAR(32) default '' NOT NULL, - PRIMARY KEY (username), - KEY (password) + username VARCHAR(50) default '' NOT NULL, + password VARCHAR(32) default '' NOT NULL, + PRIMARY KEY (username), + KEY (password) ); - ]]> - </programlisting> - <para> - These are the table and field names necessary for working - authentication. The password column must be at least 32 characters - long because we store passwords encrypted using md5() and that is - the length of the values returned by md5(). - </para> - <para> - This next feature is useful for sites which provide some services - to all users that visit the sites and some services only to users - that are logged in, such as portals. - </para> - </refsect1> - </refentry> + ]]> + </programlisting> + <para> + These are the table and field names necessary for working + authentication. The password column must be at least 32 characters + long because we store passwords encrypted using md5() and that is + the length of the values returned by md5(). + </para> + </refsect1> +</refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml