<?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; PHP</title>
	<atom:link href="http://georgi-mitev.com/tag/php/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>HTTP, HTTPS, and SSL via PHP</title>
		<link>http://georgi-mitev.com/2009/05/10/http-https-and-ssl-via-php/</link>
		<comments>http://georgi-mitev.com/2009/05/10/http-https-and-ssl-via-php/#comments</comments>
		<pubDate>Sun, 10 May 2009 07:08:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[https and php]]></category>
		<category><![CDATA[https via php]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[ssl and php]]></category>
		<category><![CDATA[ssl via php]]></category>

		<guid isPermaLink="false">http://georgi-mitev.com/?p=81</guid>
		<description><![CDATA[Today i found this very cool tutorial regarding the using of using ssl with PHP.
I&#8217;ll copy here the most interesting of it.
HTTP with PHP Sockets
// don&#8217;t need to specify http, it&#8217;s the default protocol
$hostname = &#8220;www.google.com&#8221;;
$port     = 80;
// create and configure the client socket
$fp = fsockopen($hostname, $port); // optional: $error_number, $error_string, [...]]]></description>
			<content:encoded><![CDATA[<p>Today i found this very cool tutorial regarding the using of using ssl with PHP.</p>
<p>I&#8217;ll copy here the most interesting of it.</p>
<h2><a name="http-sockets">HTTP with PHP Sockets</a></h2>
<p>// don&#8217;t need to specify http, it&#8217;s the default protocol<br />
$hostname = &#8220;www.google.com&#8221;;<br />
$port     = 80;</p>
<p>// create and configure the client socket<br />
$fp = fsockopen($hostname, $port); // optional: $error_number, $error_string, $connect_timeout<br />
if ($fp) {<br />
    stream_set_timeout($fp, 30); // seconds to wait for i/o operations</p>
<p>    // send request headers<br />
    fwrite($fp, &#8220;GET / HTTP/1.1\r\n&#8221;);<br />
    fwrite($fp, &#8220;Host: $hostname\r\n&#8221;);<br />
    fwrite($fp, $additional_headers); // Accept, User-Agent, Referer, etc.<br />
    fwrite($fp, &#8220;Connection: close\r\n&#8221;);</p>
<p>    // read response<br />
	$response = &#8220;&#8221;;<br />
    while (!feof($fp)) {<br />
        $response .= fgets($fp, 128);<br />
    }<br />
	echo $response;</p>
<p>    // close the socket<br />
    fclose($fp);<br />
}<br />
<span id="more-81"></span></p>
<h2><a name="raw-ssl-sockets">Direct SSL Sockets in PHP</a></h2>
<p>You don&#8217;t have to send request headers in the above example. You can actually connect to some servers and send raw text with <code>fwrite</code>. Because you have to implement the HTTP/HTTPS protocol yourself if you want it, sockets are considered &#8220;clean&#8221; connections.<br />
You don&#8217;t have to send request headers in the above example. You can actually connect to some servers and send raw text with fwrite. Because you have to implement the HTTP/HTTPS protocol yourself if you want it, sockets are considered &#8220;clean&#8221; connections.</p>
<p>// note that &#8220;ssl&#8221; is the protocol, NOT &#8220;https&#8221;<br />
$hostname  = &#8220;ssl://your-secure-site.com&#8221;;<br />
$port      = 443;</p>
<p>// create and configure the client socket<br />
$fp = fsockopen($hostname, $port);<br />
if ($fp) {<br />
    stream_set_timeout($fp, 30);</p>
<p>	// send data (or build HTTPS headers similar to first example)<br />
	fwrite($fp, &#8220;your message goes here&#8221;);</p>
<p>    // read response<br />
    while (!feof($fp)) {<br />
        echo fgets($fp, 128);<br />
    }</p>
<p>    // close the socket<br />
    fclose($fp);<br />
}</p>
<h2><a name="https-curl">HTTPS via cURL</a></h2>
<p>PHP doesn&#8217;t directly support attaching client certificates to web requests with <code>fsockopen</code>, so  you have to use the <code>cURL</code> library.<br />
$url = &#8220;https://your-secure-site.com/secure-service.php&#8221;;<br />
$port = 443;</p>
<p>// POST data, formatted just like a GET query string<br />
$request = &#8220;name=hb&amp;age=27&amp;site=arguments.callee.info&#8221;;</p>
<p>// the client certificate path MUST be a physical path, not url<br />
$certificate = &#8220;C:\\certificates\\test.crt&#8221;; // windows example<br />
$certificate = &#8220;/etc/pki/tls/private/test.crt&#8221;; // unix/linux example<br />
$password = &#8216;mypassword&#8217;; // client certificate&#8217;s key</p>
<p>// more details at http://php.net/curl<br />
$ch = curl_init();<br />
curl_setopt($ch, CURLOPT_POST, 1);<br />
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
curl_setopt($ch, CURLOPT_URL, $url);<br />
curl_setopt($ch, CURLOPT_PORT, $port);<br />
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);<br />
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);<br />
curl_setopt($ch, CURLOPT_SSLCERT, $certificate);<br />
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $password);</p>
<p>// fetch response and close the socket<br />
$response = curl_exec($ch);<br />
curl_close($ch);</p>
]]></content:encoded>
			<wfw:commentRss>http://georgi-mitev.com/2009/05/10/http-https-and-ssl-via-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Export / Import Excel file to sql / database using CSV and PHP</title>
		<link>http://georgi-mitev.com/2009/03/09/export-import-excel-file-to-sql-database-using-csv-and-php/</link>
		<comments>http://georgi-mitev.com/2009/03/09/export-import-excel-file-to-sql-database-using-csv-and-php/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 09:40:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[export CSV]]></category>
		<category><![CDATA[import CSV]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://georgi-mitev.com/?p=52</guid>
		<description><![CDATA[Hello everybody,
today i&#8217;ll be talking about how to export / import your Excel file into you your database using the PHP and the CSV file format.
First of all we need an Excel file with our data.
Every row of the excel file should be the same format as the previous row (so that we can make [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Hello everybody</strong>,</p>
<p>today i&#8217;ll be talking about how to export / import your Excel file into you your database using the PHP and the CSV file format.<br />
First of all we need an Excel file with our data.</p>
<p>Every row of the excel file should be the same format as the previous row (so that we can make our life easier), for example if we want to import a excel file with name/url addres corresponding to this name we should have our excel file in a format like this:<br />
<img src="http://georgi-mitev.com/images/posts/3.2009/excel.png" alt="exel file example" /><br />
After u have the file in this excel format u should hit -&gt; File -&gt; Save as -&gt; CSV (Comma Delimited) or more ofter its Called &#8220;Comma Separated Values&#8221;. For the comma separator use &#8220;;&#8221; if it asks you. So after you save the file in the CSV file format you should have something like this after you open the file with notepad etc.:</p>
<p><span id="more-52"></span><br />
<img src="http://georgi-mitev.com/images/posts/3.2009/csv.png" alt="exel file example" /><br />
in this case we use &#8220;;&#8221; for comma separator.</p>
<p>ok lets get now to the Databse &#8211; in my case i will be using mysql, so for the sample excel file above you can use this code to create your database:</p>
<p><span style="color: #888888;">CREATE DATABASE MerchantManager;<br />
USE MerchantManager;<br />
CREATE TABLE IF NOT EXISTS `merchants` (<br />
`MerchantID` int(11) NOT NULL AUTO_INCREMENT,<br />
`MerchantTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,<br />
`MerchantName` varchar(256) NOT NULL,<br />
`MerchantURL` varchar(256) NOT NULL,<br />
PRIMARY KEY (`MerchantID`)<br />
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=185 ;</span></p>
<p>after we create the database we are going to write some function in php that can import the data into our Database:</p>
<p>we can create now a new file &#8211; &#8220;import.php&#8221;</p>
<p><span style="color: #888888;">&lt;?<br />
</span></p>
<p><span style="color: #888888;">function AddMerchant($name, $url){<br />
$host = &#8220;localhost&#8221;;<br />
$user = &#8220;root&#8221;;<br />
$pass = &#8220;&#8221;; // use your mysql password<br />
$db_name = &#8220;merchantmanager&#8221;;<br />
$table = &#8220;merchants&#8221;;</span></p>
<p><span style="color: #888888;">mysqli_query(new mysqli($host, $user, $pass, $db_name), &#8220;INSERT INTO &#8220;.$table.&#8221; (`MerchantName`, `MerchantURL`) VALUES (&#8216;$name&#8217;, &#8216;$url&#8217;)&#8221;);</span></p>
<p><span style="color: #888888;">}<br />
?&gt;</span></p>
<p> <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  okz i hope it&#8217;s all clear for now, so let&#8217;s get to the php now <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
To export the CSV file into our database we are going to use:</p>
<p>&#8220;file_get_contents&#8221; function &#8211; <a href="http://bg.php.net/file_get_contents">http://bg.php.net/file_get_contents</a><br />
and &#8220;explode&#8221; function &#8211; http://bg.php.net/manual/en/function.explode.php</p>
<p>so lets get started, after the &#8220;AddMerchant()&#8221; function that we wrote above, we will add the following code into the file &#8220;import.php&#8221;</p>
<p><span style="color: #888888;">$file = file_get_contents(&#8220;file.csv&#8221;); //we load the CSV file and put it in a variable</span></p>
<p><span style="color: #888888;">$rows = explode(&#8220;\n&#8221;, $file); //we brake the variable into array, using the new line as a condition</span></p>
<p><span style="color: #888888;">foreach($rows as $row){</span></p>
<p style="padding-left: 30px;"><span style="color: #888888;"> $items = explode(&#8220;;&#8221;, $row); //we brake it again into another array using the &#8220;;&#8221; sign in our case<br />
AddMerchant($items[0],$items[1]);// we get the first and the second value of the array (name and url)<br />
echo &#8220;success&#8221;;</span></p>
<p><span style="color: #888888;">}</span></p>
<p><span style="color: #888888;">?&gt;</span></p>
<p>Can you believe it&#8217;s that simple <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  3 lines of code and we managed to put the information from the excel file into the database.</p>
<p>if you want to get all the source code from this simple tutorial<br />
download it here: <a href="http://georgi-mitev.com/files/tutorials/export_csv_to_mysql.rar">export_csv_to_mysql.rar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://georgi-mitev.com/2009/03/09/export-import-excel-file-to-sql-database-using-csv-and-php/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
