user3911182
user3911182

Reputation: 39

Redirect after successful registration

I have a registration wherein if successful it would redirect to a certain page. I'm having problem when a successful registration happens it would redirect to successReg.php my registration has a link that myurl/mobile/registration.php it should redirect to myurl/successReg.php instead what happens is it redirects to myurl/mobile/successReg.php which doesn't exist. So how can I make it to redirect at myurl/successReg.php?

Here is how I redirect when the registration is a success.

   echo ("<SCRIPT LANGUAGE='JavaScript'>            

   window.location.href='successReg.php';
          </SCRIPT>");

Upvotes: 0

Views: 1136

Answers (2)

BlindingLight
BlindingLight

Reputation: 151

Your main problem is that you specified a relative path. If your document root is myurl/ then Ben's solution is just fine, otherwise you should give the full path from your document root (like myurl/successReg.php).

If you want to accomplish this with javascript you can do:

window.location = '/successReg.php';

If you redirect with javascript without the starting / it's always relative to the current uri, so in you case it redirects to myurl/mobile/successReg.php if you are redirecting from myurl/mobile.

Check this for an article about relative and absolute paths: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

Upvotes: 1

Ben
Ben

Reputation: 9001

As long as headers haven't already been sent, you can use:

header('location: successReg.php');
exit;

PHP.net, W3S

Upvotes: 2

Related Questions