Hướng dẫn php session between pages - phiên php giữa các trang

Có hai cách mà bạn có thể làm điều này

  1. Phiên
  2. Các trường đầu vào ẩn

Phiên

Các trường đầu vào ẩn

$_SESSION['name'] = $_POST['name'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['pin'] = $_POST['pin'];

Để truyền dữ liệu từ trang này sang trang khác, trước tiên bạn cần gọi session_start() trên tất cả các trang sẽ sử dụng biến SuperGlobal $_SESSION. Sau đó bạn có thể lưu trữ các giá trị của mình trong các phiên bằng cách sử dụng

$name = $_SESSION['name']; // will contain the value entered in first page

Để sử dụng các giá trị này trong trang thứ hai, chỉ cần gọi chúng bằng tên của chúng. Bán tại:

================================================== ================================

Các trường đầu vào ẩn

Đây là một cách tiếp cận tẻ nhạt nhưng nó thực hiện công việc không kém. Quá trình này liên quan đến việc lưu trữ dữ liệu cần được chuyển sang các trang khác nhau trong các trường ẩn và sau đó truy cập chúng thông qua SuperGlobal $_POST hoặc $_GET. (which posts to page2.php)



Trang1.php (đăng lên trang2.php) (which posts to page3.php)





page3.php

echo $_POST['content']; // prints "Page 1 content"
echo $_POST['body']; // prints "Page 1 body"
echo $_POST['content2']; // prints "Page 2 content"
echo $_POST['body2']; // prints "Page 2 body"

Trang2.php (đăng lên trang3.php)

(Php 4> = 4.1.0, Php 5, Php 7, Php 8)Session variables

$ _Session - Biến phiên

Sự mô tả

Một mảng kết hợp chứa các biến phiên có sẵn cho tập lệnh hiện tại. Xem tài liệu chức năng phiên để biết thêm thông tin về cách sử dụng điều này.

Ghi chú:

Ghi chú:global $variable; to access it within functions or methods.

Đây là một 'Superglobal', hoặc biến toàn cầu, tự động. Điều này đơn giản có nghĩa là nó có sẵn trong tất cả các phạm vi trong suốt một kịch bản. Không cần phải thực hiện biến $ toàn cầu; để truy cập nó trong các chức năng hoặc phương pháp.

Tàu kéo

Creating New Session
==========================
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
?>
Getting Session
==========================
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
/*session created*/
echo $_SESSION["newsession"];
/*session was getting*/
?>
Updating Session
==========================
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
/*it is my new session*/
$_SESSION["newsession"]=$updatedvalue;
/*session updated*/
?>
Deleting Session
==========================
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
unset(
$_SESSION["newsession"]);
/*session deleted. if you try using this you've got an error*/
?>

7 năm trước

opajaap tại opajaap dot nl ¶

$name = $_SESSION['name']; // will contain the value entered in first page
0

$name = $_SESSION['name']; // will contain the value entered in first page
1

$name = $_SESSION['name']; // will contain the value entered in first page
2

$name = $_SESSION['name']; // will contain the value entered in first page
3

$name = $_SESSION['name']; // will contain the value entered in first page
4

Bohwaz ¶

14 năm trước

$name = $_SESSION['name']; // will contain the value entered in first page
5

$name = $_SESSION['name']; // will contain the value entered in first page
6

$name = $_SESSION['name']; // will contain the value entered in first page
7

$name = $_SESSION['name']; // will contain the value entered in first page
8

Jererry tại NetCourrier Dot Com ¶

14 năm trước

$name = $_SESSION['name']; // will contain the value entered in first page
9



0



1



2



3

Jererry tại NetCourrier Dot Com ¶

Fred ¶



4



5



6



7



8



9





0





1





2





0





4





5





6





7



3

9 năm trước

Fred ¶





9

echo $_POST['content']; // prints "Page 1 content"
echo $_POST['body']; // prints "Page 1 body"
echo $_POST['content2']; // prints "Page 2 content"
echo $_POST['body2']; // prints "Page 2 body"
0

echo $_POST['content']; // prints "Page 1 content"
echo $_POST['body']; // prints "Page 1 body"
echo $_POST['content2']; // prints "Page 2 content"
echo $_POST['body2']; // prints "Page 2 body"
1



3

9 năm trước

Miller ¶

echo $_POST['content']; // prints "Page 1 content"
echo $_POST['body']; // prints "Page 1 body"
echo $_POST['content2']; // prints "Page 2 content"
echo $_POST['body2']; // prints "Page 2 body"
3

echo $_POST['content']; // prints "Page 1 content"
echo $_POST['body']; // prints "Page 1 body"
echo $_POST['content2']; // prints "Page 2 content"
echo $_POST['body2']; // prints "Page 2 body"
4



3