Answers for "what is session"

PHP
13

php sessions

<?php
  	// Start new or resume existing session.
  	session_start();
	
	// Add values to the session.
	$_SESSION['item_name'] = 'value'; // string
	$_SESSION['item_name'] = 0; // int
	$_SESSION['item_name'] = 0.0; // float

	// Get session values.
	$value = $_SESSION['item_name'];
?>
Posted by: Guest on May-08-2020
3

create session in php

<?php 
  // Start the session
  session_start();

  // Set session variables
  $_SESSION["color"]= "blue";
  $_SESSION["animal"]= "dog";
  echo "The session variable are set up.";
?>
Posted by: Guest on June-16-2020
7

php session

/*Sessions are stored on the server
Sessions are a way to carry data across multiple pages. 
Typically if we set a variable on one page, it wouldn't be available 
on the next page. This is where Sessions come in. Unlike cookies session
data is not stored on the user's computer. It is stored on the server. 
In order to use session variables you have to start a session. 
Every page, that you want to use that data in, you have to use 
session_start.

If you want to unset one of these sessions you can use session_unset

youcan destry the session with session_destroy
*/

<?php if(isset($_POST['submit']))
{ session_start(); // that will start the session
$_SESSION['name'] = htmlentities($_POST['name']);
$_SESSION['email'] = htmlentities($_POST['email']);
header('Location: page2.php'); } ?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Sessions</title>
</head>
<body>
<form method="POST" action="<?php echo $server['PHP_SELF'];?>">
<input type="text" name="name" placeholder="Enter Name">
<br>
<input type="text" name="email" placeholder="Enter Email">
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Posted by: Guest on May-13-2020
0

session

$sql = "SELECT name, email FROM users WHERE username = '" . $_SESSION['username'] . "'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo "Hello, " . $row['name'] . " (" . $row['email'] . ").";
Posted by: Guest on July-22-2021
0

what is session management

Session is a State Management Technique.
A Session can store the value on the Server. 
It can support any type of object to be 
stored along with our own custom objects
Posted by: Guest on January-21-2021
0

session

from flask import Flask, redirect, url_for, render_template, request, session #session追加
from datetime import timedelta #時間情報を用いるため

app = Flask(__name__)

app.secret_key = 'user'
app.permanent_session_lifetime = timedelta(minutes=5) # -> 5分 #(days=5) -> 5日保存

@app.route("/")
def home():
  return render_template("index.html")

@app.route("/login", methods = ["POST", "GET"])
def login():
  #データベースに情報を送るとき
  if request.method == "POST":
    session.permanent = True  # <--- makes the permanent session
    user = request.form["nm"] #ユーザー情報を保存する
    session["user"] = user #sessionにuser情報を保存
    return redirect(url_for("user"))
  else: #情報を受け取るとき
    if "user" in session: #sessionにユーザー情報があったとき
      return redirect(url_for("user")) #userページに遷移
    return render_template("login.html") #sessionにユーザー情報がなかったときはloginページに遷移

@app.route("/user")
def user():
  if "user" in session:
    user = session["user"] #sessionからユーザー情報をとってくる
    return f"<h1>{user}</h1>"
  else:
    return redirect(url_for("login"))

@app.route("/logout") #ログアウトする
def logout():
  session.pop("user", None) #削除
  return redirect(url_for("login"))

if __name__ == "__main__":
  app.run(debug=True)
Posted by: Guest on November-02-2021

Code answers related to "what is session"

Browse Popular Code Answers by Language