1

I'm writing my first web application (still!), and have a problem activating user accounts.

The way I've got it set up is that the new user fills out a form with name, email address, and all that. They submit it, and my application sends a link to the email address they provide. They click that link, which passes (by way of a GET) a random code and their email address - activating their account.

In order to do some debugging, I thought I'd try this from different email services. Hotmail works, my own email works, but gmail doesn't. If you click on my 'activate' link in gmail, a 404 Not Found error pops up. So I've narrowed the problem down to how it encodes the link.

Here's the link in gmail (which doesn't work):

mywebsite.com/PHP+App+Files/App1/ln_activate.php?x=userx%40gmail.com&y=9c7b35bbdf1b0d24b0eda62f670c1456

When I change that one to this:

mywebsite.com/PHP%20App%20Files/App1/[email protected]&y=9c7b35bbdf1b0d24b0eda62f670c1456

... it does work. I can see what the differences are, but why does gmail do that, and does anyone have any suggestions for a workaround?

Thanks!

3
  • do you decode it back on your end? Commented Dec 8, 2010 at 1:24
  • how are you sending your email? Commented Dec 8, 2010 at 1:27
  • I don't decode it on my end, and I send it using phpmailer.... is that what you mean? Commented Dec 8, 2010 at 1:41

5 Answers 5

1

I bet the problem is that urlencode() translates spaces to + instead of %20. Call rawurlencode() instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Paul - one thing I'm going to try is to remove spaces. I thought I did, but missed some.
0

I suggest you NOT to use spaces in the name of folders in any webserver, I think this will solve your error 404 problem :

Rename PHP App Files into PHP_App_Files

Also I personnally don't like to use high caps as usually servers make the difference between low caps and high caps. But this is a personal habit.

You can also use urlencode() and urldecode() to process your URL parameters.

2 Comments

I think this is correct, and will try it later on this AM. Honestly, I thought I got rid of spaces.... but now that I look at it, I didn't.
This is really, really, not the correct solution to the problem. You are avoiding the fact that you are not escaping correctly by removing a known problematic input. The problem is, other problematic inputs exist, and sooner or later you may run into them.
0

Try base64 encoding the email address for the link in the email. Then, base64 decode it on the page that processes the verification.

1 Comment

Thanks - I'll read up on base64 encoding and see how it goes.
0

solution is

$url ="some url";
$encoded = urlencode($url);
$decoded = urldecode($encoded);

This is the perfect solution.

1 Comment

Thanks JapanPro. I've already got 'urlencode' in there, and I think the problem lies in the fact that I've got spaces in my path, which I shouldn't.
0

URL encoding in PHP is actually quite complicated.

There are several functions you need to know about in order to properly form a link in HTML: urlencode, rawurlencode, and htmlentities. Here's a rather contrived example of using all three:

<?php
    $query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
    echo '<a href="http://example.com/department_list_script/',
    rawurlencode('sales and marketing/Miami'),
    '?',
    htmlentities($query_string),
    '">';
?>

'; ?>

Your problem is being caused by improper encoding. Hopefully with this example and the PHP docs you can fix it!

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.