I'm trying to following a youtube tuts for make a login system on CodeIgniter.
I was pretty new on php framework and I choose CI for its semplicity.
So I have an array where I need to store session data:
$data = array('email' => $this->input->post('email'),
is_logged_in' => true);
the tutorial use userdata(); function with
$this->session->userdata($data);
but when he try to print de session array do:
print_r($this->session->all_userdata($data));
alluserdata(); is deprecated, so I read the doc, and I found out that userdata is a legacy function.
I want to learn what I write so I try to modernize the code to be updated and clean for CI3.
is use userdata(); good for CI3? or I have to use $_SESSION[]? or $this->session?
The problems is that if I try to use
$this->session->data
and than:
print_r($this->session->data);
I have nothing in output.
I just want to output data array in session so I can understand if it's working.
Thank you in advance
EDIT
if i use set_userdata() for set session and just print_r($this->session->userdata()); for print session all I have is:
Array
(
[__ci_last_regenerate] => 1453313633
[email] => admin#admin.com
[is_logged_in] => 1
)
and not info about browser, time ecc...is that normal?
Set session data
$newdata = array('email' => $email, 'is_logged_in' => true);
$this->session->set_userdata($newdata);
Get session data
$email = $this->session->userdata('email');
$is_logged_in = $this->session->userdata('is_logged_in');
OR
$dataArray = $this->session->userdata();
In Codignitor 3 you can get values from $this->session obejct as:
//Normal PHP
$name = $_SESSION['name'];
// IN Ci:
$name = $this->session->name
// you can also get by
$name = $this->session->userdata('name');
And whats wrong with your code?
You are using session object as
$this->session->data
This should be
$this->session->userdata
is use userdata(); good for CI3? or I have to use _SESSION[]?
For this, yes it's better to use framework libaray becuase you can manage and reuse your code easily.
Related
i try to fetch result from www.tadawul.com.sa with php soap client.
but when i try to load that , get nothing just loading page.
here is my code.
$reference = array(
'companyId' => '*********',
'secureKey' => '*********'
);
$client = new SoapClient('http://www.tadawul.com.sa/Tadawul_WebAPI/services/GetDetailQuote?wsdl');
$response = $client->getDetailQuoteForCompany($reference);
var_dump($response);
I think the problem is in the structure you need to pass a getDetailQuoteForCompanyRequest Object not an array
Why don't you use wsdl2phpgenerator
It'll make you life easier, You need to pass wsdl file and it will generate all the classes that you need
Instead of this
$response = $client->getDetailQuoteForCompany($reference);
Try
$response = $client->__soapCall("getDetailQuoteForCompany", array($reference));
hi i have a php web that return json data usin json!encode but when i change it from GET to POST it return null
<?php
header('Content-Type: application/json; charset=utf-8');
include('settings.php');
mysql_connect($host,$user,$password);
mysql_select_db($base);
mysql_query('SET CHARACTER SET utf8');
$login = $_GET['login'];
$password = $_GET['password'];
$req = "select * from user WHERE username = '".$login."' and password = '".$password."'";
$sql=mysql_query($req);
$nn=mysql_num_rows($sql);
$items = array("items" => NULL);
while ($data=mysql_fetch_array($sql))
{
$items["items"][] = array(
"id" => $data['id'],
"username" => $data['username'],
"password" => $data['password'],
"nom_prenom" => $data['nom_prenom'],
"nom_prenom_arabe" => $data['nom_prenom_arabe'],
"specialite" => $data['specialite'],
"specialite_arabe" => $data['specialite_arabe'],
"adresse" => $data['adresse'],
"adresse_arabe" => $data['adresse_arabe'],
"telephone_cabinet" => $data['telephone_cabinet'],
"gsm" => $data['gsm'],
);
}
echo json_encode($items,JSON_UNESCAPED_UNICODE);
?>
it returns
{"items":[{"id":"2","username":"**","password":"*","nom_prenom":"****","nom_prenom_arabe":"مهذب عبد الصمد ","specialite":"Pediatrie","specialite_arabe":"إختصاصي في الامراض النفسية و العصبية","adresse":"Av tahar sfar imm .El BARAKA sousse 4000","adresse_arabe":" 4000 شارع طاهر سفر عمارة البركة سوسة","telephone_cabinet":"73698521","gsm":"25631478"}]}
but with
$login = $_POST['login'];
$password = $_POST['password'];
it return
{"items":null}
can anyone explain to me why :) thanks
Because the post that invoke this page has a GET method , so remplace it with POST then it will work as expected.
another point is it's discouraged to use string concatenation when quering databases due to security risk. use prepared statements instead.
First of: For the love of.. Clear text password and no request validation?
Please before you do anything at all, read up about sql injections and why clear text is BAD, really really bad.
Now to you question.
The $_GET arrays contains query parameters ex (?test=test) on GET METHOD calls to the server. GET is the basic HTTP call and tells the server you want to read a page.
IN OLD TIME :
The $_POST array contains post parameters on POST METHOD calls. POST is used when you want to update or add information on the server. This is usually called from a html form.
W3School have a guide on HTTP Method calls here.
BUT NOW WITH AJAX AND THE NEW FEATURES OF HTML5 :
YOU CAN USE THE 'POST' TO GET DATA.
THE PROBLEM HERE IS THE SECURITY OF THE NAVIGATORS LIKE FIREFOX AND CHROME;
THE SOLUTION :
Modify the cors http : in the server PHP add this in first of your page php:
//Part added by ilyas :
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
//End of part.
how do i use getLastError() within php to check if my save method is inserting to mongo?
i set up my db as follows:
$this->databaseEngine = $app['mongo'];
$this->db = $this->databaseEngine->dbname;
$this->collection = $this->db->collectionname;
my insert query then looks like this:
$query = array(
'fieldname' => $fieldname
);
$this->collection->insert($query);
I want to then use getLastError() to check whether it is inserting correctly, and if not why. but im not sure how to implement it.
do i use after the insert:
$this->collection->getLastError("what goes here?");
cheers.
Update
i eventually used this to get the last error:
echo '<pre>' . print_r($this->databaseEngine->lastError(), true) . '</pre>';
Sammaye's way works just as well, see below.
$this->collection->getLastError("what goes here?");
Nothing goes there, the return of the getLastError is the last error from MongoDB ( http://www.php.net/manual/en/mongodb.lasterror.php ). Also it is used on the MongoDB class (atm).
You don't have to use it like that, instead you can do:
$this->collection->insert($query, ARRAY('safe' => TRUE));
This will return an array from the function detailing whether or not it actually inserted. The details of the array can be found by reading this page:
http://www.php.net/manual/en/mongocollection.insert.php
I am creating a 3D Secure PHP Project. I am having a rather bizzare issue in that the "MD" code is going missing when re-submitting the Array of data
My code is as follows :
$paRes = $_REQUEST['PaRes'];
$md = $_REQUEST['MD'];
require "payment_method_3d.php";
x_load('cart','crypt','order','payment','tests');
/*
* For Debugging Purposes
* Only.
echo "The Value Of PaRes is : ";
echo $paRes;
*/
$soapClient = new SoapClient("https://www.secpay.com/java-bin/services/SECCardService?wsdl");
$params = array (
'mid' => '',
'vpn_pswd' => '',
'trans_id' => 'TRAN0095', // Transaction ID MUST match what was sent in payment_cc_new file
'md' => $md,
'paRes' => $paRes,
'options' => ''
);
It seems that the $_REQUEST['MD'] string seems to go missing AFTER the soap call. Although I am having difficulty print this out to the screen. The strange thing is the $paRes variable works without issue.
Any ideas why this would be the case?
Check your case. PHP array keys are case sensitive. From this little bit of code it looks as if the request variable may be 'md' instead of 'MD'.
Try $md = $_REQUEST['md'];
PHP array statements are case sensitive, so this should work:....
$md = $_REQUEST['md'];
Thanks for your responses guys.
What was happening was the include page was sitting in front of the request methods and causing issues loading the REQUEST methods to the page.
I am using PHP5 and Codeigniter to connect to a .NET web service through SOAP requests. I'm having trouble making an update to that dataset. This is my first experience working with Codeigniter (although doesn't factor here much), SOAP, PHP SimpleXML class, and .NET web services in general. For example, this is to update a user profile. I don't have any problems getting responses but I'm unsure how to update this based on the user's edits to the profile.
My string from the dumping request is this (Note: I'm concerned with the 0, which is the start of the dataset. The 1111 is username and the next 1111 is a password)
11111111 0RandyFloydGM1955-11-05T00:00:00-04:00317787129131789770001910 E. Markwood AvenueIndianapolisIN46227falsefalse
This gives me a 400 Bad Request error. It seems obvious that is due to the space between the 0 and the last 1. By doing htmlspecialchars() I see that it looks like it is the xml declaration isn't needed.
<?xml version="1.0"?> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml- msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><dsEmployee xmlns="http://SHSSrv/dsEmployee.xsd"><Employee diffgr:id="Employee1" msdata:rowOrder="0"><EmplId>0</EmplId><FirstName>Randy</FirstName><LastName>Floyd</LastName><MI>G</MI><Sex>M</Sex><DOB>1955-11-05T00:00:00-04:00</DOB><HomePhoneArea>317</HomePhoneArea><HomePhone>7871291</HomePhone><WorkPhoneArea>317</WorkPhoneArea><WorkPhone>8977000</WorkPhone><Address1>1920 E. Markwood Avenue</Address1><Address2/><City>Indianapolis</City><St>IN</St><ZIP>46227</ZIP><ReceiveNewsLetter>false</ReceiveNewsLetter><PagerArea/><PagerNo/><EmailAddress>randy#test.com</EmailAddress><SpanishContact>false</SpanishContact></Employee></dsEmployee></diffgr:diffgram>
Taking the original response and just sending it back as update works like this.
111111110RandyFloydGM1955-11-05T00:00:00-04:00317787129131789770001910 E. Markwood AvenueIndianapolisIN46227falsefalse
And with htmlspecialchars() looks like this (No XML declaration):
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml- msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><dsEmployee xmlns="http://SHSSrv/dsEmployee.xsd"><Employee diffgr:id="Employee1" msdata:rowOrder="0"><EmplId>0</EmplId><FirstName>Randy</FirstName><LastName>Floyd</LastName><MI>G</MI><Sex>M</Sex><DOB>1955-11-05T00:00:00-04:00</DOB><HomePhoneArea>317</HomePhoneArea><HomePhone>7871291</HomePhone><WorkPhoneArea>317</WorkPhoneArea><WorkPhone>8977000</WorkPhone><Address1>1920 E. Markwood Avenue</Address1><Address2/><City>Indianapolis</City><St>IN</St><ZIP>46227</ZIP><ReceiveNewsLetter>false</ReceiveNewsLetter><PagerArea/><PagerNo/><EmailAddress>randy#test.com</EmailAddress><SpanishContact>false</SpanishContact></Employee></dsEmployee></diffgr:diffgram>
Here is the code:
function employee_update_request()
{
ini_set( 'soap.wsdl_cache_ttl' , 0 );
//Get XML from the Employee Profile Request
$response = $this->employee_profile_request();
//Turn the string into an object to manipulate
$dataset = simplexml_load_string($response->any);
//Manipulate some data from the update form
$dataset->dsEmployee->Employee->EmailAddress = "randy#test.com";
$dataset->dsEmployee->Employee->Address1 = "1920 E. Markwood Avenue";
$any = $dataset->saveXML();
//Add back the string to the original response object returned from web service
$response->any = $any;
//Get username and password for the params
$username = $this->session->userdata('username');
$password = $this->session->userdata('password');
$params = array('sUserId' => $username, 'sPassword' => $password, 'dsEmployee' => $response);
//SOAP Options
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=> 0,
'trace'=> 1,
'uri' => "http://www.w3.org/2003/05/soap-envelope"
);
//New soap client with options
$client = new SoapClient('http://localhost/SHSSRV/SHSSrv.asmx?WSDL', $options);
//Request the employee profile fromt the webservice, passing in credentials
$update_request = $client->EmployeeUpdateRequest($params);
$update_response = $update_request->EmployeeUpdateRequestResult;
return $update_response;
}
I really need help, I need to figure out how best to make updates to this data. Am I able to get the declaration stripped out somehow, or should I request that the .NET web service be changed in some way? I don't have access directly to that but I can talk to the developer if there is a better way all together.
Thanks!
I've solved this by doing this. I'd love to know if there is a better way though.
$no_xml_doctype = str_replace('<?xml version="1.0"?>' , '' , $any);
$trimmed = trim($no_xml_doctype);
$response->any = $trimmed;
//Get username and password for the params
$username = rtrim($this->session->userdata('username'));
$password = rtrim($this->session->userdata('password'));
$params = array('sUserId' => $username, 'sPassword' => $password, 'dsEmployee' => $response);