90.4k views
4 votes
Which of the following that can be use to access session variables in PHP?

Select one:

a. $_SESSION

b. start_session()

c. session_start()

d. $_SESSIONS

1 Answer

1 vote

Answer:

a. $_SESSION

Step-by-step explanation:

A session variable in PHP can be accessed using the global variable $_SESSION.

This can be used for both setting and retrieving session values as described subsequently.

$_SESSION["var1"] = "value1";

This set a session variable called 'var1' to a value 'value1'. Later if we want to retrieve this value we can do it as follows:

echo "Value of session variable 'var1' is " . $_SESSION["var1"] ;

This will print the result: Value of session variable 'var1' is value1

User Jason Carty
by
6.5k points