PHP页面重定向将目标页面添加到当前页面的底部

PHP页面重定向将目标页面添加到当前页面的底部

问题描述:

I've got a registration page and a landing page, when the register button is pressed it activates a JS function in an external JS file (reg.js) that then runs reg.php, like so:

reg.html->reg.js->reg.php

If the registration succeeds it is supposed to redirect to a landing page (landing.php) but instead it is just appending the landing page to the bottom of the current page(reg.html), like so:


Register
[register button]


Landing
[landing page text]

The redirection code is:

 header('Location: landing.php');

From the sounds of it, you're posting via AJAX to a php script to process. PHP would then need to send some sort of success response back to the AJAX—something like:

if (registered) {
  header(201); // http response code for "created"
}

The AJAX callback would see that success, and then you would redirect the user client-side:

$.post().success(function() { window.location = '/landing.php'; });

<?php
if(registered)
{
  header( 'Location: /landing.php' ) ;
}

?>

or try to input the whole url.

Are you using javascript ajax ? If yes then you need to use

window.location = 'http://webiste.com';

If your javascript submits the form then you need to use header in PHP code like this:

header( 'Location: http://website.com/landing.php' ) ;

Don't forget to add http:// in the redirect url as this may be causing an issue.