Page Redirect
Moderator: General Moderators
Page Redirect
I'm a novice at PHP, so be kind ...
I have an HTML page that captures a username/password and sends to a PHP page for processing. If all's well, the PHP sends the viewer to their desired page. Currently I'm using a javascript command for the page redirect, but when viewed on Mac using Firefox there's a 'jump' from the login page to the landing page. By jump I mean the page(s) actually shift side to side visually despite the table dimensions, etc of each page being identical. It's very distracting and unprofessional looking. I'm attempting, instead, to redirect using <?php header('Location:listing.html');?> but that's not working either. I've even tried calling the preceding as a function to no avail. Remember I'm a rookie so don't laugh, but here's the code I'm dabbling with ...
<?php
$pWord='password';
$uName='username';
$checkUName=$_POST['checkUName'];
$checkPWord=$_POST['checkPWord'];
$uNamePass=false;
$pWordPass=false;
echo "<p align='left' class='form'>Login<br>";
if($uName==$checkUName) {
$uNamePass=true;
echo "<input name='checkUName' type='text' id='loginfield' size='20' value='$uName' style='background-color:#ffffff'><br>";
} else {
echo "<input name='checkUName' type='text' id='loginfield' size='20' value='Incorrect Login.' onFocus='doClear(this)' style='background-color:#fdfcd4'><br>";
}
echo "Password<br>";
if($pWord==$checkPWord) {
$pWordPass=true;
echo "<input name='checkPWord' type='text' id='loginfield' size='20' value='$pWord' style='background-color:#ffffff'><br>";
} else {
echo "<input name='checkPWord' type='password' id='loginfield' size='20' onFocus='doClear(this)' style='background-color:#fdfcd4'><br><br>";
}
if($pWordPass && $uNamePass) {
echo "<script language='javascript'>window.location = 'listing.html'</script>";
/// ALTERNATELY I'VE TRIED ...
/// header('Location:listing.html');
}
?>
Anyone else run into this problem? Is it a javascript vs php redirect solution? Any assistance would be greatly appreciated. You can view the page live at http://www.cannedads.net/ShuklaSite/login.html. Username: username, Password: password.
Thanks in advance -
sleepydad
I have an HTML page that captures a username/password and sends to a PHP page for processing. If all's well, the PHP sends the viewer to their desired page. Currently I'm using a javascript command for the page redirect, but when viewed on Mac using Firefox there's a 'jump' from the login page to the landing page. By jump I mean the page(s) actually shift side to side visually despite the table dimensions, etc of each page being identical. It's very distracting and unprofessional looking. I'm attempting, instead, to redirect using <?php header('Location:listing.html');?> but that's not working either. I've even tried calling the preceding as a function to no avail. Remember I'm a rookie so don't laugh, but here's the code I'm dabbling with ...
<?php
$pWord='password';
$uName='username';
$checkUName=$_POST['checkUName'];
$checkPWord=$_POST['checkPWord'];
$uNamePass=false;
$pWordPass=false;
echo "<p align='left' class='form'>Login<br>";
if($uName==$checkUName) {
$uNamePass=true;
echo "<input name='checkUName' type='text' id='loginfield' size='20' value='$uName' style='background-color:#ffffff'><br>";
} else {
echo "<input name='checkUName' type='text' id='loginfield' size='20' value='Incorrect Login.' onFocus='doClear(this)' style='background-color:#fdfcd4'><br>";
}
echo "Password<br>";
if($pWord==$checkPWord) {
$pWordPass=true;
echo "<input name='checkPWord' type='text' id='loginfield' size='20' value='$pWord' style='background-color:#ffffff'><br>";
} else {
echo "<input name='checkPWord' type='password' id='loginfield' size='20' onFocus='doClear(this)' style='background-color:#fdfcd4'><br><br>";
}
if($pWordPass && $uNamePass) {
echo "<script language='javascript'>window.location = 'listing.html'</script>";
/// ALTERNATELY I'VE TRIED ...
/// header('Location:listing.html');
}
?>
Anyone else run into this problem? Is it a javascript vs php redirect solution? Any assistance would be greatly appreciated. You can view the page live at http://www.cannedads.net/ShuklaSite/login.html. Username: username, Password: password.
Thanks in advance -
sleepydad
Re: Page Redirect
How is the PHP redirect not working?
Re: Page Redirect
Try this man. As soon as you click submit (in firefox) click escape. You're gonna see that when it validates, your issue is kinda 2 fold. First of all, your if statement if($pWord==$checkPWord) { is ringing true. The reason I can tell is because your input type is changing from password to TEXT. So, right away, the application is trying to redraw with new input text boxes, and then before the table data can load 100%, it redirects to the next page.
To view what I'm talking about, right after if($pWord==$checkPWord) { , put exit; and view the output.
To view what I'm talking about, right after if($pWord==$checkPWord) { , put exit; and view the output.
Re: Page Redirect
You can't use header() if you've already echoed/printed something.
Re: Page Redirect
issue isn't with redirecting guys. the issue is that his center box jumps left and right, indicating a size change in the area that shows the form/page content. he's trying to figure out why it's jumping.
Re: Page Redirect
Thanks to all for the replies. Infolock, I used your suggestion about the time overlap of processing and moving to the landing page. I substituted a javascript delay of two seconds before the redirect, and it seems to have fixed it. Yeah, a cheesey solution I know but I'm up against the gun and need to get this posted. I'm sure as my studies in PHP evolve I'll go back and do it the right way. Thanks again to all. You can see the new, improved product at:
http://www.cannedads.net/ShuklaSite/login.html
sleepydad
http://www.cannedads.net/ShuklaSite/login.html
sleepydad
Re: Page Redirect
Very nice. Glad ya fixed it. I have a funny suspicion though like i said before is it's a part of the table not loading the data 100% . Either way, glad it worked (=
So I thought
Hi all - me again. The issue remains unresolved. For some reason the page continues jumping only when posted to www. Tested locally using Safari (I'm on Mac) and even using Firefox locally it works fine. Something about being posted to www. I have noticed that if I take out the mail() function I don't get the jumping -- all validation works fine with no jumping. When I put the mail() function back in, the sucker starts jumping on me again. Does that offer any clues?
Hellllpppp!!!! I'm running out of hairs to pull out!
Thanks -
sleepydad
Hellllpppp!!!! I'm running out of hairs to pull out!
Thanks -
sleepydad
Re: Page Redirect
The only reason I can think of why it would jump is because it's erroring out. have you tried putting an exit after the mail? Did you put an conditional around the mail?
Example:
otherwise, try putting some exit statements in the code until you find the culprit. i still think it's because of your if statements where you are testing the post. the process looks a little funky to me.
Example:
Code: Select all
if(false == mail($to, $from, $subject, $message, $headers)) {
echo "<br /><H3>AN ERROR HAS OCCURRED!</h3><br />";
}
exit;