voxanBoxer Posted January 6, 2007 Share Posted January 6, 2007 I am having a problem with fopen. I am opening a url and it works great BUT when I send login credentials, it doesn't work.I thought it might be a redirect problem but I ran a test and opened a page that redirects 3 times in a row and it returned the 3rd page. So it isn't the redirect. The common problem is when I send login credentials it doesn't work. Sometimes I get a page that says you must login first or sometimes it just returns blank.Also, http vs. https doesn't change anything.This is my code:<?php $url = "https://www.myurl.com?id=Myname&password=mypassword"; $fp = fopen( $url, 'r' ); $content = ""; while( !feof( $fp ) ) { $buffer = trim( fgets( $fp, 4096 ) ); $content .= $buffer; } echo $content; ?> Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/ Share on other sites More sharing options...
JasonLewis Posted January 6, 2007 Share Posted January 6, 2007 well thats because it is trying to include that URL so it will look for a file by that name.i am surprised your not getting an fopen error actually. Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154014 Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 the manual says you can open a remote file with fopen: http://us2.php.net/fopenwithout seeing the actual url you're trying to open, I'm sure no one can give you any definate help. How does the login work? Is it one of those browser popup things that asks for a password, or is it an online form? If it's a form, is it using the $_GET or $_POST method. Also, does the site send you a header redirect when you login? Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154031 Share on other sites More sharing options...
voxanBoxer Posted January 6, 2007 Author Share Posted January 6, 2007 It is an online form. I am trying on multiple sites. It sends the credentials, verifys them and then redirects them.They are using "Post" Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154225 Share on other sites More sharing options...
voxanBoxer Posted January 6, 2007 Author Share Posted January 6, 2007 Use this:http://64.40.144.139/squirrelmail/src/login.phpid: phptest@cannellent.compassword: phptestThis would be the url:http://64.40.144.139/squirrelmail/src/redirect.php?login_username=phptest@cannellnet.com&secretkey=phptest&js_autodetect_results=SMPREF_JS_OFF&just_logged_in=1 Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154232 Share on other sites More sharing options...
voxanBoxer Posted January 6, 2007 Author Share Posted January 6, 2007 Clicking the link logs in just fine but pass the link in my code and it doesn't return the page. Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154234 Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 curl was created for just such a task. You can get, post, or head -- you can even tell it to upload or download binary files, follow redirects, and I think it can even log into protected directories. It will take some effort, but this is a good place to start:http://us3.php.net/curlexec Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154461 Share on other sites More sharing options...
voxanBoxer Posted January 6, 2007 Author Share Posted January 6, 2007 thanks, I'll look into it and post if I have any more problems. Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-154485 Share on other sites More sharing options...
voxanBoxer Posted January 8, 2007 Author Share Posted January 8, 2007 So far, no luck. One test returned the same page telling me to login first.My test URL returns a "1":<?php $url = "http://64.40.144.139/squirrelmail/src/redirect.php?login_username=phptest@cannellnet.com&secretkey=phptest&js_autodetect_results=SMPREF_JS_OFF&just_logged_in=1"; $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,$url); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)) { print "Sorry, there was an error loading the page"; }else{ print $buffer; } curl_close()?> Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-156181 Share on other sites More sharing options...
michaellunsford Posted January 8, 2007 Share Posted January 8, 2007 you might try setting CURLOPT_POST and CURLOPT_POSTFIELDS instead of feeding the whole thing using GET. Quote Link to comment https://forums.phpfreaks.com/topic/33046-fopen-with-login-credentials/#findComment-156192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.