Frontend Development for Web Pages
- PHP is server side back end scripting language.
- PHP is an acronym for “PHP: Hypertext Preprocessor”
- PHP is a widely-used, open source scripting language
- PHP scripts are executed on the server
Bootstrap
Bootstrap is a robust and comprehensive UI library for developing responsive and mobile-first websites and apps. Here are some advantages of using Bootstrap as the styling framework for a WordPress theme.
- hundreds of JavaScript/jQuery plugins already integrated with Bootstrap.
Envato
You can buy, prepared themes over ENVATO, build your website with CHEAP and good themes. You can pay just 50 $ to get very good theme and support.
Server Installation and Development Enviroment
- Install PHP to Centos 7.9 With All Extensions (Apache, Ngins, Psql,Mysql, Redis, Memcache, unit Test )
- Professional Development Server Installation
Database driven sites
You can use libraries those are already written for PHP to manage MYSQL and other databases. But you can also use native php functions to access database. You can search at “composer“.
Mysql
1 2 |
// Create connection $conn = mysqli_connect($servername, $username, $password); |
MySQL is the most popular database system used with PHP. Mysql is tunable easily by developers. Performance is well enough for simple php sites.
For the projects, you can easily get backup of the mysql with php. It is very easy to get data from mysql. Very clean to code it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/// $sql = "SELECT id FROM kz_table"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. "<br>"; } } else { echo "0 results"; } $conn->close(); // Do not forget to close ! tooo many open connection errors occurs. /// |
Mysql ist fast. Easy to manage, but you can have inno db problems sometimes. DB crashes occurs. PhpMyadmin and SQL Dumpers are favorite Backup and management tools.
Postgresql
Postgresql is an alternative to MYSQL, if you want more and more stability and some better advantages that you need and not available at MYSQL side.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // Connecting, selecting database $dbconn = pg_connect("host=kz_SERVER dbname=kz_db user=www password=foo") or die('Could not connect: ' . pg_last_error()); // Performing SQL query $query = 'SELECT * FROM kztable'; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); // Printing results in HTML echo "<table>\n"; while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset pg_free_result($result); // |
Mysql is faster BUT Postgresql handles the Concurrency better, and heavy inserts more stable processed.
Php and Type Conversion (Sql, Data, Json, Binary, Hex ..)
Cassandra
Cassandra is Nosql DATABASE. It is distributed and you can set the data replication factors and multi datacenter avalibilities.
You can download the drive here. https://github.com/datastax/php-driver
Service Based PHP
Services are very important to create activities with 3rd parties. Your scripts can access the data from 3rd parties or can send data to them. For stability , realibility, and avalibility services are also used. You can create back-end servers to create services and your php front-end can access these servers to access data requests and responses. If you have billions of requests you can do load balancing.
OAUTH – and V2
Oauth very important to access user data from 3rd parties. Such as If a user trying to register a web page over FACEBOOK, OAUTH can transfer the user data to the web page that user trying to register. Tokens or other mechanism used for validation exchanges.
Here are the some important methods of the OAUTH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// public disableRedirects ( void ) : bool public disableSSLChecks ( void ) : bool public enableDebug ( void ) : bool public enableRedirects ( void ) : bool public enableSSLChecks ( void ) : bool public fetch ( string $protected_resource_url [, array $extra_parameters [, string $http_method [, array $http_headers ]]] ) : mixed public generateSignature ( string $http_method , string $url [, mixed $extra_parameters ] ) : string public getAccessToken ( string $access_token_url [, string $auth_session_handle [, string $verifier_token [, string $http_method ]]] ) : array public getCAPath ( void ) : array public getLastResponse ( void ) : string public getLastResponseHeaders ( void ) : string public getLastResponseInfo ( void ) : array public getRequestHeader ( string $http_method , string $url [, mixed $extra_parameters ] ) : string public getRequestToken ( string $request_token_url [, string $callback_url [, string $http_method ]] ) : array public setAuthType ( int $auth_type ) : bool public setCAPath ([ string $ca_path [, string $ca_info ]] ) : mixed public setNonce ( string $nonce ) : mixed public setRequestEngine ( int $reqengine ) : void public setRSACertificate ( string $cert ) : mixed public setSSLChecks ( int $sslcheck ) : bool public setTimestamp ( string $timestamp ) : mixed public setToken ( string $token , string $token_secret ) : bool public setVersion ( string $version ) : bool // |
As you see above, it is saying, Disable redirects or get Last response, Auth type, Request tokens. Imagine that; You have 100 users trying to do outh in the same time. A lot of time saving for clients!.
REST (REST or Representational State Transfer )
The objective is to build a RESTful web service in PHP to provide resource data based on the request with the network call by the external clients.
- Create request URI with patterns that follow REST principles.
- Make the RESTful service to be capable of responding to the requests in JSON, XML, HTML formats.
- Demonstrate the use of HTTP Status code based on different scenarios.
- Demonstrate the use of Request Headers.
- Test the RESTful web service using a REST client.
RESTful-Style | RPC-Style | |
---|---|---|
Request URI | The request URI will differ based on the resource. | Same URI for all resources. |
Request methods | The service request parameters can be sent via GET, PUT, POST request methods. | Supports only the POST method. |
Service methods or handlers | Same method for all resources. | Methods and params are posted on request. |
Target on | The service request using this style targets resources. | The target is methods. |
Response data transmission | Over HTTP | wrapped with the requested methods and params. |
An alternative to REST, FACEBOOKS graphQL.
RPC is mostly related with actions.
SOAP
SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among computers. SOAP is an application of the XML specification.
- SOAP is easy to handle for security. Security at Rest little bit complex if you would like to do it.
- SOAP using RPC(Remote Process Call) method. SOAP contains WS-* like security protocols, SOAP memorize the state information at requests and responses.
- REST can work with JSON, XML and TEXT, SOAP should use XML. REST is more usefull in this case.
- Data sizes are more smaller at REST, Traffic is lower, in this case REST is better.
- For the performance, you should choose the REST.
- REST using HTTP methods. GET,POST,PUT,DELETE etc.
- REST is more easy to integrate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
POST /PHP_Kutayzorlu_com HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.example.org"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice> <m:StockName>T</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope> |
Php Package management
composer Example loading php libraries. (require ‘vendor/autoload.php’;)
1 2 3 4 5 6 7 8 9 10 |
<?php require 'vendor/autoload.php'; use Dotenv\Dotenv; use Src\System\DatabaseConnector; $dotenv = new DotEnv(__DIR__); $dotenv->load(); $dbConnection = (new DatabaseConnector())->getConnection(); |
Session
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Session Abort # session_abort(): bool session_abort() # veriyi kaydetmeden oturumu bitirir. Böylece oturum verisindeki ozgün değerler korunur. // Başarı durumunda true, başarısızlık durumunda false döner. <?php session_start(); $_SESSION['country']="Australia"; echo session_encode(); session_abort(); session_start(); echo "<br>".session_encode(); ?> when session_abort is executed , the session is closed and the change which here is the 'country' element of Session array is discarded . Output : city|s:6:"Sydney";country|s:9:"Australia"; city|s:6:"Sydney"; Session Status : session_status(); PHP_SESSION_DISABLED, wenn Sessions deaktiviert sind. PHP_SESSION_NONE, wenn Sessions aktiviert sind, aber keine existiert. PHP_SESSION_ACTIVE, wenn Sessions aktiviert sind und eine existiert. session_start() # Without start you can not access the, $_SESSION object. it will return null. Session reads itself from file. session_unset — Free all session variables session_write_close — Oturum verisini yazıp oturumu kapatır Ref: https://www.php.net/manual/tr/book.session.php |
Document Management
For generation of the office documents and BI reports.
PHPOffice / PHPWord (Word and Office documents)
You can create office documents with this library. PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft Office Open XML (OOXML or OpenXML), OASIS Open Document Format for Office Applications (OpenDocument or ODF), Rich Text Format (RTF), HTML, and PDF.
For the Excel https://github.com/PHPOffice/PHPExcel
PDF Generation for Customers / FPDF
There are also other alternative PDF libraries are available, But here is most easiest one.
1 2 3 4 5 6 7 8 9 |
<?php require('fpdf.php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); ?> |
XML – XSLT – XSD validations
For the some of the backend services you need to validate the XML.
1 2 |
public DOMDocument::schemaValidate ( string $filename [, int $flags = 0 ] ) : bool |
Frameworks
Every developer can write own Framework. I have my own framework for E-Commerce / Crm systems
kcrm
Kcrm is private framework developed by Kutay ZORLU to FAST build CRM front-end applications. Advantages
- Built in REST services for Customer DATA
- Automatic Back-End failure detection and finding next Backend for Transactions
- Streaming Libraries impletemented, Data download, Data Stream, Data Upload
- Perfect design for CRM / ERP System coding.
- Invocing API implemented
- Usufull with multiple Data resources
- You can use, Mysql, REdis, Postgresql, Cassandra, and REST in the same time !
- FAST. Not loading toooo many libraries. Its using only what it needs.
- Caching library implemented.
- …. more and more.
Smarty
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. This implies that PHP code is application logic, and is separated from the presentation.
Here is the sample Description : https://www.smarty.net/sampleapp1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PHP <?php $counter=0; ?> <?php foreach($foo as $bar): ?> <?php if(($counter+1) % 4 == 0): ?> </tr><tr> <?php endif; ?> <td><?php echo $bar; ?></td> <?php $counter++; ?> <?php endforeach; ?> Smarty {foreach $foo as $bar} {if $bar@iteration is div by 4} </tr><tr> {/if} <td>{$bar}</td> {/foreach} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
header.tpl <html> <head> <title>{$title|default:"no title"}</title> </head> <body> footer.tpl </body> </html> index.tpl {include file="header.tpl" title="Info"} User Information:<p> Name: {$name|capitalize}<br> Address: {$address|escape}<br> {include file="footer.tpl"} output <html> <head> <title>Info</title> </head> <body> User Information:<p> Name: George Smith<br> Address: 45th & Harris<br> </body> </html> |
Laravel
1 |
composer global require "laravel/installer=~1.1" |
1 2 3 4 5 |
Typically, you may use a web server such as Apache or Nginx to serve your Laravel applications. php artisan serve php artisan serve --port=8080 |
1 2 3 4 5 6 7 8 9 |
To get started, let's create our first route. In Laravel, the simplest route is a route to a Closure. Pop open the app/routes.php file and add the following route to the bottom of the file: Route::get('users', function() { return 'Users!'; }); |
Example Mongo DB usage with Laravel composer require jenssegers/mongodb
Laravel Side Config/database.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
'mongodb' => [ 'driver' => 'mongodb', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', 27017), 'database' => env('DB_DATABASE', 'homestead'), 'username' => env('DB_USERNAME', 'homestead'), 'password' => env('DB_PASSWORD', 'secret'), 'options' => [ // here you can pass more settings to the Mongo Driver Manager // see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use 'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+ ], ], |
Phalcon
Phalcon is an open source full stack framework for PHP, written as a C-extension. Phalcon is optimized for high performance. Its unique architecture allows the framework to always be memory resident, offering its functionality whenever it’s needed, without expensive file stats and file reads that traditional PHP frameworks employ.Phalcon is an open source full stack framework for PHP, written as a C-extension. Phalcon is optimized for high performance. Its unique architecture allows the framework to always be memory resident, offering its functionality whenever it’s needed, without expensive file stats and file reads that traditional PHP frameworks employ. ref 1 ö g g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
Resolving the application’s HTTP requests Autoloader We are going to use Phalcon\Loader a PSR-4 compliant file loader. Common things that should be added to the autoloader are your controllers and models. You can also register directories which will be scanned for files required by the application. To start, lets register our app’s controllers and models directories using Phalcon\Loader: public/index.php <?php use Phalcon\Loader; define('BASE_PATH', dirname(__DIR__)); define('APP_PATH', BASE_PATH . '/app'); // ... $loader = new Loader(); $loader->registerDirs( [ APP_PATH . '/controllers/', APP_PATH . '/models/', ] ); $loader->register(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
By default Phalcon will look for a controller named IndexController. It is the starting point when no controller or action has been added in the request (eg. https://localhost/). An IndexController and its IndexAction should resemble the following example: app/controllers/IndexController.php <?php use Phalcon\Mvc\Controller; class IndexController extends Controller { public function indexAction() { return '<h1>KUTAY !!! !</h1>'; } } |
PHP – C++
C++ Implementation of the PHP. You are writing C++ Codes then compling, after that, you need to call it from PHP. Fastest way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <phpcpp.h> #include <iostream> void myFunction() { Php::out << "example output" << std::endl; } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension extension("my_extension", "1.0"); extension.add<myFunction>("myFunction"); return extension; } } |
1 2 3 |
<?php for ($i=0; $i<10; $i++) echo(myFunction()."\n"); ?> |
http://www.php-cpp.com/documentation/functions
http://www.php-cpp.com/documentation/your-first-extension
E-Commerce Systems
- XT-Commerce
- JTL WAVI – Web Service Development + XT- Commerce
- WordPress
- Gambio Installation
- Magento
- Modified E-Commerce
- B2B-E-Commerce
Code Guide Lines (richtlinien)
Object Oriented PHP
OOP is very important if your project becomes bigger and more complex. Clean programming and management of the classes are becoming very hard to handle. Composer is one of the best helper for php developers.
Modal view controller
Most important think for Development. MVC in PHP
Development with Source Code Controlling
- GIT
ALL RIGHTS RESERVED
KUTAY ZORLU