Sign in to follow this  
namingway

[web] php redirection

Recommended Posts

I need to redirect the page once the user logs in, at the moment I'm using <? if($redirect == true) echo("<meta http-equiv='Refresh' content='5;url='index.php?page=home'>"); ?> The problem is that it just refreshs the login.php page. Are there any better ways of getting it to redirect? Also how to you link to other pages with the <button> tag? [Edited by - namingway on April 21, 2008 12:32:40 AM]

Share this post


Link to post
Share on other sites
have you tried the "header"-command?
e.g. header(Location:index.php?page=home);
put there may not be any output before it, like an "echo" or something.

if i would like to link with a button, i'd try a small form with action=target.php without anything but a submit-button.

Share this post


Link to post
Share on other sites
when you submit your login form you after you check to see if the login was valid and before you output anything to the browser ie. <html><head> etc..

you can do that header() or meta refresh tag.

as for a "button" without a form you can do something like:
<input type="button" value="Some Link" onClick="window.location.href='http://www.google.com'" />

or with a form using:
<form method="link" action="somepage.html">
<input type="submit" value="Some Link" />
</form>

Share this post


Link to post
Share on other sites
This is a PHP function I wrote, which I use on almost all PHP sites I work on.


function Redirect($whereTo)
{
if (empty($whereTo) || !is_string($whereTo))
$whereTo = $links['error']['pageFail']; // Change this to your own error page URL
if (!headers_sent())
header('location: '. $whereTo);
else
{
?>
<script language="javascript" type="text/javascript">
document.href.location = '<?php echo $whereTo ?>';
</script>
<?php
}
die();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by namingway
I need to redirect the page once the user logs in, at the moment I'm using
<?
if($redirect == true)
echo("<meta http-equiv='Refresh' content='5;url='index.php?page=home'>");
?>

The problem is that it just refreshs the login.php page. Are there any better ways of getting it to redirect?

Also how to you link to other pages with the <button> tag?


The reason the login page is getting refreshed is that this content='5;url=' is what is in your content tag. Remove the quote that follows the url= and it will work properly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this