Get url parameter in cakephp 1.2.4.8284 - php

I am using cake php version 1.2.4.8284
I have url like below
http://www.example.com/users/index/filter:/site:917+919/
But when i print this url in users controller with 'print_r($this->params);'
I get result like below.
Array
(
[pass] => Array
(
)
[named] => Array
(
[filter] =>
[site] => 917 919
)
[controller] => users
[action] => index
[plugin] =>
[url] => Array
(
[ext] => html
[url] => users/index/filter:/site:917 919/
)
[form] => Array
(
)
[isAjax] =>
)
Here you can see + is missing from 'site' and 'url'.
But I want exact url and site value. Please Help.

Your URL must be encoded to get the actual symbol.
http:www.example.com/users/index/filter:/site:917%2B919/

The + character represents a space in a URL so print_r($this->params) is returning the correct value. If you want your url to include an actual + character you need to URL encode it as %2B; so your URL would be:-
http:www.example.com/users/index/filter:/site:917%2B919/
You might want to take a look at the PHP docs about urlencode.

Related

JSON Encode specific datatypes

I have a PHP Array which looks like this:
[0] => Array
(
[label] => Standard Stop
[code] => 5
[excludeIF] => [miniTrack, isTriangleHanger, tubeTrack, boxTrack]
)
[1] => Array
(
[label] => Soft Stop With Lag
[code] => 7
[excludeIF] => [miniTrack, isTriangleHanger, tubeTrack, boxTrack]
)
When I do a json_encode it generates something like this:
{"label":"Standard Stop","code":"5","excludeIF":"[miniTrack, isTriangleHanger, tubeTrack, boxTrack]"}
The problem with that encode is that it's making the code a string and it's also making the excludeIF a string.
code needs to be a float
excludeIF needs to be an array
Is something like that possible with JSON Encode?

How to retrieve an array in URL?

Trying to get data following a shopping cart purchase on the success page but having issues with $_GET. The URL is:
http://domain.com/success.php?customer[email]=email%40gmail.com&order[button][description]=music+download&order[button][id]=89765464465423184847654556&order[button][name]=music&order[button][repeat]=&order[button][resource_path]=%2Fv2%2Fcheckouts%2F9db9d0ef-9cfd-52b9-b2d7-792683d2431d&order[button][subscription]=false
How can I parse the data from this in PHP?
If you print_r $_GET variable, then it will produce output:
Array
(
[customer] => Array
(
[email] => email#gmail.com
)
[order] => Array
(
[button] => Array
(
[description] => music download
[id] => 89765464465423184847654556
[name] => music
[repeat] =>
[resource_path] => /v2/checkouts/9db9d0ef-9cfd-52b9-b2d7-792683d2431d
[subscription] => false
)
)
)
That means you can access your data via $_GET['customer']['email'] and $_GET['order']['button']['description'] etc..
In your example, you are using what is called a query string. In order to retrieve the information from the query string, the $_GET super global exists and you can use it as follows:
$customer_email = $_GET['customer']['email'];
$order_button_description = $_GET['order']['button']['description'];
$order_button_id = $GET['order']['button']['id'];
// etc.
Let me know if that helps.

how to get session variable value in php?

Inside my code i can see one session and once i printed that session i got following things in view source
Array
(
[Config] => Array
(
[time] => 1406983421
[timeout] => 10
)
[loggedIn] => 1
[user] => Array
(
[User] => Array
(
[id] => 424
[correspondence_email] =>
[terms] => Y
[old_facebook] =>
[[old_twitter] =>
[gmail_email] =>
[login_count] => 9
[last_secdeg_updated] => 2014-08-01 08:47:35
)
)
)
then i tried this line to get the value of "login_count"
echo "value".$this->Session->read("login_count");
but am not able to see this the "login_count" in echo.
am getting only this result in viewsource
value
How do i get "login_count" vale to a variable.?
echo $this->Session->read('user.User.login_count');
I hope this helps you.
Without seeing the code that writes the session, I am suspecting that this is what you're looking for:
echo $this->Session->read('user.User.login_count');
You dont have to create any codes to perfom session operations.They are already built in the cake php api.You just need to read and write the sessions from the link i given below.
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html Used in Controllers
http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html Used in Views

How to pull out certain value using php and this output

I've come across a weird scenario I do not know how to code around. I'm creating a JSON API for a wordpress site. I'm using the Connections plugin and trying to pull out the "original" image filename. The output of my sql command is this:
{
["options"]=>
string(396) "a:4:{s:5:"entry";a:1:{s:4:"type";s:12:"organization";}s:5:"group";a:1:{s:6:"family";a:0:{}}s:4:"logo";a:2:{s:6:"linked";b:0;s:7:"display";b:0;}s:5:"image";a:3:{s:6:"linked";b:1;s:7:"display";b:1;s:4:"name";a:4:{s:9:"thumbnail";s:25:"invoicelogo_thumbnail.jpg";s:5:"entry";s:21:"invoicelogo_entry.jpg";s:7:"profile";s:23:"invoicelogo_profile.jpg";s:8:"original";s:24:"invoicelogo_original.jpg";}}}"
}
}
I'm using the following command to acquire that:
querystr = "SELECT options FROM {$wpdb->prefix}connections WHERE id= '{$_GET['companyID']}'";
$options = $wpdb->get_results($querystr);
I'm not sure how to pull out the "original" part of this code though as it's not all that organized. Any help would be appreciated.
What you are seeing is the results of a php serialize call
To get at the original name just do this.
$decodedOptions = unserialize($options);
$original = $decodedOptions["image"]["name"]["original"];
Hope that helps
As a side note the deserialized data looks like
Array
(
[entry] => Array
(
[type] => organization
)
[group] => Array
(
[family] => Array
(
)
)
[logo] => Array
(
[linked] =>
[display] =>
)
[image] => Array
(
[linked] => 1
[display] => 1
[name] => Array
(
[thumbnail] => invoicelogo_thumbnail.jpg
[entry] => invoicelogo_entry.jpg
[profile] => invoicelogo_profile.jpg
[original] => invoicelogo_original.jpg
)
)
)

Named parameters being passed as part of the url because of slashes

I am using cakephp 1.3 and i want to search a record which contain / in string.
i have passed parameter as below.
Search params are as below.
Array
(
[controller] => indents
[action] => admin_index
[named] => Array
(
[pr_no_data] => pr
)
[pass] => Array
(
[0] => no
[1] => dip
[2] => 002
)
[prefix] => admin
[admin] => 1
[plugin] =>
[form] => Array
(
)
[url] => Array
(
[url] => admin/indents/index/pr_no_data:pr/no/dip/002
)
[isAjax] =>
)
as you all can see my url params contain admin/indents/index/pr_no_data:pr/no/dip/002 and now i want to search pr_no as defined in url.
How can i do this.?
because search for / record passing values as passed parameter.
Please help me.
Thanks a lot.
As you can see in your array, CakePHP sees part of the data as passed parameters. In the pr_no_data named variable, you see it references pr as it's value.
[named] => Array
(
[pr_no_data] => pr
)
However, the remaining character string in the data is recognized as passed parameters because of the slashes. So it is reading them as part of the URL, not the pr_no_data variable.
[pass] => Array
(
[0] => no
[1] => dip
[2] => 002
)
What you need to look at is how you generate that variable before it is added to the URL. Perhaps you can change it to a pipe | separated list or a comma , separated list so it does not interfere with the URL and confuse cakephp.
pr|no|dip|002
pr,no,dip,002
Once cakephp receives the data, you can then convert them back to slashes if needed:
$passed = preg_replace('/,/', '/', $this->params['named']['pr_no_data']);
Try to encode the named parameter value using urlencode.
The URL should be
admin/indents/index/pr_no_data:pr%2Fno%2Fdip%2F002
If you create the URL using the Html helper, then CakePHP should encode the value for you.
echo $this->Html->url(array(
'prefix'=>'admin',
'controller'=>'indents',
'action'=>'index',
'pr_no_data'=>'pr/no/dip/002'
));

Categories