<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Georgi Mitev &#124; Learn Scripts Tutorials &#124; PHP Cron Mysql Flash &#187; fgets</title>
	<atom:link href="http://georgi-mitev.com/tag/fgets/feed/" rel="self" type="application/rss+xml" />
	<link>http://georgi-mitev.com</link>
	<description>Georgi Mitev&#039;s blog for scripts tutorials and something else</description>
	<lastBuildDate>Thu, 29 Apr 2010 09:00:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use local script to login to remote web site (modify Header)</title>
		<link>http://georgi-mitev.com/2009/03/20/login-locally-to-remote-host/</link>
		<comments>http://georgi-mitev.com/2009/03/20/login-locally-to-remote-host/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 07:41:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[fgets]]></category>
		<category><![CDATA[fputs]]></category>
		<category><![CDATA[fsockopen]]></category>
		<category><![CDATA[Login remotely]]></category>
		<category><![CDATA[PHP modify POST]]></category>

		<guid isPermaLink="false">http://georgi-mitev.com/?p=153</guid>
		<description><![CDATA[I don&#8217;t know if this will be interesting for you, but it was very interesting for me when i found that it is very easy to modify header information and send POST/GET variables through header using php. Anyway with CURL you are able to do much more that just modify the header information etc., but [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know if this will be interesting for you, but it was very interesting for me when i found that it is very easy to modify header information and send POST/GET variables through header using php. Anyway with CURL you are able to do much more that just modify the header information etc., but we wont have that time-frame <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I will give you simple example where i login through script on localhost on some site &#8211; in this example: &#8220;gametrailers.com&#8221; &#8211; without actually enter any username and password <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , i think this will be the easiest way to understand it.</p>
<p>so here is the example:<br />
<span id="more-153"></span></p>
<p>on your localhost create php file &#8211; &#8220;loadUrl.php&#8221;</p>
<p>&lt;base href=&#8221;http://www.gametrailers.com/&#8221; /&gt;<br />
&lt;!&#8211; we use base href to be able to load the css and the js paths correctly on the site &#8211;&gt;</p>
<p>$port = 80;<br />
//usually this is default http port so probably u won&#8217;t have to change this</p>
<p>$server= &#8216;www.gametrailers.com&#8217;;<br />
//i tested thet with this host, but i guess it will work on many other URLs as well</p>
<p>$url = &#8216;/index.php?&#8217;;  //this is the index file of the url</p>
<p>$content = &#8216;userlog&#8217;;<br />
//these are custom variables especially for gametrailers &#8211; probably you won&#8217;t have to use them<br />
$content .= &#8216;&amp;try=1&#8242;;<br />
//these are custom variables especially for gametrailers &#8211; probably you won&#8217;t have to use them</p>
<p>//enter your site login name<br />
$content .= &#8216;&amp;username=your_username&#8217;;<br />
//enter your site pass<br />
$content .= &#8216;&amp;password=your_pass&#8217;;<br />
$content_length = strlen($content);<br />
//don&#8217;t touch this one &#8211; the header has to have valid lenght</p>
<p>$headers = &#8220;POST $url HTTP/1.0\r\n&#8221;;<br />
$headers.= &#8220;Content-type: application/x-www-form-urlencoded\r\n&#8221;;<br />
$headers.= &#8220;Host: $server\r\n&#8221;;<br />
$headers.= &#8220;Content-length: $content_length\r\n\r\n&#8221;;</p>
<p>$fp = fsockopen($server, $port, $errno, $errstr);<br />
//we open connection to our URL<br />
if (!$fp) return false;</p>
<p>fputs($fp, $headers);</p>
<p>fputs($fp, $content);<br />
$ret = &#8220;&#8221;;<br />
while (!feof($fp)) {<br />
$ret.= fgets($fp, 1024);<br />
//we get the content of the URL<br />
}<br />
fclose($fp);</p>
<p>print &#8220;&lt;pre style=&#8221;position:absolute;z-index:100;&#8221;&gt;&#8221;.$ret.&#8221;&lt;/pre&gt;&#8221;;</p>
<p>//we print the actual content of the website, and finally we are logged as user <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
?&gt;</p>
<p>You see &#8211; succeed to login on this URL (gametrailers), but on for some other URL you will have to make some more custom solution. For example you will have to check the login form &#8211; what are the &#8220;name&#8221; properties for the html input elements, and to change that in the script, but after that everything should be fine <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://georgi-mitev.com/2009/03/20/login-locally-to-remote-host/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
