Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

luk's avatar
Level 1

seesion_id() method is not working

In my project I want to update mu default sessionID value and i used the following way


	public function __construct(){
		$db = new DB;

		$this->db =  $db->connect();
		$this->id = $this->ID();
		$this->sessionID = $this->getSessionID();
	}
	public function ID(){
		if($this->isLoggedIn()){
			return $_SESSION['id'];
		}
	}

	public function getSessionID(){

		return session_id();
		var_dump($this->sessionID);
	}

	public function updateSession(){
	  	$stmt = $this->db->prepare("UPDATE `users` SET `sessionID` = :sessionID WHERE `id` :id");
	  	$stmt->bindParam(":sessionID",$this->sessionID,PDO::PARAM_STR);
	  	$stmt->bindParam(":id",$this->id,PDO::PARAM_INT);
	  	var_dump($this->sessionID);
	  	$stmt->execute();


	  }

	  public function getUserBySession($sessionID){
	  	$stmt = $this->db->prepare("SELECT * FROM `users` WHERE `sessionID`=:sessionID");
		$stmt->bindParam(":sessionID",$sessionID,PDO::PARAM_STR);
		
		$stmt->execute();
		 return $stmt->fetch(PDO::FETCH_OBJ);
	  }

and session.php

<?php
session_start();
require 'connection.php';
require 'user.php';

$userObj = new User;

define('BASE_URL','http://localhost:8081/insa/');

and

<?php
include_once 'session.php';
include_once 'user.php';
$userObj->updateSession();

if(isset($_GET['username']) && !empty($_GET['username'])){
	$profileData = $userObj->getUserByUsername($_GET['username']);
    $user = $userObj->userData();

	if(!$profileData){

		$userObj->redirect('home.php');
	}elseif ($profileData->username === $user->username) {
        $userObj->redirect('home.php');
    }
}else{
	$userObj->redirect('home.php');
}
//var_dump($profileData)
?>

but when refresh the page and var_dump the $sessionID I got this "'nf1tbr924igmjkurgtemgfabek' (length=26)" and it didn't update the sessionID ,I don't know why it is not working ,any one who can help me please !!

0 likes
2 replies
Sinnbeck's avatar

What do you mean by

and it didn't update the sessionID

In the database?

1 like
luk's avatar
Level 1

@Sinnbeck mean it dose nOt change the defualt value of the sessionID

Please or to participate in this conversation.