PHP goto another web page automatically after login?
Moderator: General Moderators
PHP goto another web page automatically after login?
I have created the login part, but how do I redirect the user to another web page after the user have login? Any help or examples would appreciated. Thanks.
Re: PHP goto another web page automatically after login?
Hi mike!
There are a few ways to go about redirection, however the most popular of the two are:
Meta refresh.
301 redirect.
What is the difference? Well I can't speak to much on it because I do not yet know a lot about SEO. But the 301 redirect is more vital when dealing search engines. (Kind of like a permanently moved webpage that still retains its link popularity.)
I will read more up on it, as should you.
Anyway, the META refresh:
Where content="3 is in seconds
The 301 redirect:
There are a few ways to go about redirection, however the most popular of the two are:
Meta refresh.
301 redirect.
What is the difference? Well I can't speak to much on it because I do not yet know a lot about SEO. But the 301 redirect is more vital when dealing search engines. (Kind of like a permanently moved webpage that still retains its link popularity.)
I will read more up on it, as should you.
Anyway, the META refresh:
Code: Select all
<meta http-equiv="refresh" content="3; url=http://www.example.com">The 301 redirect:
Code: Select all
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>Re: PHP goto another web page automatically after login?
Thanks for the quick reply. Unfortunately, I have tried the 2 below already:
1-Meta refesh is in html so I don't think I can have if statements with it.
2-I use the 301 refresh code and it doesn't seem to work at all. I'm not sure if it have somethign to do with the PHP version or where I'm placing the code at?
1-Meta refesh is in html so I don't think I can have if statements with it.
2-I use the 301 refresh code and it doesn't seem to work at all. I'm not sure if it have somethign to do with the PHP version or where I'm placing the code at?
-
dwightlathan77
- Forum Newbie
- Posts: 3
- Joined: Thu Jul 31, 2008 11:14 pm
Re: PHP goto another web page automatically after login?
My understanding is that the redirects should be before any html. You can break the code apart from the html by placing it along with the form validation script. The user would click login, it validates and send them to the content page, or back to the login page.
When you say it's in the html I'm guessing your writing a welcome screen that would acknowledge login. in that event you could just use a permanent link and verify that the session is set when they try to enter the content page.
When you say it's in the html I'm guessing your writing a welcome screen that would acknowledge login. in that event you could just use a permanent link and verify that the session is set when they try to enter the content page.
Re: PHP goto another web page automatically after login?
Mike,
Code: Select all
<head>
<?php
if (condition is met) {
echo "<meta http-equiv=\"refresh\" content=\"3; url=http://www.example.com\">";
} else {
// do w/e you want
}
?>
</head>
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: PHP goto another web page automatically after login?
Code: Select all
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
Re: PHP goto another web page automatically after login?
Hi mikeguan,
The following code worked for me.
This will redirect you to the page 'http://www.yoursite/index.php'.
Thanks
The following code worked for me.
Code: Select all
print "<script>";
print " self.location='http://www.yoursite/index.php';";
print "</script>";
Thanks
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: PHP goto another web page automatically after login?
Keep in mind that the javascript code will only work in browsers that have JS enabled. I would not rely on that. A simple header() with an exit() after it will suffice. And I think the location header directive throws a 301 automatically. If not, you can send that header too before sending the location header.
Re: PHP goto another web page automatically after login?
Hi Everah,
I used
But it is not redirecting, just it stays in the same page.
Could you please explain, why it is so ?
I used
Code: Select all
<?php
header("Location: http://www.mysite.org");
exit();
?>
Could you please explain, why it is so ?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: PHP goto another web page automatically after login?
Make sure you have no other output (not even an empty space or line) before the header call. Check your error logs for "Headers already sent" error messages or turn on display_errors to see if there is output being sent before the call.