How to Write on page after Redirecting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirtan007
Forum Newbie
Posts: 2
Joined: Sat Jun 06, 2009 1:30 am

How to Write on page after Redirecting

Post by kirtan007 »

i wan to redirect user to index.php page if login was not successfull and after redirecting i want to write on that page "Invalid Password"

How do i accompnish that task

??

i have coded this

Code: Select all

if ( $rownum > 0)
{
 
 
header('Location:google.com');
}
else 
{
header('Location:index.php');
echo '<font color=red>Invalid Password</font>';
}
 
Last edited by Benjamin on Sat Jun 06, 2009 1:37 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: How to Write on page after Redirecting

Post by jayshields »

Use something to persist the state. Sessions will probably be a good route.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to Write on page after Redirecting

Post by mikemike »

Or use GET to pass a value onto your forwarded page:

Code: Select all

# if ( $rownum > 0)
 {
    header('Location:google.com');
 } else {
    header('Location:index.php?msg=Invalid+password');
 }
In index.php:

Code: Select all

<?php
echo '<span style="color:red;">'.$_GET['msg'].'</span>';
?>
Can I point out though that you're use of redirects is wrong. The 'Location' header requires an absolute URL. Where most browsers do accept this, it's still wrong.
kirtan007
Forum Newbie
Posts: 2
Joined: Sat Jun 06, 2009 1:30 am

Re: How to Write on page after Redirecting

Post by kirtan007 »

Thank you Vry much for helping :)
Post Reply