Skip to content

Commit 87796a0

Browse files
committed
remove $_SESSION from methods and functions
1 parent 0cd3993 commit 87796a0

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

system/CodeIgniter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,13 +1064,13 @@ public function storePreviousURL($uri)
10641064
}
10651065

10661066
if (isset($_SESSION)) {
1067-
$_SESSION['_ci_previous_url'] = URI::createURIString(
1067+
session()->set('_ci_previous_url', URI::createURIString(
10681068
$uri->getScheme(),
10691069
$uri->getAuthority(),
10701070
$uri->getPath(),
10711071
$uri->getQuery(),
10721072
$uri->getFragment()
1073-
);
1073+
));
10741074
}
10751075
}
10761076

system/HTTP/IncomingRequest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -827,35 +827,42 @@ public function getUserAgent()
827827
*/
828828
public function getOldInput(string $key)
829829
{
830-
// If the session hasn't been started, or no
831-
// data was previously saved, we're done.
832-
if (empty($_SESSION['_ci_old_input'])) {
830+
// If the session hasn't been started, we're done.
831+
if (! isset($_SESSION)) {
832+
return null;
833+
}
834+
835+
// Get previously saved in session
836+
$old = session('_ci_old_input');
837+
838+
// If no data was previously saved, we're done.
839+
if ($old === null) {
833840
return null;
834841
}
835842

836843
// Check for the value in the POST array first.
837-
if (isset($_SESSION['_ci_old_input']['post'][$key])) {
838-
return $_SESSION['_ci_old_input']['post'][$key];
844+
if (isset($old['post'][$key])) {
845+
return $old['post'][$key];
839846
}
840847

841848
// Next check in the GET array.
842-
if (isset($_SESSION['_ci_old_input']['get'][$key])) {
843-
return $_SESSION['_ci_old_input']['get'][$key];
849+
if (isset($old['get'][$key])) {
850+
return $old['get'][$key];
844851
}
845852

846853
helper('array');
847854

848855
// Check for an array value in POST.
849-
if (isset($_SESSION['_ci_old_input']['post'])) {
850-
$value = dot_array_search($key, $_SESSION['_ci_old_input']['post']);
856+
if (isset($old['post'])) {
857+
$value = dot_array_search($key, $old['post']);
851858
if ($value !== null) {
852859
return $value;
853860
}
854861
}
855862

856863
// Check for an array value in GET.
857-
if (isset($_SESSION['_ci_old_input']['get'])) {
858-
$value = dot_array_search($key, $_SESSION['_ci_old_input']['get']);
864+
if (isset($old['get'])) {
865+
$value = dot_array_search($key, $old['get']);
859866
if ($value !== null) {
860867
return $value;
861868
}

system/Helpers/form_helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,12 @@ function set_radio(string $field, string $value = '', bool $default = false): st
701701
*/
702702
function validation_errors()
703703
{
704-
session();
704+
$errors = session('_ci_validation_errors');
705705

706706
// Check the session to see if any were
707707
// passed along from a redirect withErrors() request.
708-
if (isset($_SESSION['_ci_validation_errors']) && (ENVIRONMENT === 'testing' || ! is_cli())) {
709-
return $_SESSION['_ci_validation_errors'];
708+
if ($errors !== null && (ENVIRONMENT === 'testing' || ! is_cli())) {
709+
return $errors;
710710
}
711711

712712
$validation = Services::validation();

system/Helpers/url_helper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ function previous_url(bool $returnObject = false)
8888
{
8989
// Grab from the session first, if we have it,
9090
// since it's more reliable and safer.
91+
if (isset($_SESSION)) {
92+
$referer = session('_ci_previous_url');
93+
}
94+
9195
// Otherwise, grab a sanitized version from $_SERVER.
92-
$referer = $_SESSION['_ci_previous_url'] ?? Services::request()->getServer('HTTP_REFERER', FILTER_SANITIZE_URL);
96+
$referer ??= Services::request()->getServer('HTTP_REFERER', FILTER_SANITIZE_URL);
9397

9498
$referer ??= site_url('/');
9599

0 commit comments

Comments
 (0)