1

I am trying to extract two values from the url with Jinput.

My url is:

http://localhost/kitchen-guide-new/index.php?option=com_content&view=article&id=45?subscribers_e[email protected]&subscribers_name=test&encoding=UTF-8

I am using the following code:

$jinput = JFactory::getApplication()->input;
$name = $jinput->get('subscribers_name','none','raw');
$email = $jinput->get('subscribers_email','none','raw');

echo $name;
echo $email;

The problem is that I only get the last value; in other words I'm getting:

$name = 'test';
$email = 'none'; // (should be [email protected])

Any idea what I am doing wrong and how I should fix it?

2 Answers 2

1

I guess your problem is that second question mark, the link should be

http://localhost/kitchen-guide-new/index.php?option=com_content&view=article&id=45&subscribers_e[email protected]&subscribers_name=test&encoding=UTF-8

1

Your malformed url querystring is to blame -- specifically the second ? which should be &.

Demo:

$url = 'http://localhost/kitchen-guide-new/index.php?option=com_content&view=article&[email protected]&subscribers_name=test&encoding=UTF-8';

parse_str(parse_url($url, PHP_URL_QUERY), $array);

var_export($array);

Output:

array (
  'option' => 'com_content',
  'view' => 'article',
  'id' => '[email protected]',
  'subscribers_name' => 'test',
  'encoding' => 'UTF-8',
)

You see, the querystring parsing is dependent on the first occurring ? to dictate the start of the data. The key-value pairs are bound together with = and are separated from other pairs by &.

As a consequence of your typo, the subscribers_email key and value are appended to the id value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.