Drupal URL Encoding

I am having trouble correctly encoding the URL data. Using the following code:

$redirect = drupal_urlencode("user/register?destination=/node/1");
drupal_goto( $redirect );

but the url that appears in my browser test is the following:

http://testsite.com/user/register%253Fdestination%253D/node/1

I thought using the drupal_urlencode function should fix this encoding issue. Can someone suggest a way to fix this, please?

+5
source share
3 answers

You better use the built-in function url()to create your url, if you pass the array as query, it processes you the url:

$options = array(
  'absolute' => TRUE,
  'query' => array('destination' => '/node/1')
);
$redirect = url('user/register', $options);

drupal_goto( $redirect );

drupal_encode() will encode the entire string that you pass to it, so if you want to do it your own way, it will look like this:

$redirect = 'user/register?' . drupal_urlencode("destination=/node/1");
drupal_goto( $redirect );     
+3
source

The easiest way to do this in Drupal 6:

drupal_goto("user/register","destination=/node/1");
+2
source

The following code from Clive worked for me.

    $options = array(
  'absolute' => TRUE,
  'query' => array('destination' => '/node/1')
);
$redirect = url('user/register', $options);

drupal_goto( $redirect );
0
source

All Articles