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_email=test@gmail.com&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 test@gmail.com)

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

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_email=test@gmail.com&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&id=45?subscribers_email=test@gmail.com&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' => '45?subscribers_email=test@gmail.com',
  '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, privacy policy and cookie policy

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