[web] php redirection

Started by
5 comments, last by ID Merlin 16 years ago
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]
Advertisement
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.
Yeah I tried
if($redirect == true)
header("Location:index.php?page=home");

but it said cannot modify header information - headers already sent by (header.php in login.php on line 31.
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>
You should probably use output buffering. It's generally a useful thing, and it prevents errors like this.
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="&#106avascript" type="text/&#106avascript"&gt;<br>					document.href.location = '&lt;?php echo $whereTo ?&gt;';<br>				&lt;/script&gt;<br>			&lt;?php<br>		}<br>		die();<br>	}<br></pre>
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.

This topic is closed to new replies.

Advertisement