<?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>Bohack &#187; Scripts</title>
	<atom:link href="http://www.bohack.com/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bohack.com</link>
	<description>Check In and Tune Out!</description>
	<lastBuildDate>Sun, 08 Jan 2012 20:59:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>A Simple PHP mail() Function For Testing SMTP Delivery</title>
		<link>http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/</link>
		<comments>http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:05:00 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=385</guid>
		<description><![CDATA[Making sure mail is sent properly from a PHP website is a bit difficult when it’s not your server, like shared hosting. So I created a simple php script called testmail.php that sends mail via the mail() function.<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/' addthis:title='A Simple PHP mail() Function For Testing SMTP Delivery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Making sure mail is sent properly from a PHP website is a bit difficult when it’s not your server, like shared hosting. You never have access to the mail logs, so you can’t see mail moving. I host several websites on shared hosting and recently found my CMS was not sending emails to me. So I opened a ticket and I concluded it to be a SNAFU.</p>
<p><span id="more-385"></span>I’m never satisfied when I conclude something doesn’t work because it’s complex. The best thing to do is to snap into diagnostic mode. The first rule of diagnosis of the problem is start simple and work from there. The saying of getting to the root of the problem is accurate.</p>
<p>I looked at the CMS code and concluded that the function being called to send mail is the PHP function of mail(). So I needed to check the PHP mail function by itself, without the complexity of the CMS. If the mail() function sends mail, then the problem is the CMS or my email. If the mail() function does not send mail, then my provider has something that they can work with and I can present the problem to them. Simple I created a simple PHP script called testmail.php with this short little string of code:</p>
<pre>&lt;?php
$to = 'youraccount@youremail.com';
$subject = 'Sent on '.date("F j, Y, g:i a");
$message = 'Test message';

mail($to, $subject, $message);
?&gt;
</pre>
<p>This routine will send mail to the $to variable and also tag the date in the subject. This is all done via the sendmail variable in php, you can do a phpinfo() to find which program sends mail. This can be handy if you need to see when it left the other system and came into yours. Just look the original header and you will be able to see all details.</p>
<p>In the end my problem resulted in my SPAM filter catching the email thus never showing up in the Inbox. Stupid problem, but until you verify the flow of mail with your hosting provider and scale your complexity back… You won’t solve the problem.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/' addthis:title='A Simple PHP mail() Function For Testing SMTP Delivery ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2010/01/a-simple-php-mail-function-for-testing-smtp-delivery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To Save A Webpage In HTML To A File In VBScript</title>
		<link>http://www.bohack.com/2009/12/how-to-save-a-webpage-in-html-to-a-file-in-vbscript/</link>
		<comments>http://www.bohack.com/2009/12/how-to-save-a-webpage-in-html-to-a-file-in-vbscript/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 18:45:31 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=361</guid>
		<description><![CDATA[The VBScript code will get a webpage from Google and save the HTML to a file using the msxml2.xmlhttp.6.0 object.<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/12/how-to-save-a-webpage-in-html-to-a-file-in-vbscript/' addthis:title='How To Save A Webpage In HTML To A File In VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I had just finished working on a project where I needed to programmatically get a web page and save the HTML to a file. I started toying around with some code I used for parsing XML and totally rewrote the code. I found that I kept getting an error of “Microsoft VBScript runtime error: Invalid procedure call or argument”. I couldn’t understand what was going on. I was passing the parameters correctly to the File System Object, but I kept getting the error. All FSO was doing was creating a file and writing the string out. So I checked the length and then started writing the left(string,number) and found it was a character that was in Unicode. So I wrote a Unicode to Ascii function that is not all that efficient, but it is very effective. The sample code below will get a webpage from Google and save it to a file.</p>
<p><span id="more-361"></span>You can modify the code to accept arguments and make a VBScript replacement for wget the UNIX command. However wget is much more versatile and allows for a lot more features like agent string and referrer string modification. I use the “msxml2.xmlhttp.6.0” object, but you can replace it with “msxml2.xmlhttp.3.0” if you run into a problem. I had tested it on XP and Vista, so I think the “msxml2.xmlhttp.6.0” is tied to the IE version of IE version 6. Maybe someone can clarify that. The code does work and enjoy.</p>
<pre>
Dim FSO, dFile, sHTML

sHTML = Get_HTML ("http://www.google.com")

Set FSO = CreateObject("Scripting.FileSystemObject")
Set dFile = FSO.CreateTextFile("SaveFile.html", True)

dFile.Write UniToAsc(sHTML)
dFile.Close

Set dFile = Nothing
Set FSO = Nothing

Private Function Get_HTML (up_http)
 Dim xmlhttp
 Set xmlhttp = createobject("msxml2.xmlhttp.6.0")

 xmlhttp.open "get", up_http, False
 xmlhttp.send
 Get_HTML = xmlhttp.responsetext

 set xmlhttp = Nothing
End Function

Private Function UniToAsc(sString)
 Dim nLen, nPTR, sAsc
 nLen = Len(sString)

 For nPTR = 1 To nLen
  sAsc = sAsc &amp; Chr(Asc(Mid(sString, nPTR, 1)))
 Next

 UniToAsc = sAsc
End Function
</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/12/how-to-save-a-webpage-in-html-to-a-file-in-vbscript/' addthis:title='How To Save A Webpage In HTML To A File In VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2009/12/how-to-save-a-webpage-in-html-to-a-file-in-vbscript/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Query and Parse XML from VBScript</title>
		<link>http://www.bohack.com/2009/02/query-and-parse-xml-from-vbscript/</link>
		<comments>http://www.bohack.com/2009/02/query-and-parse-xml-from-vbscript/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 19:19:17 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=298</guid>
		<description><![CDATA[Toying around I needed to query XML from VBScript and parse it out for only the elements I needed. So I wrote a VBScript and figured I would share it. Many posts out there just load a file rather than a URL, this script will do both and I simplified it a bit. The script [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/02/query-and-parse-xml-from-vbscript/' addthis:title='Query and Parse XML from VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Toying around I needed to query XML from VBScript and parse it out for only the elements I needed. So I wrote a VBScript and figured I would share it. Many posts out there just load a file rather than a URL, this script will do both and I simplified it a bit.</p>
<p><span id="more-298"></span>The script here will basically query the URL and parse it our for the element name of description. Find a sitemap for a site and change the URL line like (http://somewhere.com/gsitemap.xml) and then change the xmltag to &#8220;loc&#8221;.</p>
<pre>url = "http://news.google.com/news?hl=en&amp;tab=wn&amp;ned=us&amp;q=test&amp;ie=UTF-8&amp;nolr=1&amp;output=rss"
xmltag = "description"

set xmlDoc = createobject("Microsoft.XMLDOM")
xmlDoc.async = "false"
xmlDoc.load (url)

set xmlCol = xmldoc.getElementsByTagName(xmltag)

For Each Elem In xmlCol
 wscript.Echo(Elem.firstChild.nodeValue)
Next

WScript.Echo "XML Element Count :" &amp; xmlCol.length

Set xmlCol = Nothing
Set xmlDoc = Nothing</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/02/query-and-parse-xml-from-vbscript/' addthis:title='Query and Parse XML from VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2009/02/query-and-parse-xml-from-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple VBScript to Display a Web Page</title>
		<link>http://www.bohack.com/2009/02/simple-vbscript-to-display-a-web-page/</link>
		<comments>http://www.bohack.com/2009/02/simple-vbscript-to-display-a-web-page/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 17:27:47 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=279</guid>
		<description><![CDATA[I was currently working on a VBScript to pull some information from a web page. So decided to build a function for it, so that it can be reused over and over again in other scripts. It uses the XMLHTTP library to query a URL and return the elements, I just ask for the responsetext [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/02/simple-vbscript-to-display-a-web-page/' addthis:title='Simple VBScript to Display a Web Page ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I was currently working on a VBScript to pull some information from a web page. So decided to build a function for it, so that it can be reused over and over again in other scripts. It uses the XMLHTTP library to query a URL and return the elements, I just ask for the responsetext and return it.</p>
<p><span id="more-279"></span></p>
<pre>Function GetHTML (url)
dim http
set http = createobject("msxml2.xmlhttp.3.0")
http.open "get", url, False
http.send

GetHTML = http.responsetext

set http = Nothing
End Function

WScript.echo GetHTML ("http://www.bohack.com")
</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/02/simple-vbscript-to-display-a-web-page/' addthis:title='Simple VBScript to Display a Web Page ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2009/02/simple-vbscript-to-display-a-web-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Page Stop Watch</title>
		<link>http://www.bohack.com/2009/01/php-page-stop-watch/</link>
		<comments>http://www.bohack.com/2009/01/php-page-stop-watch/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 01:20:50 +0000</pubDate>
		<dc:creator>Bohack</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bohack.com/?p=261</guid>
		<description><![CDATA[Lots of time I have web pages performing complex functions and want to make sure that they execute without a problem. A problem would be they just take too damn long and time out when put under a load. This is the problem when things don&#8217;t scale properly, they just get really slow. So in [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/01/php-page-stop-watch/' addthis:title='PHP Page Stop Watch ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Lots of time I have web pages performing complex functions and want to make sure that they execute without a problem. A problem would be they just take too damn long and time out when put under a load. This is the problem when things don&#8217;t scale properly, they just get really slow. So in order to gauge how long a page takes to load we really need a stop watch. Luckily we the components of one&#8230;</p>
<p><span id="more-261"></span><br />
The PHP microtime() function returns the UNIX timestamp with micro-seconds.</p>
<pre>&lt;?php echo (microtime()) ?&gt;;   //returns 0.123123 1231231231</pre>
<p>The first number is the microseconds from the change of the second number, which is the time in seconds from the UNIX epoch of 0:00:00 Jan 1st 1970.  So we can explode the line returned into an array using the explode command, then mathematically add them together. i.e. 1231231231.123123. The last line will take the end time and subtract the start time. The result will be displayed in the HTML comments towards the end of the page, where this code is executed.</p>
<pre>Put this at the beginning of your page inside of the php tags.

$start=microtime();
$start=explode(" ",$start);
$start=$start[1]+$start[0];

// do something here

Put this at the end of you page inside of the php tags.

$end=microtime();
$end=explode(" ",$end);
$end=$end[1]+$end[0];

printf("\n&lt;!-- Page was generated by PHP %s in %f seconds --&gt;\n",phpversion(),$end-$start);</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.bohack.com/2009/01/php-page-stop-watch/' addthis:title='PHP Page Stop Watch ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.bohack.com/2009/01/php-page-stop-watch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

