I am doing the following in my laravel app,
$unique_id = uniqid();
return redirect($response['_links']['next_url']['href'])->withCookie(cookie($unique_id, $response['payment_id'], 20));
Once the redirect has been done, how I would get the value of the cookie, as when I do this,
$debug = [
'uuid' => $request->query('uuid'),
'payment_id' => $request->cookie($request->query('uuid'))
];
dd($debug);
The uuid is the $unique_id that get passed into to the redirection url, so I assumed access it like above would work but no, how can I access the value of the cookie?
A cookie with uuid is getting created and has a value,
Related
I have an input like below.
array:4 [
"_token" => "evktHCfCNZVQMNYXzntfHZkdNLZFqvOoYgU3yPKy"
"name" => "Name"
"orderId" => "5cb5943a6733a1555403834"
"amount" => null
]
which I stored to a session like this:
public function store(Request $request)
{
request()->session()->put('bookingInfo', $request->input());
return redirect()->route('book.checkout');
}
Now I want to change the amount value in the session. How I am going to achieve that?
To update the value, you need to retrieve the values from session and update it again.
To do that, you need to do
$booking_info = $request->session()->get('bookingInfo');
Then you will got an array back. Update it like a normal array
$booking_info["amount"] = 10; // anything you wanted
If you need to put it back into session again you can do this
$request->session()->put('bookingInfo', $booking_info);
EDIT
If you want the ability to update partially, you would need to store it separately like this.
$input = $request->all();
$request->session()->put('bookingInfo.name', $input['name']);
$request->session()->put('bookingInfo.orderId', $input['orderId']);
$request->session()->put('bookingInfo.amount', $input['amount']);
Laravel 5+
// Via a request instance...
$request->session()->put('amount', 'value');
// Via the global helper...
session(['amount' => 'value']);
// For retrieve
session('amount');
In my Laravel project I am storing array in to session. I tried to delete the whole array from session using session forget method, but it is not working. I can access sessions after session forget. Any help would be appreciated thank you.
Storing data in to session
$item = [
'name' => 'Test',
'normalIdSession' => 'Normal Data',
'guestsSession' => '1',
'amountSession' => '200'
];
$request->session()->put('item', $item);
Deleting session
if(session()->has('item'))
{
$name = session()->get('item.name');
$normalIdSession = session()->get('item.normalIdSession');
$guestsSession = session()->get('item.guestsSession');
$amountSession = session()->get('item.amountSession');
// Here data storing in to database and deleting sessions.
session()->forget('item');
dd($name); // Here I can access session data.
}
So I have stored my session data into the session like below:
$user_data = array(
'user_id' => $user_id,
'email' => $email,
'logged_in' => true
);
$this->session->set_userdata('login_session', $user_data);
In my view, I'm trying to echo the email out onto the page but no matter which way I try to access it, it will not echo out:
echo $this->session->userdata('email');
How can I access the array values?
You are storing the values in an array & then assigning that array to a variable called login_session but while retrieving the data you are just accessing with only key and not with array['key'].
So the correct syntax is:
echo $this->session->userdata('login_session')['email'];
OR
$log_sess=$this->session->userdata('login_session');
echo $log_sess['email'];
Please go through the codeigniter document as well.
I have an cookie array with json items like this
//set my cookie
setcookie("my_Cookie", $cookie_content, time()+3600);
//this is the content of my cookie for example with 2 items
[{"item_id":"9","item_tag":"AS","session_id":"554obe5dogsbm6l4o9rmfif4o5"},{"item_id":"6","item_tag":"TE","session_id":"554obe5dogsbm6l4o9rmfif4o5"}]
The workflow is like an shopping cart, I can add and delete items. One "product" on my website contains: item_id, item_tag and the session_id;
For adding an item the cookie will be extended with item_id":"X","item_tag":"X","session_id":"X
now if I click on delete I want remove the current three values in the cookie
I try it with
unset($_COOKIE["my_Cookie", 'item_id'=> $item_id, 'item_tag'=> $item_tag, 'session_id'=> $session_id]); but this doesn't work
Is it possible to delete specific values of my cookie?
Like this:
setcookie('cookie_name'); // Deletes the cookie named 'cookie_name'.
This works because setting a cookie with no value is the same as deleting it.
If I'm not mistaken, you can't directly modify a cookie's value; you'll have to read the value, make any modifications, and then replace the cookie using the same name.
So, in this case, once a user hits the delete link, your script should save the ID of the item that they want removed, read the cookie value(s), rewrite the array and then replace the cookie with the updated values.
Perhaps this demo will help:
// Should be the user submitted value to delete.
// Perhaps a $_GET or $_POST value check.
$value_to_delete = 9;
// Should be the cookie value from $_COOKIE['myCookie'] or whatever the name is.
// Decode from JSON values if needed with json_decode().
$cookie_items = array(
array("item_id" => 9, "item_tag" => "RN"),
array("item_id" => 6, "item_tag" => "RN"),
array("item_id" => 4, "item_tag" => "RN")
);
// Run through each item in the cart
foreach($cookie_items as $index => $value)
{
$key = array_search($value_to_delete, $value);
if($key == "item_id")
{
unset($cookie_items[$index]);
}
}
// Reset the index
$cookie_items = array_values($cookie_items);
// Set the cookie
setcookie($cookie_items);
// Debug to view the set values in the cookie
print_r($cookie_items);
I believe a cookie will simply be stored as a string so you might be best off just overwriting it...
I have a valid and authenticated user, but when posting to their wall from our PHP web app it returns:
Fatal error: Uncaught OAuthException: (#803) Some of the aliases you requested do not exist: xxxxxxxxxxxxx","name":"xxxxxxx
I have 24 other users that can post with no issues. And I can see the user exists by going to https://graph.facebook.com/xxxxxxxxxxxxx
Here is the code:
$fb_user_id = $row[0]; // loaded from DB
$facebook_token = $row[1]; // loaded from DB
$result = $facebook->api('/' . $fb_user_id. '/feed/',
'post',
array('access_token' => $facebook_token,
'message' => $postMessage,
'name' => 'Product name',
'caption' => 'Accomplished!',
'link' => 'http://www.xxxxxxx.com/',
'description' => $postMessage,
'picture' => 'http://www.xxxxxxx.com/images/productImage.png'));
Any ideas why the Facebook API thinks this user does not exist?
I had this issue, later I realised I was saving the uid in my database as an integer, however, new facebook profiles have very long uids, such as : 100004409446248, this was not a value I could save as an integer in my mysql database, I changed this to treat it as a varchar, so now there's no issue
This question Getting list of Facebook friends with latest API suggests
$friends = $facebook->api('/me/friends');
I wrote two library routine for get integer querystrings. Similar to Dainel's experience when I use the intval() function, I get an invalid Facebook id cause produce that error.
Code:
function get_int($field) {
$value = 0;
if(isset($_GET[$field])) $value = intval($_GET[$field]);
return $value;
}
I use the get_str for facebook_id and problem was gone.
function get_str($field) {
$value = '';
if(isset($_GET[$field])) $value = $_GET[$field];
return $value;
}
Define APP ID as integer, not string!