PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
PEAR Auth : Use form inside HTML and Keep authentification

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Authentication
View previous topic :: View next topic  
Author Message
chben



Joined: 24 Jan 2007
Posts: 1

PostPosted: Wed Jan 24, 2007 2:32 pm    Post subject: PEAR Auth : Use form inside HTML and Keep authentification Reply with quote

Hi,
I'm trying to use PEAR::Auth in my e-commerce application, but there are several things I cannot make working and do not understand.

In my example, I've got 2 pages : identification.php & shipping.php.

On identification.php I use the start() method to display and use the default login form :

Code:

<?php
$auth = new Auth("DB", $options_auth, null, false);   
$auth->start();
?>
<html>
<head>...</head>
<body>
...
<?php
   if ($auth->getAuth()) {
      echo "<p>You're already logged in.</p>";
   }
   else {
      // Display the login form
      $auth->setShowLogin(true);
      $auth->start();
   }
?>
...
</html>


Already here, I'm not sure to use Auth as I should. In effect, If I don't use the first start() after pear::Auth instanciation, the second $auth->start() used to display form causes 2 warning :
Code:

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in D:\Ben\Dev\iscommerce\admin\conf\Auth\Auth.php on line 741

Warning: Cannot modify header information - headers already sent by (output started at D:\Ben\Dev\iscommerce\commande\identification.php:99) in D:\Ben\Dev\iscommerce\admin\conf\Auth\Auth.php on line 765


Event I can perfectly understand that in order to create a session, Auth needs no headers to be sent...I'm surprised to notice that no example in the documentation and on the web uses start() method inside an html file.


Well, as it is however working fine, let's tell you about my second problem : keep the login status on the second page (shipping.php).


In my example, if I replace the "logged in" status display by a redirection to shipping.php like this :


Code:
<?php
$auth = new Auth("DB", $options_auth, null, false);   
$auth->start();
?>
<html>
<head>...</head>
<body>
...
<?php
   if ($auth->getAuth()) {
      //echo "<p>You're already logged in.</p>";
      // Redirect to the shipping page
      header('location: shipping.php);
   }
   else {
      // Display the login form
      $auth->setShowLogin(true);
      $auth->start();
   }
?>
...
</html>



My shipping page code is as follows :
Code:

$auth = new Auth("DB", $options_auth, null, false);
$auth->start();

if ($auth->getAuth()) {
   echo "You are logged in";
}
else {
   echo "You are not logged in";
}


The problem is : my shipping page always show me "You are not logged in", whereas the login form works on the previous page. The login status seems not to be saved in session and forgot from one page to another.



Did anyone managed to have the PEAR::Auth library working ? If so, could this person post her code on tis forum ? That would be very helpful I think because Except the few documentation examples, I cannot find anyhting else on the web about a working Auth script...


Thanx for all to let your ideas about my problem, even if you don't have the entire solution, this could be interesting !





------------------

Bonjour,
Je tente comme d'autres d'utiliser PEAR::Auth, mais je reste perplexe sur plusieurs points.

Dans mon exemple, j'ai 2 pages : indentification.php et livraison.php

Sur identification.php, j'utilise la méthode start() pour afficher et utiliser le formulaire de login par défaut :

Code:

<?php
$auth = new Auth("DB", $options_auth, null, false);   
$auth->start();
?>
<html>
<head>...</head>
<body>
...
<?php
   if ($auth->getAuth()) {
      echo "<p>You're already logged in.</p>";
   }
   else {
      // Display the login form
      $auth->setShowLogin(true);
      $auth->start();
   }
?>
...
</html>


Mais déjà là, je ne suis pas sûr d'utiliser correctement la bibliothèque. En effet, si je n'utilise pas le premier start() après l'instanciation $auth= new Auth(...), celui qui se trouve au milieu de ma page provoque 2 warnings :
Code:

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in D:\Ben\Dev\iscommerce\admin\conf\Auth\Auth.php on line 741

Warning: Cannot modify header information - headers already sent by (output started at D:\Ben\Dev\iscommerce\commande\identification.php:99) in D:\Ben\Dev\iscommerce\admin\conf\Auth\Auth.php on line 765


Même si je comprend parfaitement le "headers already sent" en raison du fait que j'ai déjà fait affiché des caractères sur ma page, je suis surpris de ne voir aucun exemple de code qui utilise le start de la même façon que moi, intégré dans du HTML...

Mais puisque ça fonctionne pour le moment comme ça, je vais plutôt passer au second problème : garder l'identification active sur d'autres pages, sur ma page livraison.php par exemple

Dans mon exemple, si je remplace l'affichage du message m'alertant que je suis logué par une redirection vers livraison.php comme ceci :

Code:

<?php
$auth = new Auth("DB", $options_auth, null, false);   
$auth->start();
?>
<html>
<head>...</head>
<body>
...
<?php
   if ($auth->getAuth()) {
      //echo "<p>You're already logged in.</p>";
      // Redirection vers la page de livraison
      header('location: livraison.php');
   }
   else {
      // Display the login form
      $auth->setShowLogin(true);
      $auth->start();
   }
?>
...
</html>


Avec un code sur ma page de livraison comme suit :
Code:

$auth = new Auth("DB", $options_auth, null, false);
$auth->start();

if ($auth->getAuth()) {
   echo "You are logged in";
}
else {
   echo "You are not logged in";
}


Le problème est le suivant : La page de livraison m'affiche tout le temps "You are not logged in", alors que le login fonctionne correctement sur la première page. Le statut de la connexion ne semble pas être sauvegardé en session et donc oublié d'une page à l'autre.

J'ai bien vu sur ce forum que [URL="http://www.developpez.net/forums/showthread.php?s=4fac782f6ccd2f3298c8da241775febd&t=222333&highlight=pear+auth"]quelqu'un d'autre avait eu ce problème[/URL], mais je trouve la solution avancée assez curieuse pour une bibliothèque censée nous faciliter la tâche...

Svp, est-ce quelqu'un pourrait publier dans les tutoriaux, How-to, etc... un exemple de code concrêt qui fonctionne ? C'est malheureux, mais je ne trouve rien d'autre que les quelques exemples de la documentation qui ne nous aident pas trop dans le cadre d'un vrai projet...

Merci de venir poster vos remarques, même si vous n'avez pas la solution miracle, peut-être que ça m'avancera quand même !
Back to top
View user's profile Send private message
Codeman



Joined: 18 Apr 2007
Posts: 2

PostPosted: Wed Apr 18, 2007 9:02 am    Post subject: News on this topic Reply with quote

Hi,

sorry, I think I cannot help... but I have the same problem. This problem exists since i have updated to apache2 and php5. I don't know why - it works for me fine the time before... very strange.

Regards, Holger
Back to top
View user's profile Send private message
Codeman



Joined: 18 Apr 2007
Posts: 2

PostPosted: Wed Apr 18, 2007 10:09 am    Post subject: Got it! Problem solved... Reply with quote

Hah!

I just got it to work.

You need to enable
Code:

output_buffering = On


Perhaps you have to ebalbe cookies in the session management.

regards, Holger
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Authentication All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software