<?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>PHP &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/category/web-development/php/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Mon, 08 Jul 2019 19:54:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Laravel in five minutes: A super short crash course for the awesome PHP framework (principles and core functionalities)</title>
		<link>https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/</link>
					<comments>https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 08 Jul 2019 19:44:35 +0000</pubDate>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[crash course]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[for dummies]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2384</guid>

					<description><![CDATA[Laravel super short five minutes crash course - an overview of what it is, the core concepts and the core functionalities.]]></description>
										<content:encoded><![CDATA[<p>For understanding this Q&amp;A style tutorial you should have basic knowledge about PHP programming and frameworks. You do not have to know Laravel yet. For the real documentation just learn <a href="https://laravel.com/docs/">https://laravel.com/docs/</a> &#8211; most information in this tutorial is just a real short summary of the documentation. It is useful though if you have to learn about what Laravel is and what the most important concepts and components are.</p>
<p>&nbsp;</p>
<p><strong>Why should I even use Laravel?</strong></p>
<p>Because it is a super clean, easy to use PHP framework. My personal experience (this is subjective) told me that it is way easier to understand than the whole Symfony framework (Laravel is built on Symfony) or the Zend Frameworks. Symfony and Zend are both great frameworks, for sure, but Laravel offers you <em>simplicity</em>.</p>
<p>Laravel enables you to use best practice coding techniques for object-oriented programming. It comes with a powerful set of features for building solid web applications and assists you with solving common as well as complex problems.</p>
<p>&nbsp;</p>
<p><strong>Why shall Laravel be used with the newest PHP version (best will be the upcoming PHP 7.4)?</strong></p>
<p>Laravel makes heavy use of modern features within the PHP language. It is completely object oriented and uses e.g. typed input parameters which came with PHP 7.</p>
<p>The real great thing about PHP 7.4 is that it offers <strong>typed properties</strong>, <strong>covariant returns</strong> (more generic in subclass) and <strong>contravariant input parameters</strong> (more specific in subclass). This is extremely powerful (you should read more about it)!</p>
<p><strong> </strong></p>
<p><strong>What is Dependency Injection?</strong></p>
<p>Definition (Wikipedia): “In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A &#8220;dependency&#8221; is an object that can be used, for example a service. Instead of a client specifying which service it will use, something tells the client what service to use. The &#8220;injection&#8221; refers to the passing of a dependency (a service) into the object (a client) that would use it. The service is made part of the client&#8217;s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.</p>
<p>The intent behind dependency injection is to achieve Separation of Concerns of construction and use of objects. This can increase readability and code reuse.</p>
<p>Dependency injection is one form of the broader technique of inversion of control. The client delegates the responsibility of providing its dependencies to external code (the injector). The client is not allowed to call the injector code; it is the injecting code that constructs the services and calls the client to inject them. This means the client code does not need to know about the injecting code, how to construct the services or even which actual services it is using; the client only needs to know about the intrinsic interfaces of the services because these define how the client may use the services. This separates the responsibilities of use and construction.”</p>
<p>That means that an object either is provided with another required object within its constructor or it just specifies some interface which is used for type hinting in constructors or methods.</p>
<p>The purpose of this is to get rid of dependencies and to achieve loose coupling (and high cohesion).</p>
<p>&nbsp;</p>
<p><strong>What is a Service Container and what is the Laravel Service Container doing?</strong></p>
<p>A Service Container (or dependency injection container) is simply a PHP object that manages the instantiation of services (i.e. objects). The Service Container in Laravel is a Dependency Injection Container and a Registry for the application. The advantages of using a Service Container over creating manually your objects are.</p>
<p>It is often called with App::bind App:make etc.</p>
<p>The service provider is creating concrete classes automatically when required.</p>
<p>Class dependencies can be managed on object creation and it is used as a registry.</p>
<p>Laravel does this with binding certain services to the App:</p>
<p><code>$this-&gt;app-&gt;bind('FooService', \App\Services\FooService::class);</code></p>
<p>Essentially we are telling Laravel: “Hey store this object in your bag of tricks and label it as FooService”. Remember to always bind your services within the register method of your service providers.</p>
<p>There are also events in the service container where somebody can register to.</p>
<p><strong> </strong></p>
<p><strong>What is a Service Provider?</strong></p>
<p>Core part of a Laravel application, resides in Providers directory. Has usually a special purpose like e.g. Authentication, Translation, ….</p>
<p>Service providers are usually registered on application bootstrap. All service providers are registered in <strong>app/config.php.</strong></p>
<p>A service provider has a register and a boot method. The register method is called early and is for registering with the Service Container, the boot method is called after all Services has been registered and therefore you can use all Service Container within it.</p>
<p>&nbsp;</p>
<p><strong>What is „type hinting“?</strong></p>
<p>Methods / functions with typed input parameters (optional in PHP).</p>
<p>&nbsp;</p>
<p><strong>What is (dynamic) binding in Laravel?</strong></p>
<p>Laravel usually means binding a service provider to the service container. Almost all service container bindings will be registered within service providers.</p>
<p>&nbsp;</p>
<p><strong>What is middleware?</strong></p>
<p>A layer between a client request from the frontend and a resource (data) in the backend. Therefore the logical part oft he backend which glues certain programs / part of a program together. It simplifies backend resource requests.</p>
<p>Middleware also serves the purpose of load balancing (distributing requests), concurrency, securring the backend,  …</p>
<p>Laravel offers many Middleware objects. One middleware for instance is for authentication, but you can also use middleware for certain headers for instance.</p>
<p>&nbsp;</p>
<p><strong>What is a Facade?</strong></p>
<p>A Facade is a programming design pattern. It usually offers <strong><em>a simplified standardized interface to a certain set of sub-systems</em></strong>.</p>
<p>In Laravel: Facades provide a &#8220;static&#8221; interface to classes that are available in the application&#8217;s service container. Laravel ships with many facades which provide access to almost all of Laravel&#8217;s features. Laravel facades serve as &#8220;static proxies&#8221; to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.</p>
<p>Examples for Facades in Laravel are calls to App::, Auth::, DB::, Cookie:: …</p>
<p>Facades can be useful because they are not required in class constructors, but they can also make an application complicated to maintain in case they get to large.</p>
<p>&nbsp;</p>
<p><strong>What is a Contract in Laravel?</strong></p>
<p>Laravel&#8217;s Contracts are a set of interfaces that define the core services provided by the framework. The Illuminate\Contracts\Queue\Queue contract i.e. defines the methods needed for queueing jobs, while the Illuminate\Contracts\Mail\Mailer contract defines the methods needed for sending e-mail.</p>
<p>Contracts are often imported with the use keyword and used (e.g. in the constructor or some method). It is easy to write alternative Contract implementations and therefore they can be replaced easily.</p>
<p>&nbsp;</p>
<p><strong>What is PHP artisan?</strong></p>
<p>PHP artisan is command line tool that makes your life easier. In fact, very much easier while working with Laravel. If you know about any MVC framework, you would know what I&#8217;m about to say, it can create models, controllers, seeders, migrations and many other things with minimum (or maximum) boilerplate code. It can also start a server and can do many other things.</p>
<p><strong> </strong></p>
<p><strong>How is routing working in Laravel?</strong></p>
<p>Usually defined in routes/web.php (for API routs for instance routes/api.php is used). Basically defined with the Route Facade which offers the common HTTP methods and a callback function. Routes have certain rules for parameters (also wildcard), can be grouped, …</p>
<p>&nbsp;</p>
<p><strong>What are Controllers in Laravel?</strong></p>
<p>Handling all requests within route files can be clumsy. Controllers can do the most important calls to the model/business layer and return everything properly.</p>
<p>&nbsp;</p>
<p><strong>What is the Request/Response object doing?</strong></p>
<p>The service container can automatically inject Request/Response objects (e.g. into a certain Controller). It contains info like e.g. input parameters, cookies, and does some sanitation on it.</p>
<p>Routes and Controllers usually should return response objects or views. You can add headers and cookies, create downloads, define the output, …</p>
<p>&nbsp;</p>
<p><strong>How are views in Laravel working?</strong></p>
<p>In most projects Blade is used as a template engine. The views are built with html and contain output injected by Blade.</p>
<p>&nbsp;</p>
<p><strong>How is validation in Laravel working?</strong></p>
<p>Laravel has a powerful set of validation rules which can be performed on inputs (e.g. in Controllers).</p>
<p>&nbsp;</p>
<p><strong>How is Laravel to databases?</strong></p>
<p>Laravel usually uses the Eloquent ORM mapper. It simplifies database communication and SQL statements with certain methods. It offers a query builder which simplifies queries.</p>
<p>&nbsp;</p>
<p><strong>How are migrations and seeding working in Laravel?</strong></p>
<p>Migrations are like version control for your database, allowing your team to easily modify and share the application&#8217;s database schema. Migrations are typically paired with Laravel&#8217;s schema builder to easily build your application&#8217;s database schema. If you have ever had to tell a teammate to manually add a column to their local database schema, you&#8217;ve faced the problem that database migrations solve.</p>
<p>The Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel&#8217;s supported database systems.</p>
<p>Laravel has a Seeder for seeding applications with defined or random data which is really helpful during development.</p>
<p>&nbsp;</p>
<p>Be free to critizise this tutorial. Improvement ideas are always welcome! 😉 </p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2019%2F07%2F08%2Flaravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities%2F&#038;title=Laravel%20in%20five%20minutes%3A%20A%20super%20short%20crash%20course%20for%20the%20awesome%20PHP%20framework%20%28principles%20and%20core%20functionalities%29" data-a2a-url="https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/" data-a2a-title="Laravel in five minutes: A super short crash course for the awesome PHP framework (principles and core functionalities)"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PHP: Get rid of  &#8220;Notice: Undefined index .. in .. on line XXX&#8221; and undefined variable problems forever with this script</title>
		<link>https://blog.blackbam.at/2015/09/19/php-get-rid-of-notice-undefined-index-in-on-line-xxx-and-undefined-variable-problems-forever-with-this-script/</link>
					<comments>https://blog.blackbam.at/2015/09/19/php-get-rid-of-notice-undefined-index-in-on-line-xxx-and-undefined-variable-problems-forever-with-this-script/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sat, 19 Sep 2015 03:08:27 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[custom script]]></category>
		<category><![CDATA[helpers]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2264</guid>

					<description><![CDATA[Probably every PHP developer in the world has already seen the following notice at least once: Notice: Undefined index: not_set in /home/.sites/../../../&#8230;php on line 1 It happens if accessing the key of an array which does not exist. There is a very similar problem with PHP objects: If you access a property of an object [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Probably every PHP developer in the world has already seen the following notice at least once: </p>
<p><strong>Notice: Undefined index: not_set in /home/.sites/../../../&#8230;php on line 1</strong></p>
<p>It happens if accessing the key of an array which does not exist.</p>
<p>There is a very similar problem with PHP objects: If you access a property of an object in PHP you just get an empty string <strong>ever knowing if the property even existed</strong>. PHP does not even throw notices in this case.</p>
<p>Some examples:</p>
<pre lang="php">

//
$array = array("a","b","c");
echo $array[2]; // returns "c"
echo $array[3]; // returns nothing, notice undefined index

//
$_POST["my_field"]; // returns the value if submitted, or a notice if that value was not submitted

//
$obj = new stdClass();
$obj->a = "12";
$obj->b = "whatever";

echo $obj->a; // outputs string "12"
echo $obj->c; // outputs nothing, not even a notice just empty string

</pre>
<p>In order to enable save and good programming with PHP experienced PHP developers check for type safety and save array key accesses within their applications which usually requires a lot of extra work. PHP provides some operators and methods which check for the existence of keys and properties as well as for their type safety.</p>
<p>Example: Check if the user has submitted the value &#8220;yes&#8221; for the field &#8220;update&#8221; from a form and the array $_POST at key update contains a string value of yes.</p>
<pre lang="php">

if(isset($_POST['update']) &amp;&amp; $_POST['update'] === "yes")) {

}

</pre>
<p>Quite a lot of text to write right? There are a lot of native PHP methods which check for existence like isset(), property_exists(), array_key_exists() and more. Furthermore there are a lot of methods which check for type safety like is_int, is_bool etc. as well as the operators with the additional = like ===, !==.</p>
<p>However some time ago I somehow got annoyed by this behaviour of PHP especially. I developed a method which is especially useful in case a developer knows that a <strong>variable might not be populated</strong> and wants to set <strong>an adequate default value</strong> for this case. Furthermore I guarantees <strong>a type safe result</strong> for key/property access.</p>
<p>Just check out the following function and you may find it helpful, too:</p>
<p>&nbsp;</p>
<pre lang="php">
/**
 * Constats representing the primitive types.
 */
class Primitive {
    const STR = 0;
    const INT = 1;
    const BOOL = 2;
    const FLOAT = 3;
}

/**
 * In case you are unsure if an array key/object property exists and you want to get a (possibly typesafe) defined result.
 * 
 * @param $var array/object: An array or object with the possible key/property
 * @param $key array/string: The key. For a multidimensional associative array, you can pass an array.
 * @param $empty: If the key does not exist, this value is returned.
 * @param $primitive: The type of the given variable (-1 for ignoring this feature).
 * 
 * @return The (sanitized) value at the position key or the given default value if nothing found.
 */
function resempty(&$var,$key,$empty="",$primitive=-1) {
    
    $tcast = function($var,$primitive) {
        switch(true):
            case $primitive === Primitive::STR:
                $var = strval($var);
                break;
            case $primitive === Primitive::INT:
                $var = intval($var);
                break;
            case $primitive === Primitive::BOOL:
                $var = boolval($var);
                break;
            case $primitive === Primitive::FLOAT:
                $var = floatval($var);
                break;
        endswitch;
        return $var;
    };

    
    if(is_object($var)) {
        if(is_array($key)) {
            $tpclass = $var;
            $dimensions = count($key);
            for($i=0;$i<$dimensions;$i++) {
                if(property_exists($tpclass,$key[$i])) {
                    if($i === $dimensions-1) {
                        return $tcast($tpclass->$key[$i],$primitive);
                    } else {
                        $tpclass = $tpclass->$key[$i];
                    }
                } else {
                    return $tcast($empty,$primitive);
                }
            }
            return $tcast($empty,$primitive);
        }

        if(property_exists($var,$key)) {
            return $tcast($var->$key,$primitive);
        }
    } else if(is_array($var)) {
        if(is_array($key)) {
            $tpar = $var;
            $dimensions = count($key);
            for($i=0;$i<$dimensions;$i++) {
                if(array_key_exists($key[$i],$tpar)) {
                    if($i === $dimensions-1) {
                        return $tcast($tpar[$key[$i]],$primitive);
                    } else {
                        $tpar = $tcast($tpar[$key[$i]],$primitive);
                    }
                } else {
                    return $tcast($empty,$primitive);
                }
            }
            return $tcast($empty,$primitive);
        }

        if(array_key_exists($key,$var)) {
            return $tcast($var[$key],$primitive);
        }
    }
    return $tcast($empty,$primitive);
}

// Examples:
resempty($array,"key"); // returns the value at postion "key" if set, otherwise empty string
resempty($obj,"key",-1,Primitive::INT); // returns an integer value, -1 in case the property of the object is not set, otherwise the integer value of the object at this place


</pre>
<p>Be free to tell me if you find this useful or if you have improvement suggestions.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2015%2F09%2F19%2Fphp-get-rid-of-notice-undefined-index-in-on-line-xxx-and-undefined-variable-problems-forever-with-this-script%2F&#038;title=PHP%3A%20Get%20rid%20of%20%20%E2%80%9CNotice%3A%20Undefined%20index%20..%20in%20..%20on%20line%20XXX%E2%80%9D%20and%20undefined%20variable%20problems%20forever%20with%20this%20script" data-a2a-url="https://blog.blackbam.at/2015/09/19/php-get-rid-of-notice-undefined-index-in-on-line-xxx-and-undefined-variable-problems-forever-with-this-script/" data-a2a-title="PHP: Get rid of  “Notice: Undefined index .. in .. on line XXX” and undefined variable problems forever with this script"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2015/09/19/php-get-rid-of-notice-undefined-index-in-on-line-xxx-and-undefined-variable-problems-forever-with-this-script/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Breaking News &#8211; PHP: Hypertext Preprocessor discontinued</title>
		<link>https://blog.blackbam.at/2015/04/01/breaking-news-php-hypertext-preprocessor-discontinued/</link>
					<comments>https://blog.blackbam.at/2015/04/01/breaking-news-php-hypertext-preprocessor-discontinued/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Wed, 01 Apr 2015 21:55:18 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cobol]]></category>
		<category><![CDATA[discontinued]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2216</guid>

					<description><![CDATA[Bad news for all PHP developers and users of Open CMS. Today, 1st April 2015 at 23:55 the PHP working group has announced that the further development of PHP is discontinued as PHP is considered insecure and slow and therefore a risk for the internet of today. As this concern is serious there will be [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Bad news for all PHP developers and users of Open CMS. Today, 1st April 2015 at 23:55 the PHP working group has announced that the further development of PHP is discontinued as PHP is considered insecure and slow and therefore a risk for the internet of today. As this concern is serious there will be no further forks of the programming language.</p>
<p>However the development team &#8220;Chuck Norris&#8221; from Silicon Valley has created some sophisticated interpreter which can convert the source code of all your PHP projects into <a href="http://de.wikipedia.org/wiki/COBOL">COBOL</a>  which is considered to be the future web programming language of choice. Instead of complicated variable assignments like</p>
<pre lang="php">
$a = $b;
</pre>
<p>you can write</p>
<pre lang="cobol">
MOVE b TO a
</pre>
<p>&nbsp;</p>
<p class="de1">now, which looks way more plausible, right? Well after all I think this is a step in the correct direction and the PHP working group has made the correct decision. Do you agree?</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2015%2F04%2F01%2Fbreaking-news-php-hypertext-preprocessor-discontinued%2F&#038;title=Breaking%20News%20%E2%80%93%20PHP%3A%20Hypertext%20Preprocessor%20discontinued" data-a2a-url="https://blog.blackbam.at/2015/04/01/breaking-news-php-hypertext-preprocessor-discontinued/" data-a2a-title="Breaking News – PHP: Hypertext Preprocessor discontinued"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2015/04/01/breaking-news-php-hypertext-preprocessor-discontinued/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Calculate Local Timestamp (with Summertime) from UTC-Timestamp in PHP</title>
		<link>https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/</link>
					<comments>https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 16 Oct 2012 22:53:15 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Snippets]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2000</guid>

					<description><![CDATA[As it was a bit tricky to find out how this works, I want to share this script. This is how you can convert a UTC timestamp without offset and summertime into a converted timestamp using PHP. This is especially useful when extending a Calendar Plugin for example, which saves its dates in UTC-timestamps while [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As it was a bit tricky to find out how this works, I want to share this script. This is how you can convert a UTC timestamp without offset and summertime into a converted timestamp using PHP. This is especially useful when extending a Calendar Plugin for example, which saves its dates in UTC-timestamps while local time is needed.</p>
<pre lang="php">
/** Calculate middle european summertime */
function utc_to_local_time($timestamp,$offset=0,$summertime=true) { 
	 $year = strftime("%Y", $timestamp); 
	$timestamp += (3600*intval($offset)); // add local offset
	
	// Calculate beginning and end of Summertime
	$initTime = mktime(2,0,0,3,31-date('w', mktime(2,0,0,3,31,$year)),$year); 
	$endTime = mktime(2,0,0,10,31-date('w', mktime(2,0,0,10,31,$year)),$year); 

    // Check if summertime, return adequatly
    if (($timestamp > $initTime && $timestamp < $endTime) &#038;&#038; $summertime) { 
        return ($timestamp + 3600); 
    } else { 
        return ($timestamp); 
    } 
}

// example: Austria time
echo date("d.m.Y, H:i",utc_to_local_time($utc_time,1);
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F10%2F17%2Fcalculate-european-summertime-from-utc-timestamp-in-php%2F&#038;title=Calculate%20Local%20Timestamp%20%28with%20Summertime%29%20from%20UTC-Timestamp%20in%20PHP" data-a2a-url="https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/" data-a2a-title="Calculate Local Timestamp (with Summertime) from UTC-Timestamp in PHP"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Implementing a simple and flexible paging algorithm using PHP</title>
		<link>https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/</link>
					<comments>https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 18 Jul 2011 08:00:47 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1403</guid>

					<description><![CDATA[A very common problem in programming web pages is to implement paging. Paging is required whenever there is an undefined amount of items (usually queried from a database) with a maximum amount of items to be displayed on one page. If there is more than one page, there must be a possibility to navigate through [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A very common problem in programming web pages is to implement paging. Paging is required whenever there is an undefined amount of items (usually queried from a database) with a maximum amount of items to be displayed on one page. If there is more than one page, there must be a possibility to navigate through these pages while each page displays the desired amount of items.</p>
<h2>Case example</h2>
<p>Imagine you have a blog with a dynamic number of articles, while the current number of articles is 37. You want to create an article overview yourself, with the following conditions:<br />
1. The maximum number of articles on an overview page is 10<br />
2. A navigation to navigate to the next and previous 10 articles is required<br />
The result will be, that you need to have four pages:<br />
page 1: article 1-10,<br />
page 2: article 11-20,<br />
page 3: article 21-30,<br />
page 4: article 30-37<br />
<br />
Knowing the result, it is easy to develop a navigation between these pages: You just need to know the number of articles to show on each page (usually decided when coding the script), the page you are currently on (usually passed via Post- or Get- paramters and the number of all results you have to display (usually from counting the SQL results). <br />
But how can this result always be calculated dynamically?</p>
<h2>The script</h2>
<p>The following script shows the basic implementation of the page results algorithm in PHP:</p>
<pre lang="php">
/*** The three paramters ***/
// Make a query to get all your results (like posts, images, whatever)
$resultsOverall = 0;
 
// Results per page (the number of results per page to be shown)
$resultsPerPage = 10;
 
// Page number (the current page number, usually $_REQUEST['pageNumber'] or something similar)
$pageNumber = 1; 
 
if(isset($_REQUEST["pageNumber"]) && $_REQUEST["pageNumber"] > 1) {
	$pageNumber = $_REQUEST["pageNumber"];
}
 
 
/**** The logic ****/
// determine the first result to show
$resultsFrom = ($pageNumber*$resultsPerPage-$resultsPerPage+1);
 
// determine the last result to show
$resultsTo = ($resultsFrom-1)+$resultsPerPage;
 
if($resultsTo > $resultsOverall) {
	$resultsTo = $resultsOverall;
}
 
// determine number of Pages (for example to show in a navigation)
$allPages = ceil($resultsOverall / $resultsPerPage);
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F07%2F18%2Fimplementing-a-simple-and-flexible-paging-algorithm-using-php%2F&#038;title=Implementing%20a%20simple%20and%20flexible%20paging%20algorithm%20using%20PHP" data-a2a-url="https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/" data-a2a-title="Implementing a simple and flexible paging algorithm using PHP"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Bypass usage of sessions by using $_POST and hidden fields with JSON</title>
		<link>https://blog.blackbam.at/2011/04/21/bypass-usage-of-sessions-by-using-post-and-hidden-fields-with-json/</link>
					<comments>https://blog.blackbam.at/2011/04/21/bypass-usage-of-sessions-by-using-post-and-hidden-fields-with-json/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 21 Apr 2011 21:05:02 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bypass sessions]]></category>
		<category><![CDATA[hidden fields]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[Session]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1326</guid>

					<description><![CDATA[Today we have been searching for an easy and fast way to store and reuse $_POST variables over 2 pages and more without using a session. This can save you a lot of work in some cases. This possiblity is completly browser based, so there is no need for the server to re-identify a user. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Today we have been searching for an easy and fast way to store and reuse $_POST variables over 2 pages and more without using a session. This can save you a lot of work in some cases. This possiblity is completly browser based, so there is no need for the server to re-identify a user.</p>
<p></p>
<p>Save $_POST or some other array to a hidden field by converting it to the JSON-format. Use URL-encode to make sure that there will be no encoding problems.</p>
<p></p>
<pre lang="html4strict">
<form method="post" action="">
<input type='hidden' name='post_saver' value='<?php echo urlencode(json_encode($_POST)); ?>' />
</form>
</pre>
<p>Decode the hidden-fields&#8217; value on the server-side. Replace the $_POST variables depending on your needs or take the new ones.</p>
<p></p>
<pre lang="php">
// We save previous POST values in the 'post_saver', to provide page navigation and so on
if(strlen($_POST['post_saver'])>0) {

	$previous_post_object = json_decode(urldecode($_POST['post_saver']));
	unset($_POST['post_saver']);
	
	foreach($previous_post_object as $pkey=>$pval) {
		if(strlen($_POST[$pkey]) <= 0) {
			$_POST[$pkey] = $pval;
		}
	}
}
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F04%2F21%2Fbypass-usage-of-sessions-by-using-post-and-hidden-fields-with-json%2F&#038;title=Bypass%20usage%20of%20sessions%20by%20using%20%24_POST%20and%20hidden%20fields%20with%20JSON" data-a2a-url="https://blog.blackbam.at/2011/04/21/bypass-usage-of-sessions-by-using-post-and-hidden-fields-with-json/" data-a2a-title="Bypass usage of sessions by using $_POST and hidden fields with JSON"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/04/21/bypass-usage-of-sessions-by-using-post-and-hidden-fields-with-json/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Secure Sessions with PHP</title>
		<link>https://blog.blackbam.at/2010/01/26/session-sicherheit-in-php/</link>
					<comments>https://blog.blackbam.at/2010/01/26/session-sicherheit-in-php/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 26 Jan 2010 17:25:17 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Proxies]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[SESSID]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[Session-ID]]></category>
		<category><![CDATA[Sessions]]></category>
		<category><![CDATA[Sicherheit]]></category>
		<category><![CDATA[Skript]]></category>
		<category><![CDATA[Snippet]]></category>
		<guid isPermaLink="false">http://www.blackbam.at/blog/?p=468</guid>

					<description><![CDATA[Sorry, this entry is only available in Deutsch.]]></description>
										<content:encoded><![CDATA[<p class="qtranxs-available-languages-message qtranxs-available-languages-message-en">Sorry, this entry is only available in <a href="https://blog.blackbam.at/de/category/web-development/php/feed/" class="qtranxs-available-language-link qtranxs-available-language-link-de" title="Deutsch">Deutsch</a>.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2010%2F01%2F26%2Fsession-sicherheit-in-php%2F&#038;title=Secure%20Sessions%20with%20PHP" data-a2a-url="https://blog.blackbam.at/2010/01/26/session-sicherheit-in-php/" data-a2a-title="Secure Sessions with PHP"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2010/01/26/session-sicherheit-in-php/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
