I'm having some problems trying to access variables sessions in the confirmation page used it by payu. In the post request I can access the variables sent from the gateway like this: $state_pol = $_POST["state_pol"]; and no problem with that, I can stored the value in my data base, But when I try to do this $email = Auth::user()->email; when I do that I can't get any variable or stored values in the DB. I need to stored in the DB the cart Items and I'm using moltin Cart, so I need to do something like this:
foreach (Cart::contents() as $item) {
$citem = new Ite;
$citem->compra_id = $compra->id;
$citem->id_product = $item->id;
$citem->name = $item->name;
$citem->val_uni = $item->price;
$citem->image = $item->image;
$citem->iva = $item->tax;
$citem->qty = $item->quantity;
$citem->val_total = $item->total();
$citem->save();
}
Cart::destroy();
the methods Cart::contents() and Cart::destroy(); don't work, but just in the payu request, I tried this with paypal request and everything works correctly and I'm using the same code, I mean with the variables session.
Thanks in advance for the time and help.
I just realized that the problem is with eloquent too. I mean, I cannot get access to the DB, I cannot do something like this $user = User::where('id','=',1)->first(); I tried with query builder but it didn't work.
Related
I am using the Foursquare API to request information for my users.
It says to make a request to get user info like this,
https://api.foursquare.com/v2/users/self?oauth_token=TOKENHERE
So I am doing it like this,
$fsUser = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
When I var_dump I get null from the value I am saving it in, Here is what my full code looks like,
<?php
$client_id = "iwdhwouchweohcuwoehcowehcu";
$secret = "ojdwojwjwrhvo";
$redirect = "http://www.example.com";
if($_GET['code']){
//We need to hit up the authkey URL and get the key in JSON format
$authkey = file_get_contents("https://foursquare.com/oauth2/access_token?client_id=".$client_id."&client_secret=".$secret."&grant_type=authorization_code&redirect_uri=".$redirect."&code=".$_GET['code']);
//We then need to decode it and store that key in a variable
$auth = json_decode($authkey,true);
$access_token = $auth['access_token'];
//we then look up whatever endpoint of the api we want
$fsUser = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
$user = json_decode($fsUser, true);
// $name = $decoded_userinfo['response']['user']['firstName'];
}
?>
When I var_dump $fsUser I get bool(false)
I have var_dump every variable with no issues till I get to $fsUser I can not get past this part...
You also need to use the version number (v) with your request.
Like this
https://api.foursquare.com/v2/venues/search?client_id=CLIENT_ID&v=20140806&m=foursquare
See documentation here.
https://developer.foursquare.com/overview/versioning
I have been attempting to use steam api to display a persons name. When I insert there steamid in directly it works however, when I try to use a variable it doesn't work. The thing that confuses me is that I have this exact same code for my queue that works however this does not work. I have looked around and I believe I am doing this right but for some reason it is not working. Any help here would be great. Thanks.
<?
$name = 76xxxxxxxxxxx;
$response = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/? key=xxx&steamids={$name}&format=json";
$middle = (file_get_contents($response));
$json = json_decode($middle, true);
$b = $json['response']['players'][0]['personaname'];
print_r($b);
?>
Your $name variable needs to be wrapped in quotes.
$name = "76xxxxxxxxxxx";
This will properly create your response variable
I am trying to build a simple shopping cart using PHP and no Database.
Based on the user input, I search for an Item using ebay API(returns XML Data).
I am able to get its price,id,and other details.
I am then creating an array called ITEMS which contains all the data returned by ebay.
(I know I have to create a cart only for items that are selected).
The Issue is I am able to access the cart contents from the session within the search function but not from other functions.I am new to PHP could someone help me fix this.
As of now I am only trying to access the cart contents from buy.
function search(){
$xml = new SimpleXMLElement($xmlstr);
print "<table border=1>";
$loop = $xml->categories[0]->category->items->product;
foreach ( $loop as $dummy) {
$id = $dummy->attributes();
$link = $dummy->productOffersURL;
$name = $dummy->name;
$price = $dummy->minPrice;
$image = $dummy->images->image->sourceURL;
}
array_push($ITEMS, $item);
}
}
I changed the for eeach loop and it worked:
The code is :
$id = (String) $dummy->attributes();
$link = (String)$dummy->productOffersURL;
$name = (String)$dummy->name;
$price = (String)$dummy->minPrice;
$id = (String) $dummy->attributes();
$link = (String)$dummy->productOffersURL;
$name = (String)$dummy->name;
$price = (String)$dummy->minPrice;
You shouldn't call session start with the # (error supression) modifier. It could be triggering and error and you wouldn't know.
Check if your php.ini configuration is set to autostart the session.
session.auto_start = 0
If it's set to 1, you could be overwriting its contents by manually calling session start every time.
I've got a new SMS service for my php app. To send a message you need to go to an URL with the number and message as parameters.
This sms service sucks, is from an external company I know :(
//example.com/sms/?c=number&m=message
With an array of data I made a foreach loop to send each message.
<?php
// Users array
$users[] = ['Jhon', 123456789]
$users[] = ['Peter', 223456789]
$users[] = ['Sam', 323456789]
$users[] = ['Carl', 423456789]
// The loop
foreach ($users as $thisUser) {
// URL builded with the users data
$thisNumber = $thisUser[1];
$thisMessage = 'Hey,+your+name+is+' . $thisUser[0]
$request = sprintf('http://example.com/sms/?c=%d&m=Hey+%s+', $thisNumber, $thisMessage);
}
?>
Now, ¿witch is the best way to go that URL in a loop [several times]? Header redirection doesn't work for me. Maybe cURL...
I don't think JavaScript is a good solution. From the sound of it, you want to call that remote url so you can send an SMS. You can either use CURL or file_get_contents and just ignore the results (unless you need the results).
In my code i am trying to store a variable between two pages but i either get a string return "images" or 0... or nothing- tried casting it.. echoing in on one page works and displays correct number but as soon as you click through the view to the next page- its lost- i tried turning on cs_sessions in the db and made no difference
<?php
public function carconfirm($car_id = '')
{
if(empty($car_id))
{
redirect('welcome');
}
$this->load->model('mcars');
$car = $this->mcars->getCar($car_id);
$data['car'] = $car->row_array();
$car_id = (int) $car_id;
$this->session->set_userdata('flappy', $car_id);
echo $car_id;
//insert details
//display details
$this->load->view('phps/carconfirm',$data);
}
function confirm()
{
//get vars
$time_slot = $this->session->userdata('slot');
$person_id = $this->session->userdata('person_id');
$car_id = $this->session->userdata('flappy');
$insert_array = array( 'slot'=> $time_slot ,
'car'=> $car_id,
'person_id'=> $person_id
);
print_r($insert_array);
$this->load->model('mbooking');
$result = $this->mbooking->addbooking($insert_array);
if($result)
{
redirect('welcome/options');
}
}
?>
the variable I'm losing is flappy- i changed the name to see if that was the problem
Finally, I fixed this. Using this answer in SO too : codeigniter setting session variable with a variable not working, I scan my js/css for missing resources. Turn out that, my thickbox.js refer to loadingAnimation.gif in, yes, images folder. That's where the images come. Having fix the missing file, the sesion variabel working just fine.
Not sure, why CI replace (maybe) last added session variabel using this, but maybe it's because CI is not using $_SESSION global variabel. CMIIW. I use this article as a hint : http://outraider.com/frameworks/why-your-session-variables-fail-in-codeigniter-how-to-fix-them/