hello I'm trying to start a session in the sql login query to save the image in a Session variable and display it. How can I insert an image into a Session variable in sql query?
Query:
function checkuser($conexionBd,$us,$pass){
$sentence= $conexionBd->prepare("SELECT us_id, us_img FROM users where us_us=? AND us_pass=?");
$img='us_img';
session_start();
$sentence->execute(array($us, $pass));
if ($sentence->rowCount()==1) {
$_SESSION['img']= $img;
header("Location:img.php");
exit();
}else{
echo 'user or password incorrect';
}
}
You first need to load your image and convert it using base64.
$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
Then you add $base64 variable to session
session_start();
$_SESSION['product_number'.$base64 ] = true;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.