i want to ask how do i check/see the value inside of this $datame in my code, i tried to var_dump it, i am using mozilla, it didn't show the value in console/network . Where or how do i check if there were data stored in my variable array.
public function facebook_request(){
$this->load->library('facebook/src/facebook', array('appId' => '1027885817316593', 'secret' => '6db175699897b514bf4881955b2944bb'));
$this->user = $this->facebook->getUser();
if ($this->user) {
$data['user_profile'] = $this->facebook->api('/me?fields=id,first_name,last_name,email,link,gender,locale,picture');
// Get logout url of facebook
$data['logout_url'] = $this->facebook->getLogoutUrl(array('next' => base_url() . 'index.php/oauth_login/logout'));
$datame = array(
'oauth_provider'=> 'facebook',
'oauth_uid' => $data['user_profile']['id'],
'first_name' => $data['user_profile']['first_name'],
'last_name' => $data['user_profile']['last_name'],
'email' => $data['user_profile']['email'],
'gender' => $data['user_profile']['gender'],
'locale' => $data['user_profile']['locale'],
'picture' => $data['user_profile']['picture']['data']['url'],
'link' => $data['user_profile']['link']
);
$userData = $this->user_model->checkUser2($datame);
var_dump($datame);
exit();
// Send data to profile page
$this->load->view('admin/profile.php', $data);
}
The server doesn't have access to write to that. You could pass $datame to the view you are trying to render and print it there or you could replace var_dump($datame) with error_log($datame) and then view your error log to see what it printed
change from
$userData = $this->user_model->checkUser2($datame);
var_dump($datame);
exit();
to
echo "<pre>";
print_r($datame);
exit();
$userData = $this->user_model->checkUser2($datame);
Related
I am sending post requests in PHP to get a boolean value from my API (so it should return wither true or false)
This is the code I am using in the file for my API. The file is called users.php
if ($_POST['type'] == "authenticateMinecraft"){
$p = new dibdibs\post(
array(
'url' => 'https://authserver.mojang.com/authenticate',
'data' => array(
'agent' => array(
'name' => 'Minecraft',
'version' => 1
),
'username' => $_POST['username'],
'password' => $_POST['password'],
'clientToken' => "33225A179D9A4E1BDA73C012C1C3CBAB8BD00326883BDBEB6FA682482E40F68D"
)
)
);
$res = $p->json();
if (isset($res["selectedProfile"])){
echo("true");
}
else{
echo("false");
}
}
This is the code I am using to reference it (I am using a class which I have put on Pastebin to actually send the request).
$params = array(
'data' => array(
'type' => 'authenticateMinecraft',
'username' => $mcuname,
'password' => $mcpasswd
),
'url' => "api/users.php"
);
$c = new dibdibs\post($params);
$r = $c->http();
var_dump($r);
Whenever I use the .php fule extension when defining url, the whole PHP code of the API page is returned, but when I remove the extension, only true or false is returned. Why is this and is it a problem that I should be aware of and I should fox?
Well I have created sessions but having trouble implementing cookies in my website. In config file i have set $config['sess_expire_on_close'] = TRUE; so that user's session expires on closing browser.
Now what i want is, On login if user checks remember me ... all data should be stored in a cookie so that on closing browser, user is still logged on.
function login($email, $password, $loginas) {
if ($loginas == 'user') {
$this->db->select('*');
$this->db->where('email', $email);
$this->db->where('password', $password);
$query = $this->db->get("user_info");
if ($query->num_rows() > 0) {
foreach ($query->result() as $rows) {
$newdata = array('id' => $rows->id,
'firstname' => $rows->firstname,
'lastname' => $rows->lastname,
'address' => $rows->address,
'city' => $rows->city,
'email' => $rows->email,
'phone' => $rows->phone,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
if ($rememberme == 'on') {
// create a cookie here with all data that i have put in session
}
return TRUE;
}
return FALSE;
}
}
Does creating cookie automatically creates session? or we have put these data in session manually again?
In CodeIgniter, you can use set_cookie()
$cookie = array(
'name' => 'The Cookie Name',
'value' => 'The Value',
'expire' => '86500',
'domain' => '.example.com',
'path' => '/',
'prefix' => 'myprefix_',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
First of all you need to load cookie helper
$this->load->helper('cookie');
Set your cookie
$cookie = array(
'name' => "cookieName",
'value' => array('id'=>$rows->id,
'firstname'=>$rows->firstname,
'lastname'=>$rows->lastname,
'address'=>$rows->address,
'city'=>$rows->city,
'email'=>$rows->email,
'phone'=>$rows->phone,
'logged_in'=>TRUE
) ,
'expire' => '86500',
);
Just pass your array into set cookie
$this->input->set_cookie($cookie);
And you can retrieve it using
$cookie['cookieName']['id'];
Also read manual
I am using web services to get the parameter from SOAP client successfully. I want to pass this parameters in url through html form so that i can connect to my system with this parameters. I have 2 functions. Function login() is to set the parameters for the connection from SOAP client and function getVehicle() to get this parameters. In getVehicle() i want to send the parameters user, hash password, dealer_number, corporate_group_id to client.php from url. And this parameters i want to send from form action without submit button.
index.php
function login()
{
$wsdl = 'http://www.schwackenet.de/awonline/de/service2/SNWebService.php?wsdl';
$options = array('trace' => true);
$params = array(
'user' => utf8_encode('deshmukh'),
'password' => utf8_encode('deshmukh'),
'corporate_group_id' => '101',
'dealer_number' => 'INT31303',
'dms_id' => 'A13T2D19',
'dms_image_url' => '',
'dms_keepalive_url' => '',
'dms_followup_url' => ''
);
$client = new SoapClient($wsdl, $options);
$result = $client->Login($params);
return $return;
}
if($parameter['aktion'] == 'getVehicle')
{
//var_dump(Login());
$vehicle=login();
$user_login=$vehicle['user'];
$password=$vehicle['password'];
$dealer_no=$vehicle['dealer_number'];
$group_id=$vehicle['corporate_group_id'];
//form action here
}
You can have the data transferred to your client.php as a GET request using the built-in php function file_get_contents() like this:
if ($parameter['aktion'] == 'getVehicle')
{
$vehicle=login();
$user_login=$vehicle['user'];
$password=$vehicle['password'];
$dealer_no=$vehicle['dealer_number'];
$group_id=$vehicle['corporate_group_id'];
// send the data to your system
$system_url = 'http://yoursite.com/path/to/client.php';
header("Location: $system_url?user=$user_login&password=$password&dealer_number=$dealer_no&corporate_group_id=$group_id");
exit();
}
If you want, you can have client.php reurn a "success" or "error" output and you'll have it on the $response variable and you can log it or do something else with it.
In your login() you are returning $return, that is wrong. You need to return $result, which is holding the result from curl request.
function login()
{
$wsdl = 'http://www.schwackenet.de/awonline/de/service2/SNWebService.php?wsdl';
$options = array('trace' => true);
$params = array(
'user' => utf8_encode('deshmukh'),
'password' => utf8_encode('deshmukh'),
'corporate_group_id' => '101',
'dealer_number' => 'INT31303',
'dms_id' => 'A13T2D19',
'dms_image_url' => '',
'dms_keepalive_url' => '',
'dms_followup_url' => ''
);
$client = new SoapClient($wsdl, $options);
$result = $client->Login($params);
return $result;
}
if($parameter['aktion'] == 'getVehicle')
{
$vehicle=login();
var_dump($vehicle);
}
Hello so here is the problem i have a login/register system and when the user creates his account a new folder gets created with same name as he puts username so if the username is test123 a folder test123 gets created. Now the problem is i dont know how to move files that user uploads with the upload system to his directory. And ofc user has to be loged in after he register to even upload files.
here is upload.php
<?php
if($_POST[submit]) {
$name = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
if($size <= 5000000){
move_uploaded_file($temp,"userfiles/$name");
echo "File: $name was uploaded!";
} else{
echo "Wrong size!";
}
} else {
header("Location: mojprofil.php");
}
?>
so actualy at the move_uploaded_file($temp, "userfiles/$name"); in the folder userfiles there is a folder for each user that registers
and here is the register.php:
<?php
require_once 'core/init.php';
if(input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array(
'required' => true,
'min' => 2,
'max' => 20,
'unique' => 'users'
),
'password' => array(
'required' => true,
'min' => 6
),
'password_again' => array(
'required' => true,
'matches' => 'password'
),
'name' => array(
'required' => true,
'min' => 2,
'max' => 50
)
));
if($validation->passed()) {
$user = new User();
$salt = Hash::salt(32);
try {
$user_dir = Input::get('username');
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'name' => Input::get('name'),
'joined' => date('Y-m-d H:i:s'),
'group' => 1
));
Session::flash('home', '<h3>Registracija uspešna!</h3>');
mkdir(__DIR__.'/userfiles/'.$user_dir);
Redirect::to('mojprofil.php');
} catch (Exception $e) {
die($e->getMessage());
}
} else {
foreach($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
In my experience, I've always used a full server path when setting an upload path to any given directory.
So instead of this:
move_uploaded_file($temp,"userfiles/$name");
Try this:
... $tmp_filename= $_FILES['yourFile]['tmp_name']
move_uploaded_file($tmp_filename,'/your/full/server/path/userfiles/'.$name);
Also, if your user has to be logged in, I'm assuming you might track their user id or something unique in some sort of session variable.
If you are setting the directory name based off of a _FILES variable, I think you might run risk of getting folder names that don't match user id/ username.
It would be better, in my opinion, to grab the username from some sort of query first to ensure everything matches. For example:
$username = get_user($_SESSION['user_id'); // returns user data -> id, username etc...
move_uploaded_file($tmp_filename,'/your/full/server/path/userfiles/'.$username);
That would give you something like:
/public_html/foo/bar/userfiles/username/
This is very, very rough but something along these lines:
$user_data = array();
$user_data['username'] = $_POST['username'];
...
...
// Logic to clean data before insert into DB.
$user = create_user($user_data); // Return username, id or something unique.
if ($user) { // This contains username or false
// Create directory with returned username then upload file
...
...
// Logic to prep the file for upload
move_uploaded_file($tmp_filename,'/your/full/server/path/userfiles/'.$user);
}
I'm create a remote access using codeigniter curl library from here https://github.com/philsturgeon/codeigniter-curl , then using this code below to login, then I get good respons that I've logged in.
$this->load->library('curl');
$opt = array(
'COOKIEJAR' => 'curl_sess/cookie.txt',
'COOKIEFILE' => 'curl_sess/cookie.txt',
);
$array = array(
'email' => 'user#example.com',
'password' => 'somepassword'
);
echo $this->curl->simple_post('http://remoteweb.com/cek_login', $array, $opt);
Then I want to create another request that need logged in status, like :
$array = array();
echo $this->curl->simple_get('http://remoteweb.com/get_datadeposit', $array);
but I get nothing, because my login session at first request not brought in second request.How to achieve this or I missing something ... ?
Try
$this->load->library('curl');
$opt = array(
CURLOPT_COOKIEJAR => 'curl_sess/cookie.txt',
CURLOPT_RETURNTRANSFER => true
);
$array = array(
'email' => 'user#example.com',
'password' => 'somepassword'
);
echo $this->curl->simple_post('http://remoteweb.com/cek_login', $array, $opt);