how to redirect in PHP

  • JackDaRippaZ
  • Newbie
  • Newbie
  • JackDaRippaZ
  • Posts: 11

Post 3+ Months Ago

hey guys
i was wondering if anyone knows how to redirect in PHP

ie, i want to check if a username and password match
so essentially code would be like:

In a page called login.htm

IF username and password match
go to (or redirect) to validaccount.php
ELSE
go to (or redirect) to incorrectlogin.php

thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Tdotwire
  • Proficient
  • Proficient
  • User avatar
  • Posts: 486
  • Loc: Toronto

Post 3+ Months Ago

here is your php code;

<?

if (($username && password) == true)
{
header("location: validaccount.php");
}
else
{
header("location: incorrectlogin.php");
}

?>

just make sure that this script file is in the same directory as the other two php files. If not then you should know how to make the right paths.

Another way that I do that is

<?

if (($username && password) == true)
{
include "account.php";
exit();
}
else
{
include "incorrectlogin.php";
exit();
}

?>

I think that that is a better way to redirect.
But do what you want to do
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

The default redirect function for php is

PHP Code: [ Select ]
<?php
 
header("Location: <!-- m --><span class="postlink">http://www.example.com/</span><!-- m -->");
 
exit;
 
?>
  1. <?php
  2.  
  3. header("Location: <!-- m --><span class="postlink">http://www.example.com/</span><!-- m -->");
  4.  
  5. exit;
  6.  
  7. ?>


But this won't work in your case most probably, as it should come up with a header already sent warning.

Echo javascript to for what you want to accomplish.


PHP Code: [ Select ]
<?
 
echo "<script type='text/javascript'>";
 
echo "document.location.href='http://www.quantumcloud.com/'";
 
echo "</script>";
 
?>
  1. <?
  2.  
  3. echo "<script type='text/javascript'>";
  4.  
  5. echo "document.location.href='http://www.quantumcloud.com/'";
  6.  
  7. echo "</script>";
  8.  
  9. ?>


Also your page obviously cannot be called login.htm to use php!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 88 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.