FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Acces another site which needs login automatically via php..





Ecthelion
Hi,

To try and make myself clear I'll give an example of what I would like.

So let's say I have a site, called "getnews.net". Also there is another site called "thenews.net" on which I have an account, with username "Ecthelion" and password "pass".
Now on this site "thenews.net" there is a news feed that I would like to display too. Problem is: it is only accesible to logged in users.

So what I want to know is:
How can I, using php, "automatically start a session (login) on "thenews.net", take the info and (logout) on "thenews.net".

The idea is thus that, when someone accesses getnews.net/index.php, the page index.php automatically goes to thenews.net logs in gets the info logs out etc WITHOUT that the person who visits my page needing to enter anything etc...

It's quite complicated to explain, but I hope the idea gets through. ...?

Thanks!
rvec
I made this to login to frihost and get the pm-inbox page (with some help from manofgames):
Code:
$post_data = array('username'=>'rvec', 'password'=>'pass', 'login'=>'Log in', 'redirect'=>'');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.frihost.com/account/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$index = curl_exec($ch);
curl_close($ch);
preg_match('/sid=([a-z0-9]{32})/',$index, $matches);
$sid = $matches[1];


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.frihost.com/forums/privmsg.php?folder=inbox&sid='. $sid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$pm = curl_exec($ch);
curl_close($ch);
Ecthelion
Hey,

Thanks for this extremely quick reply Smile

But I'm afraid I have a problem: they seem to be using javascript here and there Sad

To fill in this line
Quote:
$post_data = array('username'=>'rvec', 'password'=>'pass', 'login'=>'Log in', 'redirect'=>'');

I can fill most in, except for the last value.
I see that (I compared with the login page of frihost) you do 'name' => 'value'
Problem is, this is the line of the submit button (the rest is simply a form)
Quote:
<input type='submit' value='Login!' class='savebutton' onClick="this.disabled=true;makeMD5('pw');this.form.submit();">


So now I wonder. Does that mean that I have to submit a MD5 of my password?
Or can I simply ignore this and do
'login' => 'Login!'
?

EDIT: this is the MD5 function of the site:
Quote:
function makeMD5(f)
{
v = document.getElementById(f).value;
if (v != "" && v.length != 33 && v.charAt(0) != '_')
document.getElementById(f).value = '_' + MD5(v);
}


Since there doesn't seem to be any return value, can I ignore it?
MrBlueSky
Quote:

Since there doesn't seem to be any return value, can I ignore it?


Probably not, because it changes the value of a field with the id 'pw':

Quote:
function makeMD5(f)
{
v = document.getElementById(f).value;
if (v != "" && v.length != 33 && v.charAt(0) != '_')
document.getElementById(f).value = '_' + MD5(v);
}

<input type='submit' value='Login!' class='savebutton' onClick="this.disabled=true;makeMD5('pw');this.form.submit();">


What does the MD5() function do? Does it just calculates the md5 hash?
Ecthelion
Hi,

I've been doing some lookup and I found out that "document.getElementById(f).value; " or anything with "document.getElementById" is only for css purposes...
I don't give a damn about how it is displayed when I let my script do it, so I dare think that I can ignore it Smile

Well I'll see if it works without adapting to it anyway :/

EDIT: Aww...
Quote:
Sorry, no valid session


Your session may have timed out, or your browser does not accept cookies.
Cookies are necessary for authentication so you have to enable them in your browser's options.


That curl trick doesn't take cookies, does it?
It only remembers the UID...?
Or does it work with cookies?
rvec
take a look at this site: http://www.phpdig.net/ref/rn11re189.html
that should help you on setting cookies.
Ecthelion
Thanks!

I also readed the php.net manual on the curl functions.

But something that would probably help me a lot in solving this problem is a way to find those cookies that curls seems to store, and look at their content.
That would probably help me a lot, but I don't seem to find a curl function that you can use to actually save the cookies (nor a place where I could look to find those "saved" cookies)
I know how they look and what content they should have (except for the session-specific info)
Maybe I could find out what goes wrong then Smile
rvec
The cookies should be in the header (I think) so if you want cookies save the headers.
Related topics
HTTP AUTH with PHP and mySQL
Hide Part of Your Web Site from Yahoo!
The Definative Web Hosting Guide
Hoe mijn site volledig zichtbaar maken via google
some people can't acces my site
PHP?
Sending email via PHP
My site.....
phpBB sessions continue around whole site.
Another dumb question <.<
Post value from one site to another site.
Easy login in script
manda um site que tenha bons scripts php para cadastro
Can ASP be used with XAMPP?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.