Jump to content


Logging into a remote site (htaccess) using fsockopen

  • Please log in to reply
3 replies to this topic

#1 mcguile25

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 October 2006 - 07:50 PM

Hi, I am trying to be able to write a PHP script that will connect to an external site that has a restricted directory (htaccess) that I want to redirect the user to.  Obviously I have to send over the username and password in the headers.  I have everything working, but what's happening is all I am getting back is the HTML for the index file in the folder in question from the server...but I want to literally redirect the user to that external site after I've been authenticated...how is that possible?  Here is my code:

	$fp = fsockopen( $host, 80, $errno, $errstr );

	$auth = base64_encode( "$username:$password" );

	$out = "GET $path HTTP/1.0\r\n";
	$out .= "Host: $host\r\n";
	$out .= "Connection: Keep-Alive\r\n";
	$out .= "Authorization: Basic $auth\r\n";
	$out .= "\r\n";

	fputs( $fp, $out );
	$response = "";
	while ( !feof( $fp ) )
		$response .= fgets( $fp, 4096 );

	fclose( $fp );

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 09 October 2006 - 09:45 PM

You'll want to look at using curl.

#3 printf

  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 09 October 2006 - 09:47 PM

You can't do that, a remote request, is remote request, it has nothing to do with a client request. In other words you can redirect a client and have them use your remote request credentials. The only way is to give them the username and password, if you don't want to do that, then your out of luck!


#4 mcguile25

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 October 2006 - 10:15 PM

Yes, it seems curl can only give you the contents of the requested page, but I want the user to be able to follow links from that page.  I don't think curl was made for that:

Is the only way to do this is by using the http://username:password@url scheme?

By doing this, all of the links show the username and password in the status bar as I am highlighting the links.

Is there any other way??

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users