8

all, I'm having a problem with my wordpress page while using encrypted $_GET parameters to obtain data. this is my function:

function encryptDecrypt($key, $string, $decrypt)
{
    if($decrypt)
    {
        $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "6");
        return $decrypted;
    }else{
        $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
        return $encrypted;
    }
}

I'm using the registered user's mail to encrypt it and to retrieve his data using $_GET parameter. The problem is that if i use the normal email address (not encrypted, which it will be quite useless and dangerous) the $_GET request works. If i use an encrypted email, I only get a 404 Error.

This is what I've tried so far:

$m=urlencode(encryptDecrypt('mail',$mail,false));    
$msg.="<br><a href='siteurl/pageurl/?m=".$m."'>Click here</a>";

Example of encrypted mail which is used in the URL to send data:

VOvk4Wh%2FpMzm21lQNrFnvBcwRWLw6ZVPOMe0VCi2t3g%3D

and, in the "retrieving" page:

urldecode($_GET['m']);

Example of encrypted mail which is used in the URL to retrieve data:

VOvk4Wh/pMzm21lQNrFnvBcwRWLw6ZVPOMe0VCi2t3g=

When i open the "receiving" page with that link i get the 404 Error

UPDATE+

I've solved the problem, which was the 'm' as $_GET parameter, which is a wordpress's default taxonomy... Thanks to you all for helping me. :)

4
  • Did you add a Query Var for it? codex.wordpress.org/Function_Reference/add_query_arg
    – MikeGWP
    Commented Dec 3, 2014 at 15:22
  • Should I use it? That page is only intended to be a "black-on-white" page with some text to be printed... The funny thing is that if i write siteurl/pageurl/?m=fooor ?m=bar or ?m=wololoooo it works... Commented Dec 3, 2014 at 15:34
  • 1
    I've found the problem! Commented Dec 3, 2014 at 15:37
  • I just had the same problem but I was using ?name=. You can find a list of all the reserved terms here
    – DazBaldwin
    Commented Dec 24, 2018 at 15:33

3 Answers 3

9

As the OP found out, m is a reserved parameter name that should be use only by core (indicates month). Solution is to use some other parameter name (always use your own prefixes in all global contexts!).

2
  • 1
    Many of us discover this the hard way ;-)
    – birgire
    Commented Jan 20, 2018 at 17:34
  • 2
    I just found out that year is also reserved...
    – joehanna
    Commented Nov 17, 2019 at 8:05
2

I just found out I had a post_type with the same name as the query string.

For instance, if you had a post_type called news, this query string would return a 404: ?news=foo, even if you have pretty permalinks enabled.

You can either rename the post type or the query string.

0

first off; turn the wp_debug function on if you haven't already. (wp_config.php). This should give you some additional error data. Secondly; it looks like you are using urldecode, but not encoding your string. If you're including an email address be sure to urlencode your data as well.

7
  • i use urlencode to write the string on the a tag's href and then, on that page, i use urldecode to retrieve the original string... By the way, if I get a 404 Error the problem should be on the "link writing" function, or am I missing something? WP_DEBUG is already enabled Commented Dec 3, 2014 at 10:58
  • Hi sorry, I overlooked that. The solution is easier I think :) If the link you posted is the code you are really using then the problem lies with the quote '"'. <a href="siteurl/page/?m="<?php echo urlencode(encryptDecrypt('mail',$mail,false)); ?>"> you are closing the quotes when addding the php part. Commented Dec 3, 2014 at 11:05
  • try: <a href="siteurl/page/?m=<?php echo urlencode(encryptDecrypt('mail',$mail,false)); ?>"> Commented Dec 3, 2014 at 11:05
  • Isn't it the same thing as I've done so far? Commented Dec 3, 2014 at 11:34
  • In your code there is a closing double quote (") after ...?/m". This says that your url ends there. However, in your link there is more to come. Check the source code of the link in your browser. It will look messed up. Commented Dec 3, 2014 at 12:04

Your Answer

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

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