PHP workaround – how to use file_get_contents() without allow_url_fopen

php_artikel_logoI admit, the title of this article is somewhat misleading. The PHP function file_get_contents(), which can be used to read files from the internet into a string, just does not work with allow_url_fopen disabled. On that not even this article will change anything.
However, if you want to develop an application or a script, that should work on as many server environments as possible, such as a wordpress plugin, so there is a good workaround for all the environments where allow_url_fopen is disabled. And just this little snippet/workaround is what I want to show and explain to you today.

$file = "http://www.example.com/my_page.php";
if (function_exists(‘curl_version’))
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $file);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl);
curl_close($curl);
}
else if (file_get_contents(__FILE__) && ini_get(‘allow_url_fopen’))
{
$content = file_get_contents($file);
}
else
{
echo ‘You have neither cUrl installed nor allow_url_fopen activated. Please setup one of those!’;
}

First, it is checked whether the cURL extension is available on the server. If […]

MD5 hashes in C# – benchmark and speed ​​optimization

For a current project I must generate a large number of MD5 hashes. I explicitly don’t want to discuss the meaning and security of MD5 hashes in this article, but rather concern myself with the question on how to generate MD5 hashes as fast as possible using C#.
The. NET Framework itself provides a class for creating MD5 hashes, which after the first attempts seemed a little slow to me. So I began to search for alternative classes and/or functions and came across a class of Syed Faraz Mahmood. His class is a manual implementation of the RFC 1321 (“The MD5 Message-Digest Algorithm”). The class can be downloaded for free on his blog.
The test environment
For the test I created six lists (List<int>) with many different numbers. Each with 1,000, 10,000, 50,000, 100,000, 1,000,000 and 10,000,000 elements.
All lists were run complete for both methods (MD5 .NET framework implementation & manual MD5 implementation) and […]

New project: colorcodes.code-bude.net

ColorCodes - ÜbersichtToday I would like to point you to a small project of mine, which I have released a few minutes ago. Concrete it’s “colorcodes.code-bude.net“, a small website which presents you a list of all the colors that are in the Color-struct of the .NET framework.
On the home page you get an overview in list form, including RGB and hexadecimal representation of the colors. Via a link in each table entry you will be lead to a details page (like that), where all information is summarized again for each color.
ColorCodes - DetailansichtThe whole thing is more practice and research project, than a serious webpage. For one, I wanted to do some little finger exercise – so all pages have been automatically generated with a C# […]

How to use Wortschatz Leipzig web services in C#

C# Sourcecode IconIn that article I provided a small C# based library that allows you to easily access the thesaurus web service of the Wortschatz Leipzig project.
Now, in this article, I want to describe briefly what “obstacles” I had to overcome to address the web service from C#. Despite the fact that the Wortschatz Leipzig team provides a WSDL file for their web service, it is not done with adding a Web- or ServiceReference in Visual Studio.
 
Add Wortschatz Leipzig web service to Visual Studio solution
First you need to create a ServiceReference to the desired web service. For this article, let’s take the thesaurus web service. The path to the WSDL file, which is required to create the ServiceReference, is:
http://wortschatz.uni-leipzig.de/axis/services/Thesaurus?wsdl
Info: I called the ServiceReference “ThesaurusClient”.
Now one would think that everything is done and you would have to instantiate the client class […]

C#-API for the Wortschatz Leipzig webservices

csharp webserviceAt the weekend I was looking for a way to find synonyms for a given word. After a quick search on the net I came across the Openthesaurus project, which offers an offline database of synonyms for download. However, I wanted to have a second source for comparison. After further searching, I went to the thesaurus of the “Wortschatz Leipzig” project.  Although they offer no offline synonym database, but a free webservice.
Since this web service can not be easily integrated in the Visual Studio into your own projects and it took me some time and energy to figure out how to get things up and running, I have enclosed my whole web service client code into a small library.
If you’re not interested in a “ready-to-use” library, but […]