Insert cookies data into MySQL database in PHP? [d

2019-09-22 03:21发布

问题:

Possible Duplicate:
How to get offline cookies data with php and insert it in mysql?
Get cookies in php?

I have some users information saved in cookie, the users information are like this,

Fname:Muhammad,Lname:Riaz,title:Developer,org:MagicLamp,email:riaz@yaho.com Fname:Fraz,Lname:Khan,title:Developer,org:MagicLamp,email:riaz@yaho.com

I want to insert these information in to MySQL database. The problem is this: how can I get this information from a cookie and insert into database?

回答1:

$str = "";

foreach ($_COOKIE as $key => $value)
{
    $str .= $key . ":" . $value . ",";
}

$str = substr($str, 0, -1);


回答2:

Please check this out: $_COOKIE

After getting the cookie you can use pdo or mysqli to insert the data into the database.

Make sure you clean the data before inserting into the db.