PHP Classes

Could not login

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  Could not login  >  (Un) Subscribe thread alerts  
Subject:Could not login
Summary:Could post values at login
Messages:4
Author:sunugur
Date:2007-05-03 09:27:56
Update:2007-05-05 07:54:01
 

  1. Could not login   Reply   Report abuse  
Picture of sunugur sunugur - 2007-05-03 09:27:56
Hi,

I am trying to get to the url http://www.yonja.com/myworld.jsp after logging in at http://www.yonja.com/Login.jsp page. I could not figure out the probelm but after posting the login values, I am getting the login page again although follow redirect parameter is set. I would appreciate your feed

  2. Re: Could not login   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-03 19:27:03 - In reply to message 1 from sunugur
You need to show the script you are using the class to access both pages so I can figure what is the problem.

  3. Re: Could not login   Reply   Report abuse  
Picture of sunugur sunugur - 2007-05-04 06:13:39 - In reply to message 2 from Manuel Lemos
I have tried to modify the yahoo script that you had provided.

Below is the class script
======================================================
<?php
/*
* yahoo_user.php
*
* @(#) $Header: /home/mlemos/cvsroot/http/yahoo_user.php,v 1.4 2007/02/07 21:28:27 mlemos Exp $
*
*/

class yahoo_user_class
{
var $error = '';
var $user = '';
var $password = '';
var $logged_user = '';
var $http;
var $response_buffer_length = 1000;
var $user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';


Function SetupHTTP()
{
if(!IsSet($this->http))
{
$this->http = new http_class;
$this->http->follow_redirect = 1;
$this->http->debug = 0;
$this->http->debug_response_body = 0;
$this->http->html_debug = 1;
$this->http->user_agent = $this->user_agent;
}
}

Function OpenRequest($arguments, &$headers)
{
if(strlen($this->error=$this->http->Open($arguments)))
return(0);
if(strlen($this->error=$this->http->SendRequest($arguments))
|| strlen($this->error=$this->http->ReadReplyHeaders($headers)))
{
$this->http->Close();
return(0);
}
if($this->http->response_status!=200)
{
$this->error = 'the HTTP request returned the status '.$this->http->response_status;
$this->http->Close();
return(0);
}
return(1);
}

Function GetRequestResponse(&$response)
{
for($response = ''; ; )
{
if(strlen($this->error=$this->http->ReadReplyBody($body, $this->response_buffer_length)))
{
$this->http->Close();
return(0);
}
if(strlen($body)==0)
break;
$response .= $body;
}
$this->http->Close();
return(1);
}

Function GetRequest($arguments, &$response)
{
if(!$this->OpenRequest($arguments, $headers))
return(0);
return($this->GetRequestResponse($response));
}

Function Login(&$parameters)
{
if(strlen($this->user)
&& !strcmp($this->logged_user, $this->user))
return(1);
$this->logged_user = '';
$this->SetupHTTP();
$url='http://www.yonja.com/Login.jsp';
$this->http->GetRequestArguments($url, $arguments);
$arguments['RequestMethod']='GET';
if(!$this->GetRequest($arguments, $response))
return(0);
$redirect = (IsSet($parameters['GetPage']) ? $parameters['GetPage'] : 'http://www.yonja.com/myworld.jsp');
$url='http://www.yonja.com/Login.jsp';
$this->http->GetRequestArguments($url, $arguments);
$arguments['RequestMethod']='POST';
$arguments['PostValues']=array(
'isSubmit'=>'true',
'nickname'=>$this->user,
'password'=>$this->password
);
$arguments['Headers']['Referer']= 'http://www.yonja.com/Login.jsp';
if(!$this->GetRequest($arguments, $response))
return(0);
/*
if(GetType(strpos($response, '<meta http-equiv="Refresh" content="0; url='.$redirect.'">'))!='integer')
{
$this->error = 'the login page does not redirect to the expected page';
return(0);
}
*/
$this->http->GetRequestArguments($redirect, $arguments);
$arguments['RequestMethod']='GET';
$arguments['Headers']['Referer']= $url;
if(!$this->GetRequest($arguments, $response))
return(0);
if(IsSet($parameters['GetPage']))
{
$parameters['Response']=$response;
$parameters['GetPage']=$this->http->protocol.'://'.$this->http->host_name.$this->http->request_uri;
}
$this->logged_user = $this->user;
$this->page = $this->http->body;
return(1);
}

Function SendMessage(&$parameters)
{
$url='http://www.yonja.com/Messages.jsp?s=0&kt=605619421';

$login_parameters = array('GetPage'=>$url);
if(!$this->Login($login_parameters))
return(0);
if(strlen($this->logged_user)==0)
return(1);
$url=$login_parameters['GetPage'];
$this->http->GetRequestArguments($url, $arguments);
$arguments['Headers']['Referer']= $url;
if(!$this->GetRequest($arguments, $response))
return(0);

$arguments['PostValues']=array(
'subject'=>'test subject',
'message'=>'test message'
);

if(!$this->GetRequest($arguments, $response))
return(0);

return(1);

}
};

?>


This is th script used to access the page
==============================================================
<?php
/*
* yahoo_group_invite.php
*
* @(#) $Header: /home/mlemos/cvsroot/http/yahoo_group_invite.php,v 1.1 2006/04/07 21:44:23 mlemos Exp $
*
*/

require('http.php');
require('yonja_user.php');

$yahoo = new yahoo_user_class;
$yahoo->user = '[email protected]';
$yahoo->password = '123456';
$parameters = array();
$success = $yahoo->SendMessage($parameters);
?>
<html>
<head>
<title>Invite users to a Yahoo group</TITLE>
</head>
<body>
<h1 style="text-align: center">Invite users to a Yahoo group</h1>
<hr />
<?php
if($success)
{
if(strlen($yahoo->logged_user))
{
?>
<h2 style="text-align: center">The user '<?php echo $yahoo->logged_user; ?>' has logged in Yahoo successfully.</h2>
<?php

echo $yahoo->$page;
}
else
{
?>
<h2 style="text-align: center">The Yahoo user '<?php echo $yahoo->user; ?>' login attempt failed.</h2>
<?php
}
}
else
{
?>
<h2 style="text-align: center">Error: <?php echo $yahoo->error ?></h2>
<?php
}
?>
<hr />
</body>
</html>



Thanks very much in advance
Thanks

  4. Re: Could not login   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-05 07:54:01 - In reply to message 3 from sunugur
The problem is simple. The login form submission page and subsequent requests are under www2.yonja.com domain instead of www.yonja.com .