Quick search:

struggling to understand forwardRequest

pkellner
2005-08-20 22:29:40
 
Hi,

I'm trying to add a login page as is described in the online help.  I've added to my site class the code below.

I'm wanting to display what I have in ../classes/ClassObjectLoginPage.php but that is not happening.  How can I get this page to display?

Thanks,  -Peter

$loginSucceeded = true;
if ($loginSucceeded) {
   // process normally
}    
else {
    $requestData["pntType"] = "LoginPage";
}
parent::forwardRequest(&$requestData, $information=null);
henk
2005-08-21 12:57:38
 
Peter,

Maybe because your ClassObjectLoginPage.php starts with a capital C?

Greetings,

Henk Verhoeven.

pkellner
2005-08-22 06:02:34
 
Actually, I do have figure out how to get my LoginPage to display.  The thing I am really stuck on is how to make it act like something that does not have a database behind it.  That is, just the username and password fields.  I've been playing with the Dialog's but have not been able to figure it out.  

Could you give me a couple more hints?  Maybe a very simple example (or point me at an example) that would let a user type in something like a username and password, then I have some php code that acts on that.

Thanks,

-Peter

(sorry for the vague description.  I'll try and do better next time)
henk
2005-08-22 13:04:47
 
Peter,

For a while i thought that [url=http://www.phppeanuts.org/site/index.php?pntType=HcodeMethod&id=pnt.web.pages.PntPage::initForHandleRequest] initForHandleRequest[/url] inherited from PntPage would be calling [url=http://www.phppeanuts.org/site/index.php?pntType=HcodeMethod&id=pnt.web.PntRequestHandler::getRequestedObject]getRequestedObject[/url], but as you can see, it does not. So basically a subclass of PntPage should not try to get anything from the database. Does forwardRequest really forward to an ObjectLoginPage? If not, maybe you can try to do the forwarding like this:

if (!$loggedIn) {
  $handler = new LoginPage($this, $this->requestData);
  return $handler->handleRequest();
}

(Mind that i changed the class name to LoginPage - The prefixing is not applied, so i thought you would not need the 'Object' prefix any more).

To make the LoginPage work, take a look at the code of [url=http://www.phppeanuts.org/site/index.php?pntType=HcodeClass&id=pnt.web.pages.PntIndexPage]IndexPage[/url], all it does is include skinIndex.php. Maybe you can make you LoginPage only include skinLogin.php. If you hard-code a form there with <input type=text ..> for the username and password, and an hidden field named pntHandler and value=LoginAction, you should be able to process the login from a class named ObjectLoginAction.

Success,

Henk Verhoeven.
pkellner
2005-08-23 04:50:32
 
Don't quite have it yet.  I've got the LoginPage working with the skinLoginPage as you suggest, built a class and put it in my classes/generalfunctions ( class LoginPage extends PntPage {.. ) and added to classSite.php the code below.

My login page comes up, I have added a hidden field:
<input type=hidden value='LoginAction' name='pntHandler'>

But, I am not finding my ObjectLoginAction.  It seems that in classPntRequestHandler, the $classname variable is not set and therefore not forming the handler correctly.

Please tell me it is something simple.  I do not understand what $classname is and where it gets set.  I have searched and searched.

Thanks,  -Peter

// override
function forwardRequest(&$requestData, $information=null) {
//..dbinitstuff
$loginSucceeded = false; // this will be a global of some sort
if ($loginSucceeded) {
  $handler =& $this->getRequestHandler($requestData);
  if ($information)
    $handler->setInformation($information);
    $handler->handleRequest();
}    
else
{
  $handler = new LoginPage($this, $this->requestData);
  return $handler->handleRequest();
}
pkellner
2005-08-23 21:43:18
 
I think I am almost there.  (I can see you rolling your eyes in doubt).

For some reason, the session variable

$loginSucceeded = isSet($_SESSION['user']);

Will not stay set between pages.  It seems that when I process the submenu choice (printSubmenu), that the session variable disappears.  This makes it prompt me before going into every page.

I don't understand how a session variable can go away.  My understanding from the php docs is that it is persistent as long as you call session_start which you do in every pntpage.

Thanks again for all the help.

-Peter
pkellner
2005-08-23 22:22:45
 
One problem remains since I did solve one of the problems myself thanks to a guy who posted on the internet about sessions restarting on every page.  (see below if interested).

Now, it seems that for every folder (like example1,example2, etc.) it reprompts me for a password.  I assume that is because the cookie is formed in that directory.  When I try to move my index.php to the root of my app, all the references to includes are wrong.

Almost done with this one and thanks again for the help.

-Peter




User Contributed Notes
Session Handling Functions
fasteddie at byu dot edu not_this_part
16-Aug-2005 11:43
I hope this helps someone:
---PHP SESSIONS NOT WORKING---
My sessions wouldnt ever load from disk. The sessions would start just fine, and a session file would be created and written to disk. (BTW, I'm on a win XP box, Apache 2.0.54, PHP version 5.0.4.) However, next time I loaded the page, the old session would not be used. Instead, a NEW session was created. For me, this happened no matter what computer I was using, whether it was the server (localhost) or a client (remote). A new session was created EVERY TIME I loaded the page.. it was annoying. After a few hours of googling, I gave up and decided to mess around in the php.ini file. I changed this line:
session.cookie_path = /
to this:
session.cookie_path =

Now, php sessions are loaded properly.

I havent tried many things but I think maybe it is because windows needs backslashes (\) instead of forward slashes (/), and if you just leave it blank, it turns out ok.
henk
2005-08-24 01:53:57
 
Peter,

Sorry, i do not know about these session problems, with me it has allways worked. My php5/php.ini holds
session.cookie_path = /
The problem of loosing your session when you move outside the folder when using session.cookie_path =
seems logical. This does not seem a good idea, there must be an other way.

However, if you really want to run your script in the root folder, you have to change some include directives in classSite.php and adapt the includeClass and tryIncludeClass function in pntPhp5Functions.php. But you will loose the ability to have several applications/modules with their own submenu and their own special skins and classes.


Greetings,

Henk Verhoeven.
pkellner
2005-08-24 01:57:42
 
I will stick with the recommended way and not have shared passwords between different sites.   -thanks
Add a Reply
Loading form, please wait
The website will not send you an e-mail when a reply is added to this topic

Back to Topics List