phpencodingbase64urlencodeurldecode

base64_encode() function is not working with equal to (==) operator.


$url = get_url(CONFIRM,base64_encode($_POST['status']."|".$agent_id));
ta_send_verification($_POST['email'],$_POST['agent_name'],$url);

I'm sending the profile confirmation mail to user profile. That mail contains activation url link. When I click that link I got this url

Wrong url

MlJPSEU0WEFKVlNZSFZFRFVXMlk1VVpUUTBIRk1KT0w0WDVBUzNVMnwyNA==

Correct url

MlJPSEU0WEFKVlNZSFZFRFVXMlk1VVpUUTBIRk1KT0w0WDVBUzNVMnwyNA

Second url is the correct one and it works fine too. But, In my activation link I always get the url with this == equal to symbol. I don't know how can I remove that == equal to symbol in my activation url link?


Solution

  • That's a default behaviour of the base64_encode() as == is nothing but padding.

    From the wikipedia of base64 encoding..

    The '==' and '=' sequence indicate that the last group contained only 8 or 16 bits, respectively.

    To remove that, simple do a str_replace() for the double equal symbol.

    $url = get_url(CONFIRM,base64_encode($_POST['status']."|".$agent_id));
    $url = str_replace('==','',$url);