Fill it!
Fill it!
Fill it!
Fill it!
Fill it!
Fill it!
Fill it!
Fill it!
The ini_set() function allows you to change system attributes(in php.ini file) that affect the way your script is executed. Changes only affect the current script, and will revert back when the script ends. To use ini_set() , pass it the value you want to change as its first parameter, and the new value to use as its second parameter.
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer. Default time out of session in php is 24 minutes and 2 hours in laravel.
Cookies and Sessions are used to store informations. Cookies are only stored on the client-side machine(desktop/laptops/mobiles), while sessions get stored on the client as well as a server side. A session creates a file in a temporary directory on the server where registered session variables and their values are stored and send to client side through a file with the help of cookies.
A RESTful(REpresentational State Transfer) API is an architectural style for an application program interface (API) that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources. One of the key advantages of REST APIs is that they provide a great deal of flexibility. Data is not tied to resources or methods, so REST can handle multiple types of calls, return different data formats and even change structurally with the correct implementation of hypermedia.With the help of Restful API we can deal with any devices to display,update and delete data whout writing multiple version of code for multiple devices.
24 minutes. Each session has a 'timeout' declared in seconds in the PHP. INI as session. gc_maxlifetime. This timeout (default of 24 minutes) is like a clock that is 'restarted' every time a user hits a page that uses a session (session_start()).
Primary key will not accept NULL values whereas Unique key can accept one NULL value. A table can have only primary key whereas there can be multiple unique key on a table. A Clustered index automatically created when a primary key is defined whereas Unique key generates the non-clustered index.
Difference between a GET and POST In GET method, values are visible in the URL. In POST method, values are not visible in the URL. GET has a limitation on the length of the values, generally 255 characters. POST has no limitation on the length of the values since they are submitted via the body of HTTP.
Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
git init
This command turns a directory into an empty Git repository. This is the first step in creating a repository. After running git init, adding and committing files/directories is possible.
Usage:
# change directory to codebase
$ cd /file/path/to/code
# make directory a git repository
$ git init
The error reporting function is a built-in PHP function that allows developers to control which and how many errors will be shown in the application. Remember, the PHP ini configuration has an error_reporting directive that will be set by this function during runtime.
Abstract classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks. An abstract class is a class that contains at least one abstract method. An abstract method is a method that is declared, but not implemented in the code.
Static methods can be called directly - without creating an instance of the class first.
Static methods are declared with the static keyword:
Syntax
A migration class contains two methods: up and down . The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.
Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.
Yes you can do multi-threading in PHP with pthreads From the PHP documentation: pthreads is an object-orientated API that provides all of the tools needed for multi-threading in PHP. PHP applications can create, read, write, execute and synchronize with Threads, Workers and Threaded objects. Warning: The pthreads extension cannot be used in a web server environment. Threading in PHP should therefore remain to CLI-based applications only.
Main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled. This means one cannot be used independent of each other. Also with time, during maintenance adding new features both base as well as derived classes are required to be changed.
Polymorphism is one of the PHP Object Oriented Programming (OOP) features. In general, polymorphism means the ability to have many forms. If we say it in other words, "Polymorphism describes a pattern in Object Oriented Programming in which a class has varying functionality while sharing a common interfaces.".
A stored procedure is a subroutine stored in the database catalog. Applications can call and execute the stored procedure. The CALL SQL statement is used to execute a stored procedure. Stored procedures can have IN , INOUT and OUT parameters, depending on the MySQL version.
PHP - What are Interfaces? Interfaces allow you to specify what methods a class should implement. Interfaces make it easy to use a variety of different classes in the same way. When one or more classes use the same interface, it is referred to as "polymorphism".
this keyword is used inside a class, generally withing the member functions to access non-static members of a class(variables or functions) for the current object. Let's take an example to understand the usage of $this .
OOP stands for Object-Oriented Programming.
Procedural programming is about writing procedures or functions that perform operations on the data, while object-oriented programming is about creating objects that contain both data and functions.
Object-oriented programming has several advantages over procedural programming:
OOP is faster and easier to execute
OOP provides a clear structure for the programs
OOP helps to keep the PHP code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug
OOP makes it possible to create full reusable applications with less code and shorter development time
Tip: The "Don't Repeat Yourself" (DRY) principle is about reducing the repetition of code. You should extract out the codes that are common for the application, and place them at a single place and reuse them instead of repeating it.
Routing in Laravel allows you to route all your application requests to its appropriate controller. The main and primary routes in Laravel acknowledge and accept a URI (Uniform Resource Identifier) along with a closure, given that it should have to be a simple and expressive way of routing.
Route is a way of creating a request URL of your application. These URL do not have to map to specific files on a website. The best thing about these URL is that they are both human readable and SEO friendly. In Laravel 5.5, routes are created inside the routes folder.
The Root Directory. The App Directory. The app directory contains the core code of your application. The Bootstrap Directory. The bootstrap directory contains the app. The Config Directory. The Database Directory. The Public Directory. The Resources Directory. The Tests Directory. The Vendor Directory.
I am familiar with Laravel and CodeIgniter.
4 Years+
Yes, I know. It is based on MVC pattern but having component oriented programming procedures not ORM (Object Realation Mapping) like Laravel.
Sum, avrage, max, min are the aggregate functions in PHP.
An Object is an individual instance of the data structure defined by a class. We define a class once and then make many objects that belong to it. Objects are also known as instances. Object contains properties of classe as well as methods.
Constructor is special type of function which automatically get called when the object is created. Destructor is also special type of function which automatically get called when the object is destroyed. Used to initialize the instance of a class. Used to de-initialize objects already existing to free up memory for new accomodation.
Yes, I know.
Bootstrap 4, JavaScript, JQuery, HTML5, CSS3, NodeJs, AngularJs.
Mysql, Postgres Sql and MongoDB.
echo and print are more or less the same. They are both used to output data to the screen. The differences are very small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. print_r() can be used to display array values(Key & Value) while cho can not be.
We use var_dump() to display values and data-type of a variable at a same time.
Functionally, a for loop is similar to a while loop; it's mean that, each can be rewritten as the other with no change to the outcome or side effects. However, each has different meanings. A while loop runs while a condition holds true; the condition is static, though circumstances change. A for loop runs over a sequence without checking conditions.
Use die() when there is an error and have to stop the execution. e.g. die( 'Oops! Something went wrong' ); Use exit() when there is not an error and have to stop the execution.
Use prepared statements and parameterized queries. These are SQL statements that are sent to and parsed by the database server separately from any parameters. This way it is impossible for an attacker to inject malicious SQL.
You basically have two options to achieve this:
1.)Using PDO (for any supported database driver):
$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
$stmt->execute([ 'name' => $name ]);
foreach ($stmt as $row) {
// Do something with $row
}
2.) Using MySQLi (for MySQL):
$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
$stmt->bind_param('s', $name); // 's' specifies the variable type => 'string'
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
// Do something with $row
}
Option-1:
The easiest and safest way to check whether an email address is well-formed is to use PHP's filter_var() function.
In the code below, if the e-mail address is not well-formed, then store an error message:
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
Option-2:
The code below shows a simple way to check if the name field only contains letters, dashes, apostrophes and whitespaces. If the value of the name field is not valid, then store an error message:
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
Note: The preg_match() function searches a string for pattern, returning true if the pattern exists, and false otherwise.
An HTML form contains various input fields such as text box, checkbox, radio buttons, submit button, and checklist, etc. These input fields need to be validated, which ensures that the user has entered information in all the required fields and also validates that the information provided by the user is valid and correct.
There is no guarantee that the information provided by the user is always correct. PHP validates the data at the server-side, which is submitted by HTML form. You need to validate a few things:
Empty String
Validate String
Validate Numbers
Validate Email
Validate URL
Input length
When you consider all the possible attacks that you are likely to come under when running a successful web site, the most feared attack is denial of service - when a hacker, or potentially a group of hackers, conspire to stop your web site from working as intended. It may well be that this involves taking your database server offline, making your whole web site run slow, or, worse, taking your web site offline entirely.
There are three methods of denial of service (DoS), of which two are essentially the same:
A malicious user with a fast Internet connection bombards your web server with requests, thereby overloading it
A malicious user with accomplices, who may be unwitting, bombard your web server with requests, thereby overloading it. In this situation, the attackers do not need fast Internet connections - 100 requests from 10,000 people are as damaging as 1,000,000 requests from one person.
A malicious user finds a hole in your web site that forces your server to perform an inordinate amount of work, thereby overloading the server.
Of the three, the first two are impossible to defend against - the world's largest sites have been taken offline by this form of denial of service, and there is nothing you can do irrespective of whether you are using PHP.
The last option, however, is something you can guard against. If you have holes in your code that can be exploited by outsiders to cause your web server to chew up 99% of your CPU time, you are in trouble.
A popular mistake is to write code that results in URLs like this:
www.example.com/article.php?file=aboutus.php
www.example.com/article.php?file=products.php
www.example.com/article.php?file=legal.php
The code for article.php will read in the $_GET['file'] variable, then include() the necessary file into the script. This might make sense at first, but consider what happens if a clever use modified the URL to this:
www.example.com/article.php?file=article.php
What will happen is that article.php will load, then include()article.php, which will load, then include()article.php, which will load, then... and so on. This will continue going on and on until your server hits the maximum execution time for a script and terminates. However, during this time your web server will be performing large amounts of unnecessary work, and will be slower for other clients connecting to it.
Now consider what would happen if that same malicious user loaded that URL three times quickly - or thirty. From that, consider what would happen if that user loaded the URL three thousand times - nothing difficult, considering that can be handled even with a slow connection. At three thousand almost-simultaneous connections, even a normal web server would have trouble coping. However, if each of those three thousand resulted in a CPU-consuming infinite include() loop, the server would simply stop responding to new requests and may well even crash.
Author's Note: if you are think three thousand pages is too much for just one client to handle, think again - HTTP has a special access method called "HEAD" that sends a request to the server, makes the server process the page fully, then returns only the header information of the page - this is usually only around 100 bytes. Three thousand times 100 bytes is three hundred thousand bytes, or 300 kilobytes - well within the reach of even lowly modem users.
The moral of the story is that you should always keep in mind the possibility that malicious users may use your own code against you. The most obvious solution to the problem detailed here is not include files based upon a variable, but if that is not possible then at least consider using include_once() to stop the recursion.
SOURCE: Denial of Service Attacks
URI(Unifrom Resource Identifier) = URL(Uniform Resource Locatior) + URN(Uniform Resource Name) .
Reverse routing is the process of generating the URL that would lead to a route, given a symbolic reference to the route (could be name of the route/view/controller or a reference to the controller, depending on the framework).
Fill it!
Yes, I know.
Yes, I know.
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
The Laravel PHP artisan serve command helps running applications on the PHP development server. As a developer, you can use Laravel artisan serve to develop and test various functions within the application. It also accepts two additional options. You can use the host for changing application's address and port.
Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen.
Fill it!
Controllers are meant to group associated request handling logic within a single class. In your Laravel project, they are stored in the app/Http/Controllers' directory. The full form of MVC is Model View Controller, which act as directing traffic among the Views and the Models.
To include multiple view file in a view file.
Views hold the presentation logic of a Laravel application. It is served separately from the application logic using laravel's blade templating engine. Passing data from a controller to a view is as simple as declaring a variable and adding it as a parameter to the returned view helper method.
Each database table has a corresponding "Model" which is used to interact with that table.
In computing, a namespace is a set of signs that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces are commonly structured as hierarchies to allow reuse of names in different contexts. In PHP Namespaces are qualifiers that solve two different problems: They allow for better organization by grouping classes that work together to perform a task. They allow the same name to be used for more than one class.
Model–view–controller is a software design pattern commonly used for developing user interfaces that divides the related program logic into three interconnected elements. This is done to separate internal representations of information from the ways information is presented to and accepted from the user. In PHP MVC is an application design pattern that separates the application data and business logic (model) from the presentation (view). MVC stands for Model, View & Controller. The controller mediates between the models and views. Think of the MVC design pattern as a car and the driver.
Codeigniter is Object-oriented whereas Laravel is relational Object-Oriented. Codeigniter doesn't come with built-in authentication features whereas Laravel comes with authentication class features. Codeigniter doesn't have an inbuilt Unit testing tool while Laravel has an inbuilt Unit testing tool.
Writing CSS After installing the laravel/ui Composer package and generating the frontend scaffolding, Laravel's package. json file will include the bootstrap package to help you get started prototyping your application's frontend using Bootstrap. However, feel free to add or remove packages from the package.
Fill it!
Route groups allow you to group several routes together, and apply any shared once to the entire group, to reduce this duplication.
Routing rules are defined in your application/config/routes.php file. In it you'll see an array called $route that permits you to specify your own routing criteria.
The make method accepts the name of the class or interface you wish to resolve: $api = $this->app->make('HelpSpot\API'); One advantage to using the make method, is that Laravel will automatically inject any dependencies the class may define in it's constructor.
Fill it!
This is a great feature for when you run a migration, and then you need you need to rollback or revert the last one instead of the whole batch.
The term Web service (WS) is either: a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web, or a server running on a computer device, listening for requests at a particular port over a network, serving web documents (HTML, JSON, XML, images), and creating[clarification needed] web applications services, which serve in solving specific domain problems over the Web (WWW, Internet, HTTP) In a Web service a Web technology such as HTTP is used for transferring machine-readable file formats such as XML and JSON. In practice, a web service commonly provides an object-oriented Web-based interface to a database server, utilized for example by another Web server, or by a mobile app, that provides a user interface to the end-user. Many organizations that provide data in formatted HTML pages will also provide that data on their server as XML or JSON, often through a Web service to allow syndication, for example, Wikipedia's Export. Another application offered to the end-user may be a mashup, where a Web server consumes several Web services at different machines and compiles the content into one user interface.
Steps-1: Installing Composer.
Get Composer
Step-2: Installing laravel Via Composer Create-Project.
Open cmd and run: composer create-project --prefer-dist laravel/laravel blog
Step-3: Check installation:
run in cmd: php artisan serve
laravel development server started on http://localhost:8000/
Step-4: That's it.
folders:-->
app
bootstrap
config
database
public
resources
storage
tests
vendor
files:-->
.env
.env.example
.gitignore
artisan
composer.json
composer.lock
env-original
gulpfile
package.json
phpunit
readme.md
server
> php artisan make:model Models/users
After making model , it can be found under folder:
app/Models/users.php
> php artisan make:migration create_tasks_table --create=tasks
After making migrations , it can be found under folder:
/database/migrations folder
> Eloquent is Laravel’s ORM which provides simple Active-record Implementation for working with database. Each Database table can have corresponding Eloquent model. Eloquent Model represents database entities and can be used to query data as well as insert and update data to the tables. So, let’s make a model for our tasks table using make:model command.
php artisan make:model Task
After making migrations , it can be found under folder:
app/Models folder
Relationships are used to connect tables. Eloquent provides way to connect their models through eloquent relationships. One-to-many relationship means when one model owns multiple amounts of another model.For our example: single user can have many tasks thus one-to-many relationship exists between User table and Task Table. It's very easy to define and use Eloquent relationship and the benefit is, you don’t have to run query at all. Eloquent will bind the models so you will have to only use functions.
Let’s edit Task Model and User Model to create Eloquent Relationship:
Task Model (task.php found in app/task.php):
use App\Models\User;
class Task extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
}
Laravel provides a command-line interface known as Artisan. Artisan contains various commands and among them, we will now discuss about Tinker. Tinker allows you to interact with your entire Laravel application through console window without the need of accessing web interface. Major benefit of tinker is you can test relationships, debug data and access Eloquent ORM, jobs, tests, events etc. So we will also be using Tinker in our laravel tutorial. Let’s say you registered to the app and created two tasks. Now you check those tasks directly in the console window as below:
$ php artisan tinker
>App\User::first()->tasks;
Tinker directly access database so this is a great tool for testing functions as well as the data.
Controllers are used to direct traffic between views and models and they can group multiple request handling logic into a single class. Thus, generally they receive all the request and based on their logic, they redirect or return respective data. In our example, now we are moving towards front-end, thus we should make controllers through which we can handle requests coming to our application. Execute below command to create controller for tasks:
php artisan make:controller TasksController
This will create TasksController and you can find that in app/Http/Controllers directory.
Routing means to accept the request and redirect it to appropriate function. Our app needs five routes which will do following:
Login
Register
Display list of all our tasks
Add new tasks
Delete existing tasks
Login and register are added by Laravel Jetstream so now we need to take care of only three routes.
Laravel provides various route files inside '/routes' folder for various use cases. For example: routing configuration for API will go in '/routes/api.php' file while routing configuration for our regular web application will go in '/routes/web.php'.
Now, let’s edit web.php. Below is the edited version of file. Make changes accordingly:
Hello! I also encountered this problem before. Please check your Apache's httpd.conf file. Make sure that you enabled the LoadModule rewrite_module modules/mod_rewrite.so by removing the # from the start line of the code.
And also change inside the httpd.conf from Require all denied to Require all granted, AllowOverride All, and Options Indexes FollowSymLinks
Follow: https://laracasts.com/discuss/channels/laravel/route-not-working-1 route-not-working