Login via php code on an external page

Hi there!
I have to do a php script that daily surf a webpage (I do it with
crontab) and collect some data.
The proble is that to access that webpage I have to do a login. I have
the login data, but do it via browser....ok, I'm not stupid, but do
that via php script...well I'm not able to do it.
The script is running on the server side, so it's useless to do the
login on my browser prior to run the script.
The page where I have to login has this code in it:

<form name="homesiteccontrol" method = "post" action="/sasa/index.jsp?
epi-content=LOGIN&epi-
process=home_process_login.jsp&type=url&form_url_name=http:/ /
www.xxxxxxxx.xxx/sasa/site/ffds/?epi_menuItemID=5558e3fd3775 e0c3beda0052c01041ca&target=top&source=sitecontrol"
target="_parent" style="margin-bottom:0px;">
<input type="hidden" name="realm" value="SQL">
<table width="148" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="login">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td colspan="2"><img src="/images/xxxxxxx/newhome/
login.gif" width="45" height="20" /></td>
</tr>

<tr>
<td colspan="2" class="login_box">Username
<input name="logon" type="text" class="login_form"
size="15" maxlength="50">
</td>
</tr>
<tr>
<td valign="bottom" class="login_box">Password
<input name="password" class="login_form"
type="password" size="15" maxlength="20" onKeyPress="return
submitenter(this,event)"/>
</td>
<td valign="bottom">

<input name="Invia" type="image" src="/images/
xxxxxxxxx/newhome/login_box_frecce.gif" width="26" height="17">
</td>
</tr>
<tr>
<td colspan="2">
<a href="http://www.xxxxxxxx.xxx/sasa/site/ffds/?
epi_menuItemID=a2dc1cab4db4465fb70c3072e02041ca&beanID=98976 176&viewID=richiestaPass&epi-
content=GENERIC" class="link_login_box">password dimenticata?</a>
<a href="http://www.xxxxxxxx.xxx/sasa/site/ffds/?
epi_menuItemID=61c946e879c833d632294560c01041ca"><img src="/images/
xxxxxxxxx/newhome/login_box_registrazione_it.gif" width="129"
height="19" border="0" /></a>
</td>

</tr>
</table>
</td>
<td width="7"><img src="/images/xxxxxxxxx/newhome/
login_box_dx.gif" width="7" height="128" /></td>
</tr>
</table>
</form>

How can I do it???
Thanks,
Andrea
Andrea [ Do, 01 März 2007 14:24 ] [ ID #1644112 ]

Re: Login via php code on an external page

Andrea wrote:
> I have to do a php script that daily surf a webpage (I do it with
> crontab) and collect some data.
> The proble is that to access that webpage I have to do a login. I have
> the login data, but do it via browser....ok, I'm not stupid, but do
> that via php script...well I'm not able to do it.
> The script is running on the server side, so it's useless to do the
> login on my browser prior to run the script.
> The page where I have to login has this code in it:

It's a lot easier if you use wget, it supports sessions and cookies, you first
use wget to get the page to your local machine and then process the file in php.


--

//Aho
Shion [ Do, 01 März 2007 14:34 ] [ ID #1644113 ]

Re: Login via php code on an external page

> It's a lot easier if you use wget, it supports sessions and cookies, you first
> use wget to get the page to your local machine and then process the file in php.

Well...but how to login via wget???
>
> //Aho

Andrea
Andrea [ Do, 01 März 2007 15:49 ] [ ID #1644116 ]

Re: Login via php code on an external page

Andrea wrote:
>> It's a lot easier if you use wget, it supports sessions and cookies, you first
>> use wget to get the page to your local machine and then process the file in php.
>
> Well...but how to login via wget???

I guess it's a normal form, password and login that is sent and that is
usually done with a POST, so you will need to use the --post-data option, you
may want to lie that you are using a browser, in that case you use
--user-agent. For the session cookie you need to use the --save-cookies option

You use the wget once for the login and then once for fetching the page you
wanted.

For further information, I suggest you take a look at the wget man page:
man wget

Simple example from the man page:

get --save-cookies cookies.txt --post-data 'user=foo&password=bar'
http://server.com/auth.php

wget --load-cookies cookies.txt -p http://server.com/interesting/article.php


--

//Aho
Shion [ Do, 01 März 2007 17:06 ] [ ID #1644121 ]

Re: Login via php code on an external page

> I guess it's a normal form, password and login that is sent and that is
> usually done with a POST, so you will need to use the --post-data option, you
> may want to lie that you are using a browser, in that case you use
> --user-agent. For the session cookie you need to use the --save-cookies option

Ok, thanks...but first of all I have to find the page I have to call
and pass the post data...
have a look at the form code...can you find it???
Andrea [ Do, 01 März 2007 17:25 ] [ ID #1644122 ]

Re: Login via php code on an external page

Andrea wrote:
>> I guess it's a normal form, password and login that is sent and that is
>> usually done with a POST, so you will need to use the --post-data option, you
>> may want to lie that you are using a browser, in that case you use
>> --user-agent. For the session cookie you need to use the --save-cookies option
>
> Ok, thanks...but first of all I have to find the page I have to call
> and pass the post data...
> have a look at the form code...can you find it???

You go to the page where you usually do login at with your own browser, check
the form-tags action argument, thats the page that will be called when a form
is sent, when it don't state any http:// it means it's on the same machine
(address) as the form page is located, I assume this is the
http://www.xxxxxxxx.xxx/, so the page to post to is
http://www.xxxxxxxx.xxx/sasa/index.jsp


--

//Aho
Shion [ Do, 01 März 2007 18:08 ] [ ID #1644127 ]
PHP » alt.php » Login via php code on an external page

Vorheriges Thema: Form input data
Nächstes Thema: query string passing woes........ help... please....