How to call JWT payload dataHow can I prevent SQL injection in PHP?How do I get PHP errors to display?How do I get a YouTube video thumbnail from the YouTube API?How do you parse and process HTML/XML in PHP?How do I check if a string contains a specific word?How does PHP 'foreach' actually work?angular2 with Slim framework jwt authenticationHow to use session variables in php?Slim Controller Request, response and args not availableHow to display error message to user in PHP MVC with Slim Router?

What does "play with your toy’s toys" mean?

Apply brace expansion in "reverse order"

What is the legal status of travelling with methadone in your carry-on?

Employer wants to use my work email account after I quit

Long term BTC investing

In the Marvel universe, can a human have a baby with any non-human?

What's currently blocking the construction of the wall between Mexico and the US?

Inverse-quotes-quine

Do I have any obligations to my PhD supervisor's requests after I have graduated?

Is it damaging to turn off a small fridge for two days every week?

What is this tool/thing in an Aztec painting?

What is the origin of Scooby-Doo's name?

Should I prioritize my 401(k) over my student loans?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

expiry or manufactured date?

How does Powershell create fake drive labels in Windows?

Can any NP-Complete Problem be solved using at most polynomial space (but while using exponential time?)

Suggested order for Amazon Prime Doctor Who series

Links to webpages in books

Find the probability that the 8th woman to appear is in 17th position.

Require advice on power conservation for backpacking trip

Sci fi short story, robot city that nags people about health

Unusual mail headers, evidence of an attempted attack. Have I been pwned?

A STL-like vector implementation in C++



How to call JWT payload data


How can I prevent SQL injection in PHP?How do I get PHP errors to display?How do I get a YouTube video thumbnail from the YouTube API?How do you parse and process HTML/XML in PHP?How do I check if a string contains a specific word?How does PHP 'foreach' actually work?angular2 with Slim framework jwt authenticationHow to use session variables in php?Slim Controller Request, response and args not availableHow to display error message to user in PHP MVC with Slim Router?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















here I have my post login to make a user login to the system, then return a JWT which contain initialize time, expired time and id.



$app->post('/login', function ($request, $response) 

$input = $request->getParsedBody();
$settings = $this->get('settings'); // get settings array.
$sql = "SELECT id, password FROM users WHERE id= :id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $input['id']);
$sth->execute();
$user = $sth->fetchObject();

// verify user id
if(!$user)
return $this->response->withJson(['error' => true, 'message' => 'NO ID '], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);

// Compare the input password and the password from database for a validation
if (strcmp($input['password'],$user->password))
return $this->response->withJson(['error' => true, 'message' => 'These credentials do not match our records.'], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);


if (session_status() === PHP_SESSION_NONE)
session_start();


$payload = [
"iat" => time(),
"exp" => time() + 36000,
"id" => $input['id']
];

$token = JWT::encode($payload, $settings['jwt']['secret'],"HS256");

$_SESSION['user_id'] = $input['id'];

return $this->response->withJson($input, 200)
->withHeader('Content-type', 'application/json;charset=utf-8', 200)
->withAddedHeader('Authorization', $token);


);



$app->put('/address/id', function ($request, $response, $args) 

if (session_status() === PHP_SESSION_NONE)
session_start();


if(!empty($_SESSION['user_id']))
$input = $request->getParsedBody();
$sql = "UPDATE address SET s_pNumber =:s_pNumber, s_address =:s_address, s_address2 =:s_address2 , s_pCode =:s_pCode, s_city =:s_city,
s_state =:s_state, s_country =:s_country WHERE id =:id";

$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->bindParam("s_pNumber", $input['s_pNumber']);
$sth->bindParam("s_address", $input['s_address']);
$sth->bindParam("s_address2", $input['s_address2']);
$sth->bindParam("s_pCode", $input['s_pCode']);
$sth->bindParam("s_city", $input['s_city']);
$sth->bindParam("s_state", $input['s_state']);
$sth->bindParam("s_country", $input['s_country']);
$input['id'] = $args['id'];
$sth->execute();
session_destroy();

return $this->response->withJson($input, 200);


// if(empty($_SESSION['user_id']))
// return $response->withJson(['error' => true, 'message' => 'Login please'], 403);
//


);



My question is how can I edit the user data based on the id in the payload that the user already logged in inside? How can I decode the payload and make my mysql look like it is something like " WHERE (payload.id)" not " WHERE id =:id ' Thank you










share|improve this question






















  • I don't get why you are mixing JWT and Sessions? Better use Sessions OR JWT, but not everything at the same time.

    – odan
    Mar 25 at 16:02

















0















here I have my post login to make a user login to the system, then return a JWT which contain initialize time, expired time and id.



$app->post('/login', function ($request, $response) 

$input = $request->getParsedBody();
$settings = $this->get('settings'); // get settings array.
$sql = "SELECT id, password FROM users WHERE id= :id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $input['id']);
$sth->execute();
$user = $sth->fetchObject();

// verify user id
if(!$user)
return $this->response->withJson(['error' => true, 'message' => 'NO ID '], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);

// Compare the input password and the password from database for a validation
if (strcmp($input['password'],$user->password))
return $this->response->withJson(['error' => true, 'message' => 'These credentials do not match our records.'], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);


if (session_status() === PHP_SESSION_NONE)
session_start();


$payload = [
"iat" => time(),
"exp" => time() + 36000,
"id" => $input['id']
];

$token = JWT::encode($payload, $settings['jwt']['secret'],"HS256");

$_SESSION['user_id'] = $input['id'];

return $this->response->withJson($input, 200)
->withHeader('Content-type', 'application/json;charset=utf-8', 200)
->withAddedHeader('Authorization', $token);


);



$app->put('/address/id', function ($request, $response, $args) 

if (session_status() === PHP_SESSION_NONE)
session_start();


if(!empty($_SESSION['user_id']))
$input = $request->getParsedBody();
$sql = "UPDATE address SET s_pNumber =:s_pNumber, s_address =:s_address, s_address2 =:s_address2 , s_pCode =:s_pCode, s_city =:s_city,
s_state =:s_state, s_country =:s_country WHERE id =:id";

$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->bindParam("s_pNumber", $input['s_pNumber']);
$sth->bindParam("s_address", $input['s_address']);
$sth->bindParam("s_address2", $input['s_address2']);
$sth->bindParam("s_pCode", $input['s_pCode']);
$sth->bindParam("s_city", $input['s_city']);
$sth->bindParam("s_state", $input['s_state']);
$sth->bindParam("s_country", $input['s_country']);
$input['id'] = $args['id'];
$sth->execute();
session_destroy();

return $this->response->withJson($input, 200);


// if(empty($_SESSION['user_id']))
// return $response->withJson(['error' => true, 'message' => 'Login please'], 403);
//


);



My question is how can I edit the user data based on the id in the payload that the user already logged in inside? How can I decode the payload and make my mysql look like it is something like " WHERE (payload.id)" not " WHERE id =:id ' Thank you










share|improve this question






















  • I don't get why you are mixing JWT and Sessions? Better use Sessions OR JWT, but not everything at the same time.

    – odan
    Mar 25 at 16:02













0












0








0








here I have my post login to make a user login to the system, then return a JWT which contain initialize time, expired time and id.



$app->post('/login', function ($request, $response) 

$input = $request->getParsedBody();
$settings = $this->get('settings'); // get settings array.
$sql = "SELECT id, password FROM users WHERE id= :id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $input['id']);
$sth->execute();
$user = $sth->fetchObject();

// verify user id
if(!$user)
return $this->response->withJson(['error' => true, 'message' => 'NO ID '], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);

// Compare the input password and the password from database for a validation
if (strcmp($input['password'],$user->password))
return $this->response->withJson(['error' => true, 'message' => 'These credentials do not match our records.'], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);


if (session_status() === PHP_SESSION_NONE)
session_start();


$payload = [
"iat" => time(),
"exp" => time() + 36000,
"id" => $input['id']
];

$token = JWT::encode($payload, $settings['jwt']['secret'],"HS256");

$_SESSION['user_id'] = $input['id'];

return $this->response->withJson($input, 200)
->withHeader('Content-type', 'application/json;charset=utf-8', 200)
->withAddedHeader('Authorization', $token);


);



$app->put('/address/id', function ($request, $response, $args) 

if (session_status() === PHP_SESSION_NONE)
session_start();


if(!empty($_SESSION['user_id']))
$input = $request->getParsedBody();
$sql = "UPDATE address SET s_pNumber =:s_pNumber, s_address =:s_address, s_address2 =:s_address2 , s_pCode =:s_pCode, s_city =:s_city,
s_state =:s_state, s_country =:s_country WHERE id =:id";

$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->bindParam("s_pNumber", $input['s_pNumber']);
$sth->bindParam("s_address", $input['s_address']);
$sth->bindParam("s_address2", $input['s_address2']);
$sth->bindParam("s_pCode", $input['s_pCode']);
$sth->bindParam("s_city", $input['s_city']);
$sth->bindParam("s_state", $input['s_state']);
$sth->bindParam("s_country", $input['s_country']);
$input['id'] = $args['id'];
$sth->execute();
session_destroy();

return $this->response->withJson($input, 200);


// if(empty($_SESSION['user_id']))
// return $response->withJson(['error' => true, 'message' => 'Login please'], 403);
//


);



My question is how can I edit the user data based on the id in the payload that the user already logged in inside? How can I decode the payload and make my mysql look like it is something like " WHERE (payload.id)" not " WHERE id =:id ' Thank you










share|improve this question














here I have my post login to make a user login to the system, then return a JWT which contain initialize time, expired time and id.



$app->post('/login', function ($request, $response) 

$input = $request->getParsedBody();
$settings = $this->get('settings'); // get settings array.
$sql = "SELECT id, password FROM users WHERE id= :id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $input['id']);
$sth->execute();
$user = $sth->fetchObject();

// verify user id
if(!$user)
return $this->response->withJson(['error' => true, 'message' => 'NO ID '], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);

// Compare the input password and the password from database for a validation
if (strcmp($input['password'],$user->password))
return $this->response->withJson(['error' => true, 'message' => 'These credentials do not match our records.'], 404)->withHeader('Content-type', 'application/json;charset=utf-8', 404);


if (session_status() === PHP_SESSION_NONE)
session_start();


$payload = [
"iat" => time(),
"exp" => time() + 36000,
"id" => $input['id']
];

$token = JWT::encode($payload, $settings['jwt']['secret'],"HS256");

$_SESSION['user_id'] = $input['id'];

return $this->response->withJson($input, 200)
->withHeader('Content-type', 'application/json;charset=utf-8', 200)
->withAddedHeader('Authorization', $token);


);



$app->put('/address/id', function ($request, $response, $args) 

if (session_status() === PHP_SESSION_NONE)
session_start();


if(!empty($_SESSION['user_id']))
$input = $request->getParsedBody();
$sql = "UPDATE address SET s_pNumber =:s_pNumber, s_address =:s_address, s_address2 =:s_address2 , s_pCode =:s_pCode, s_city =:s_city,
s_state =:s_state, s_country =:s_country WHERE id =:id";

$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->bindParam("s_pNumber", $input['s_pNumber']);
$sth->bindParam("s_address", $input['s_address']);
$sth->bindParam("s_address2", $input['s_address2']);
$sth->bindParam("s_pCode", $input['s_pCode']);
$sth->bindParam("s_city", $input['s_city']);
$sth->bindParam("s_state", $input['s_state']);
$sth->bindParam("s_country", $input['s_country']);
$input['id'] = $args['id'];
$sth->execute();
session_destroy();

return $this->response->withJson($input, 200);


// if(empty($_SESSION['user_id']))
// return $response->withJson(['error' => true, 'message' => 'Login please'], 403);
//


);



My question is how can I edit the user data based on the id in the payload that the user already logged in inside? How can I decode the payload and make my mysql look like it is something like " WHERE (payload.id)" not " WHERE id =:id ' Thank you







php slim slim-3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 9:34









Hisyam SyazaniHisyam Syazani

319 bronze badges




319 bronze badges












  • I don't get why you are mixing JWT and Sessions? Better use Sessions OR JWT, but not everything at the same time.

    – odan
    Mar 25 at 16:02

















  • I don't get why you are mixing JWT and Sessions? Better use Sessions OR JWT, but not everything at the same time.

    – odan
    Mar 25 at 16:02
















I don't get why you are mixing JWT and Sessions? Better use Sessions OR JWT, but not everything at the same time.

– odan
Mar 25 at 16:02





I don't get why you are mixing JWT and Sessions? Better use Sessions OR JWT, but not everything at the same time.

– odan
Mar 25 at 16:02












0






active

oldest

votes














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55334812%2fhow-to-call-jwt-payload-data%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55334812%2fhow-to-call-jwt-payload-data%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴