How to redirect to another page using PHP
That's the problem. I've outputted a bunch of information (including the HTML to build the login page itself). So how do I redirect the user from one page to the next?
This means your application design is pretty broken. You shouldn't be doing output while your business logic is running. Go an use a template engine (like Smarty) or quickfix it by using output buffering).
Another option (not a good one though!) would be outputting JavaScript to redirect:
<script type="text/javascript">location.href = 'newurl';</script>
Redirect to another page using PHP
You should user header Function:
header('location: file.php');
in your case:
header('location: /views/login.php');
visit Header Function
How can I redirect another page in php?
This will work if you haven't written anything on the page yet:
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
If you have, you'll have to use javascript for redirection:
<script>window.location.href = "http://www.yoursite.com/new_page.html";</script>
How to redirect user to another page using javascript in php?
Standard "vanilla" JavaScript way to redirect a page
You can use the code below to redirect the user after form submission code.
if( $mail_status ){
echo "
<script>
setTimeout(function() {
window.location = 'http://www.example.com/newlocation';
}, 2000);
</script>
";
}
MDN web docs on how setTimeout
works
Hope it helps!
How can I redirect a php page to another php page?
<?php
header("Location: your url");
exit;
?>
Related Topics
Correct Indentation of HTML and PHP Using Vim
Why, Fatal Error: Class 'Phpunit_Framework_Testcase' Not Found in ...
How to Execute Raw Queries with Laravel 5.1
Performance of Static Methods VS. Functions
Category Hierarchy (Php/Mysql)
How to Use Multi Auth in Laravel 5.2
How to Handle User Input of Invalid Utf-8 Characters
Phpmyadmin Automatic Logout Time
How to Access a Property of an Object (Stdclass Object) Member/Element of an Array
How to Downgrade or Install a Specific Version of Composer
Getting the Name of a Child Class in the Parent Class (Static Context)
PHP Cli Getting Input from User and Then Dumping into Variable Possible
How to Replace All Xhtml/HTML Line Breaks (<Br>) with New Lines