How to make a cookie secure and httponly in PHP ?

As we know Cookie is often used for identifying user data, when user opening a website, cookie stores information about the user in the browser, Each time the same system requests a page with in a same browser, it will send the cookie too.So when we are considering about the security it is a programmer duty to make it more secure when it exchanging between browser and server,nowadays it is easy to access other website cookie and get the flow of the website using that cookie information.So here am going explain you how to make a cookie secure and httponly in PHP .we have lot of method to accomplish this task,lets have a look on it.

Method 1

Make cookie secure using PHP.ini 

if you have the permission to access php.ini you can open and add below code at the end of php.ini to make your cookie secure and httponly

session.cookie_httponly=On
session.cookie_secure=On

Method 2

if you don't have the permission to access php.ini file,fortunately we have another method to accomplish this, which can be done by one of the most common function ini_set();


Make cookie secure using ini_set() function

add below ini_set() functions in the top of your home page

ini_set('session.cookie_httponly',1);
ini_set('session.use_only_cookies',1);
ini_set('session.cookie_secure', 1);

Method 3

if you don't have the permission to access php.ini file,fortunately we have another method to accomplish this,which can be done by one of the most common function header() in php


Make cookie secure using header() function

add below header() functions in the top of your home page

header("Set-Cookie: key=value; path=/; domain=www.tutorialshore.com; HttpOnly; Secure; SameSite=Strict");

See how we can check a cookie is secure and httponly, we can do with the help of chrome browser as we know almost every browser have the inspect element option, within inspect element tab we have the application section to check cookie see below image.
Click F12 function button go for application => cookies

make a cookie secure and httponly in PHP

Redirect any subdirectory to another subdirectory using htaccess in wordpress

In our blog sometimes for SEO purpose we need to rename the folder name from one directory to another directory suppose we need to rename my folder name style to trends.we need to redirect all url related to https://www.tutorialshore.com/style/***** to https://www.tutorialshore.com/trends/*****.This can be done by using htaccess redirection .here am going to do in wordpress

RewriteRule ^style/(.*)$ /trends/$1 [R=301,NC,L]
#Here all style folder redirect to trends

Full .htaccess files in wordpress


RewriteEngine On
RewriteRule ^style/(.*)$ /trends/$1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  


how to create new database user in mysql python

Step1

Set Mysql variable path

set path=%PATH%;C:\xampp\mysql\bin;

Step 2
Using command prompt login to databse

mysql -u root -p

Password NULL
create a database python

Step 3
Create new username and password
jack username
jackpassword is the password

c:\python>mysql -u root -p
Enter password: *
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.1.34-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'jack'@'localhost' IDENTIFIED BY 'jackpassword';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

Step 4
create new database using Python mysql connection

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="jack",
  passwd="jackpassword"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE myschool")

For Loop Syntax in Python

For Loop in Python

The for loop that is used is python,whenever we need repetition or iterate over a sequence .For Loop is one the frequently using loop in python.For loop has simple syntax .Let see the for loop syntax in details.

Here we are going to iterate over a sequence


#For Loop Syntax in Python

cars = ["SWIFT", "BELANO", "BMW"]
for x in cars:
  print(x) 

Output

SWIFT
BELANO
BMW