The document provides an overview of accessing and using MySQL with PHP. It discusses MySQL database structure and syntax, common MySQL commands, data types in MySQL, and how PHP fits with MySQL. It also covers topics like connecting to a MySQL database with PHP, creating and manipulating database tables, inserting and retrieving data, and maintaining state with cookies and sessions.
A presentation about MySQL for beginners. It includes the following topics:
- Introduction
- Installation
- Executing SQL statements
- SQL Language Syntax
- The most important SQL commands
- MySQL Data Types
- Operators
- Basic Syntax
- SQL Joins
- Some Exercise
BITS: Introduction to relational databases and MySQL - Schema designBITS
BITS training: Introduction to relational databases and MySQL - Module 3: Schema design.
See http://www.bits.vib.be/index.php?option=com_content&view=article&id=17204047:green-basics-of-databases&catid=81:training-pages&Itemid=190
A presentation about MySQL for beginners. It includes the following topics:
- Introduction
- Installation
- Executing SQL statements
- SQL Language Syntax
- The most important SQL commands
- MySQL Data Types
- Operators
- Basic Syntax
- SQL Joins
- Some Exercise
BITS: Introduction to relational databases and MySQL - Schema designBITS
BITS training: Introduction to relational databases and MySQL - Module 3: Schema design.
See http://www.bits.vib.be/index.php?option=com_content&view=article&id=17204047:green-basics-of-databases&catid=81:training-pages&Itemid=190
BITS: Introduction to relational databases and MySQL - SQLBITS
BITS: Introduction to relational databases and MySQL - Module2: Structured query language
See http://www.bits.vib.be/index.php?option=com_content&view=article&id=17204047:green-basics-of-databases&catid=81:training-pages&Itemid=190
CakePHP 3 comes with a new ORM. This talk starts with a short history of how this library came to be and then walk through a series of examples from beginner to advanced for using the Querying features of the ORM.
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
This talk will teach you how to use Slick in practice, based on our experience at EatingWell Media Group. Slick is a totally different (and better!) relational database mapping tool that brings Scala’s powerful features to your database interactions, namely: static-checking, compile-time safety, and compositionality.
Here at EatingWell, we have learned quite a bit about Slick over the past two years as we transitioned from a PHP website to Scala. I will share with you tips and tricks we have learned, as well as everything you need to get started using Slick in your Scala application.
I will begin with Slick fundamentals: how to get started making your connection, the types of databases it can access, how to actually create table objects and make queries to and from them. We will using these fundamentals to demonstrate the powerful features inherited from the Scala language itself: static-checking, compile-time safety, and compositionality. And throughout I will share plenty of tips that will help you in everything from getting started to connection pooling options and configuration for use at scale.
Talk was presented at PGConfUS on April 20th, 2016.
___________
With features like foreign data wrappers, Postgres makes it easy for you to integrate rich data stores into your application architectures. Yet sometimes you only have a few rich data structures to deal with, or can’t afford the time and resource cost of running a NoSQL cluster alongside Postgres. Happily Postgres natively supports several document data formats, giving you the best of both worlds in one database. You can keep document oriented data solely within Postgres, or write a foreign table schema that’s naturally compatible with your document database.
At this talk you’ll learn how to access document data stored in Postgres, and write Ruby code to make use of the data with your favorite ORM. We’ll survey the various document stores which are natively supported in Postgres. You’ll learn what are the pros and cons of each data type, and come away understanding which use cases are best suited to each document store.
BITS: Introduction to relational databases and MySQL - SQLBITS
BITS: Introduction to relational databases and MySQL - Module2: Structured query language
See http://www.bits.vib.be/index.php?option=com_content&view=article&id=17204047:green-basics-of-databases&catid=81:training-pages&Itemid=190
CakePHP 3 comes with a new ORM. This talk starts with a short history of how this library came to be and then walk through a series of examples from beginner to advanced for using the Querying features of the ORM.
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
This talk will teach you how to use Slick in practice, based on our experience at EatingWell Media Group. Slick is a totally different (and better!) relational database mapping tool that brings Scala’s powerful features to your database interactions, namely: static-checking, compile-time safety, and compositionality.
Here at EatingWell, we have learned quite a bit about Slick over the past two years as we transitioned from a PHP website to Scala. I will share with you tips and tricks we have learned, as well as everything you need to get started using Slick in your Scala application.
I will begin with Slick fundamentals: how to get started making your connection, the types of databases it can access, how to actually create table objects and make queries to and from them. We will using these fundamentals to demonstrate the powerful features inherited from the Scala language itself: static-checking, compile-time safety, and compositionality. And throughout I will share plenty of tips that will help you in everything from getting started to connection pooling options and configuration for use at scale.
Talk was presented at PGConfUS on April 20th, 2016.
___________
With features like foreign data wrappers, Postgres makes it easy for you to integrate rich data stores into your application architectures. Yet sometimes you only have a few rich data structures to deal with, or can’t afford the time and resource cost of running a NoSQL cluster alongside Postgres. Happily Postgres natively supports several document data formats, giving you the best of both worlds in one database. You can keep document oriented data solely within Postgres, or write a foreign table schema that’s naturally compatible with your document database.
At this talk you’ll learn how to access document data stored in Postgres, and write Ruby code to make use of the data with your favorite ORM. We’ll survey the various document stores which are natively supported in Postgres. You’ll learn what are the pros and cons of each data type, and come away understanding which use cases are best suited to each document store.
What is PHP?
PHP stands for "PHP Hypertext Preprocessor”
An embedded scripting language for HTML like ASP or JSP
A language that combines elements of Perl, C, and Java
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...Neo4j
Leonard Jayamohan, Partner & Generative AI Lead, Deloitte
This keynote will reveal how Deloitte leverages Neo4j’s graph power for groundbreaking digital twin solutions, achieving a staggering 100x performance boost. Discover the essential role knowledge graphs play in successful generative AI implementations. Plus, get an exclusive look at an innovative Neo4j + Generative AI solution Deloitte is developing in-house.
UiPath Test Automation using UiPath Test Suite series, part 6DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 6. In this session, we will cover Test Automation with generative AI and Open AI.
UiPath Test Automation with generative AI and Open AI webinar offers an in-depth exploration of leveraging cutting-edge technologies for test automation within the UiPath platform. Attendees will delve into the integration of generative AI, a test automation solution, with Open AI advanced natural language processing capabilities.
Throughout the session, participants will discover how this synergy empowers testers to automate repetitive tasks, enhance testing accuracy, and expedite the software testing life cycle. Topics covered include the seamless integration process, practical use cases, and the benefits of harnessing AI-driven automation for UiPath testing initiatives. By attending this webinar, testers, and automation professionals can gain valuable insights into harnessing the power of AI to optimize their test automation workflows within the UiPath ecosystem, ultimately driving efficiency and quality in software development processes.
What will you get from this session?
1. Insights into integrating generative AI.
2. Understanding how this integration enhances test automation within the UiPath platform
3. Practical demonstrations
4. Exploration of real-world use cases illustrating the benefits of AI-driven test automation for UiPath
Topics covered:
What is generative AI
Test Automation with generative AI and Open AI.
UiPath integration with generative AI
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIVladimir Iglovikov, Ph.D.
Presented by Vladimir Iglovikov:
- https://www.linkedin.com/in/iglovikov/
- https://x.com/viglovikov
- https://www.instagram.com/ternaus/
This presentation delves into the journey of Albumentations.ai, a highly successful open-source library for data augmentation.
Created out of a necessity for superior performance in Kaggle competitions, Albumentations has grown to become a widely used tool among data scientists and machine learning practitioners.
This case study covers various aspects, including:
People: The contributors and community that have supported Albumentations.
Metrics: The success indicators such as downloads, daily active users, GitHub stars, and financial contributions.
Challenges: The hurdles in monetizing open-source projects and measuring user engagement.
Development Practices: Best practices for creating, maintaining, and scaling open-source libraries, including code hygiene, CI/CD, and fast iteration.
Community Building: Strategies for making adoption easy, iterating quickly, and fostering a vibrant, engaged community.
Marketing: Both online and offline marketing tactics, focusing on real, impactful interactions and collaborations.
Mental Health: Maintaining balance and not feeling pressured by user demands.
Key insights include the importance of automation, making the adoption process seamless, and leveraging offline interactions for marketing. The presentation also emphasizes the need for continuous small improvements and building a friendly, inclusive community that contributes to the project's growth.
Vladimir Iglovikov brings his extensive experience as a Kaggle Grandmaster, ex-Staff ML Engineer at Lyft, sharing valuable lessons and practical advice for anyone looking to enhance the adoption of their open-source projects.
Explore more about Albumentations and join the community at:
GitHub: https://github.com/albumentations-team/albumentations
Website: https://albumentations.ai/
LinkedIn: https://www.linkedin.com/company/100504475
Twitter: https://x.com/albumentations
In the rapidly evolving landscape of technologies, XML continues to play a vital role in structuring, storing, and transporting data across diverse systems. The recent advancements in artificial intelligence (AI) present new methodologies for enhancing XML development workflows, introducing efficiency, automation, and intelligent capabilities. This presentation will outline the scope and perspective of utilizing AI in XML development. The potential benefits and the possible pitfalls will be highlighted, providing a balanced view of the subject.
We will explore the capabilities of AI in understanding XML markup languages and autonomously creating structured XML content. Additionally, we will examine the capacity of AI to enrich plain text with appropriate XML markup. Practical examples and methodological guidelines will be provided to elucidate how AI can be effectively prompted to interpret and generate accurate XML markup.
Further emphasis will be placed on the role of AI in developing XSLT, or schemas such as XSD and Schematron. We will address the techniques and strategies adopted to create prompts for generating code, explaining code, or refactoring the code, and the results achieved.
The discussion will extend to how AI can be used to transform XML content. In particular, the focus will be on the use of AI XPath extension functions in XSLT, Schematron, Schematron Quick Fixes, or for XML content refactoring.
The presentation aims to deliver a comprehensive overview of AI usage in XML development, providing attendees with the necessary knowledge to make informed decisions. Whether you’re at the early stages of adopting AI or considering integrating it in advanced XML development, this presentation will cover all levels of expertise.
By highlighting the potential advantages and challenges of integrating AI with XML development tools and languages, the presentation seeks to inspire thoughtful conversation around the future of XML development. We’ll not only delve into the technical aspects of AI-powered XML development but also discuss practical implications and possible future directions.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
2. Overview of My SQL Structure and
Syntax
Databases are stores of information.
MySQL is an open-source database that can be used for web
applications.
The only requirement is that, you need to have a server at your
disposal where you can install MySQL.
Types of Storage Engines
◦ MyISAM (Indexed Sequential Access Method)
◦ MERGE
◦ MEMORY
◦ InnoDB
◦ BDB (BerkeleyDB )
3. My SQL Syntax and
Commands
Common commands
◦ CREATE : Creates new databases and tables
◦ ALTER : Modifies existing tables
◦ SELECT : Chooses the data you want
◦ DELETE : Erases the data from your table
◦ DESCRIBE : Lets you know the structure and
specifics of the table
◦ INSERT INTO table name VALUES : Puts values
into the table
◦ UPDATE : Lets you modify data already in a table
◦ DROP : Deletes an entire table or database
4. Data Type in
MySQL Text Types
◦ char(size)
It is used to store no. of character and it is in fixed length.
◦ varchar(size)
It is used to store alphanumeric data of variable length.
◦ blob
It is binary large object which can hold variable amount of business data
◦ Binary and Varbinary
These 2 type are similar to char and varchar except that they hold
binary string rather than ascii string
Number Types
◦ int(size)
It is used to store integer type of data.
It divide in to 5 segment int, tiny int, small int, medium int,big int
◦ Float(size,precision)
It is allow to store decimal numbers with specific precision.
◦ Double(size,precision)
It is allow to store large floating decmial point value.
5. Date
◦ Hold the date value
◦ Range between 1000-01-01 to 9999-12-31
Time
◦ Hold the time value
◦ Standard format hh:mm:ss
Datetime
◦ It hold date and time value
◦ Range between 1000-01-01 00:00:00 to 9999-12-31 23:59:59
◦ Standard format yyyy-mm-dd hh:mm:ss
year
◦ It is required 1 byte for holds year value
6. How PHP Fits with My
SQLYou can use MySQL commands within PHP code.
Some of the more commonly used functions are:
◦ mysql_connect($host, $username, $password) : Connects to the
MySQL server and returns a resource which is used to reference the
connection.
◦ Mysql_pconnect():-
◦ mysql_select_db($database, $resource) : Equivalent to the MySQL
command USE and sets the active database.
◦ mysql_query($query, $resource) : Used to send any MySQL
command to the database server. In the case of SELECT queries, a
reference to the result set will be returned.
◦ mysql_fetch_array($result) : Return a row of data from the query ’
s result set as an associative array, numeric array or both.
◦ mysql_fetch_assoc($result) : Return a row of data from the query ’
s result set as an associative array.
◦ mysql_error([$resource]) : Shows the error message generated by
the previous query.
◦ die(<String> $msg)
die() prints message and exits the current script.
7. Cont…
To connect with database
◦ $con = mysql_connect ($host, $username, $password)
$host = ‘localhost’;
$user = ‘root’;
$pass = ‘’;
$con = mysql_connect($host, $user, $pass);
The following statement has the same effect:
$con = mysql_connect(‘localhost’, ‘root’, ‘’);
To close the connection
◦ mysql_close($con);
To select database
$db = mysql_select_db(DBName,$con)
8. Create
Table
Syntax:-
◦ CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)
Example:-
◦ CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)
Important: A database must be selected before a table can be
created. The database is selected with the mysql_select_db()
function.
9. Insert data into tables
The INSERT INTO statement is used to add new records to a database table.
It is possible to write the INSERT INTO statement in two forms.
The first form doesn't specify the column names where the data will be
inserted, only their values:
INSERT INTO table_name VALUES (value1, value2, value3,...)
The second form specifies both the column names and the values to be
inserted:
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1,
value2, value3,...)
To get PHP to execute the statements above we must use the mysql_query()
function. This function is used to send a query or command to a MySQL
connection.
Example:-
// insert data into table
$insert=mysql_query("INSERT INTO Persons VALUES (1, 'Glenn',
'Quagmire',33 )");
// Execute query
mysql_query($insert,$con);
// insert data into table
$insert=mysql_query("INSERT INTO Persons (personID,FirstName,
LastName, Age) VALUES (2,'Peter', 'Griffin',35)");
10. Insert data into table using
FORM<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text"
name="firstname">
Lastname: <input type="text"
name="lastname">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html>
When a user clicks the submit button in the HTML
form in the example above, the form data is sent to
"insert.php".
11. Here is the "insert.php" page:
<?php
$con = mysql_connect('localhost', 'root', '') or
die ('Unable to connect. Check your connection
parameters.');
echo "Connection successfullyn";
// select database
mysql_select_db('student', $con) or die(mysql_error($con));
echo "Database activen";
//insert data
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
12. Retrieve the Data From a Database
Table$result = mysql_query("select * from Persons ")
To retrive the data from the table we are using the
mysql_fetch_array() function.
When we pass $result into the mysql_fetch_array function --
mysql_fetch_array($result) -- an associative array (firstname,
lastname, age) is returned.
mysql_fetch_array() function to return the first row from the
recordset as an array.
In our MySQL table " Persons," there are only three fields that we
care about: firstname, lastname and age.
These names are the keys to extracting the data from our
associative array.
To get the firstname we use $row[‘firstname'] , to get the
lastname we use $row[‘lastnamr'] and to get the age we
use $row['age'].
13. fetch array while
loopEach call to mysql_fetch_array() returns the next row
in the recordset.
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " .
$row['LastName'].””.$row[‘age’];
echo "<br />";
}
The while loop loops through all the records in the
recordset.
To print the value of each row, we use the PHP $row
variable ($row['FirstName']
,$row['LastName'],$row[‘age’]).
14. Retrieving data
To retrieving the data from database 2 function are used.
◦ mysql_fetch_array()
◦ mysql_fetch_assoc()
The mysql_fetch_assoc() function returns a single row from the table
as an associative array. The data can be retrieved by using the column
names as indexes.
The mysql_fetch_array() function returns a single row from the table.
The data can be retrieved by column names and column indexes.
@ is used to generate user defined exception other than System
generated errors.
mysql_num_fields( $result ) is used to count total number of fields and
coloumn from your database.
$num_cols = mysql_num_fields( $result );
mysql_num_rows( $result ) is used to count total number of recods
from your database.
$num_rows = mysql_num_rows( $result );
15. Include() AND include_once()
Include() AND require():-
◦ The include and require statements are used to insert useful
codes written in other files, in the flow of execution.
◦ Include and require are identical, except upon failure:
require will produce a fatal error (E_COMPILE_ERROR) and stop the script
include will only produce a warning (E_WARNING) and the script will
continue
So, if you want the execution to go on and show users the output, even if
the include file is missing, use include(). Otherwise, require().
◦ Syntax:-
Include(“file name with path”); or include “file name with path”;
Require(“file name with path”); or require “file name with path”;
◦ Example:-
<html>
<body>
<?php include 'header.php'; ?>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
</body>
</html>
16. Include_once() AND
require_once()
Include_once() & require_once() both are functioning same as
include() and require.
But the main difference between those function is include_once()
and require_once() include file only once while include() and
require() include files as many time as you want.
◦ Syntax:-
Include_once(“file name with path”); or include_once “file name with path”;
Require_once(“file name with path”); or require_once “file name with path”;
◦ Example:-
<html>
<body>
<?php include_once 'header.php'; ?>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
</body>
</html>
17. Maintaining State in PHP using Cookies &
Sessions
Why to maintain state in php?
◦ HTTP is stateless Protocol.
◦ Any data you have stored is forgotten about
when the page has been sent to the client
and the connection is closed.
◦ Cookie is tiny bits of information that a web
site could store on the client's machine that
were sent back to the web site each time a
new page was requested. Each cookie could
only be read by the web site that had written
it.
18. What is a Cookie?
A cookie is a small text file that is
stored on a user’s computer.
Each cookie on the user’s computer is
connected to a particular domain.
Each cookie be used to store up to
4kB of data.
A maximum of 20 cookies can be
stored on a user’s PC per domain.
19. 1. User sends a request for page at
www.example.com for the first time.
Exampl
e
page request
20. 2. Server sends back the page xhtml to
the browser AND stores some data in
a cookie on the user’s PC.
Exampl
e
cookie data
xhtml
21. 3. At the next page request for domain
www.example.com, all cookie data
associated with this domain is sent
too.
Exampl
e
page request
cookie data
22. setcookie(name [,value [,expire [,path [,domain
[,secure]]]]])
name = cookie name
value = data to store (string)
expire = UNIX timestamp when the cookie expires.
Default is that cookie expires when browser is closed.
path = Path on the server within and below which the
cookie is available on.
domain = Domain at which the cookie is available for.
secure = If cookie should be sent over HTTPS
connection only. Default false.
Set a
cookie
23. setcookie(‘name’,’Robert’)
This command will set the cookie called name on
the user’s PC containing the data Robert. It will be
available to all pages in the same directory or
subdirectory of the page that set it (the default path
and domain). It will expire and be deleted when the
browser is closed (default expire).
setcookie(‘age’,’20’,time()+60*60*24*30)
This command will set the cookie called age on
the user’s PC containing the data 20. It will be available
to all pages in the same directory or subdirectory of the
page that set it (the default path and domain). It will
expire and be deleted after 30 days.
Set a cookie -
examples
24. As the setcookie command involves
sending a HTTP header request, it must
be executed before any xhtml is
echoed to the browser, including
whitespace.
Where to write code for Cookie…
correct!
incorrect.
echoed
whitespace
before
setcookie
25. All cookie data is available through the
superglobal $_COOKIE:
$variable = $_COOKIE[‘cookie_name’]
or
$variable = $HTTP_COOKIE_VARS[‘cookie_name’];
e.g.
$age = $_COOKIE[‘age’]
Read cookie
data
26. To remove a cookie, simply overwrite the
cookie with a new one with an expiry time
in the past…
setcookie(‘cookie_name’,’’,time()-
6000)
Delete a
cookie
27. You can store user information (e.g. username,
items selected, etc.) in the server side for later
use using PHP session.
Sessions work by creating a unique id (UID) for
each visitor and storing variables based on this
UID.
The UID is either stored in a cookie or is
propagated in the URL.
PHP
Sessions
<?php session_start(); ?>
<html>
<body>
</body>
</html>
session_start() function must appear BEFORE the <html>
tag.
Before you can store user information in your PHP
session, you must first start up the session.
28. PHP
Sessions Starting a PHP session:
<?php
session_start();
?>
• This tells PHP that a session is requested.
• A session ID is then allocated at the server
end.
• session ID looks like:
sess_f1234781237468123768asjkhfa78912
34g
29. $_SESSION
e.g., $_SESSION[“intVar”] = 10;
Testing if a session variable has been
set:
session_start();
if(!$_SESSION['intVar']) {...} //intVar is set or not
Session
variables
31. Ending
sessionsunset($_SESSION[‘name’])
–Remove a session variable
session_destroy()
– Destroys all data registered to a session
– does not unset session global variables and cookies
associated with the session
–Not normally done - leave to timeout