That is because you have an output:
?> <?php
results in blank line output.
header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP
Combine all your PHP codes and make sure you don’t have any spaces at the beginning of the file.
also after header('location: index.php');
add exit();
if you have any other scripts bellow.
Also move your redirect header after the last if
.
If there is content, then you can also redirect by injecting javascript:
<?php echo "<script>window.location.href='target.php';</script>"; exit; ?>
Related Posts:
- How to fix “Headers already sent” error in PHP
- PHP page redirect
- How to fix “Headers already sent” error in PHP
- Returning JSON from a PHP Script
- Returning JSON from a PHP Script
- How do I make a redirect in PHP?
- List of All Locales and Their Short Codes?
- Whoops, looks like something went wrong. Laravel 5.0
- PHP “or” Syntax
- PDOException SQLSTATE[HY000] [2002] No such file or directory
- How do I check if a string contains a specific word?
- Get the full URL in PHP
- Invalid column count in CSV input on line 1 Error
- How to copy a file from one directory to another using PHP?
- How to check if a string starts with a specified string?
- How can I find my php.ini on wordpress?
- mysqli_real_connect(): (HY000/2002): No such file or directory
- PHP + curl, HTTP POST sample code?
- How to call a JavaScript function from PHP?
- Error 500: Premature end of script headers
- Cookies vs. sessions
- $wpdb->update or $wpdb->insert results in slashes being added in front of quotes
- PDO with INSERT INTO through prepared statements
- How to get the file extension in PHP?
- Are there dictionaries in php?
- Multiple file upload in php
- laravel updateOrCreate method
- How to listen messageSent event in laravel 5.5
- When should I use ‘self’ over ‘$this’?
- php create object without class
- Creating a search form in PHP to search a database?
- How do I make a simple crawler in PHP?
- Create PDF file using PHP
- pdo – Call to a member function prepare() on a non-object
- Sort array of objects by object fields
- Compare given date with today
- When to generate a new Application Key in Laravel?
- “Connection for controluser as defined in your configuration failed” with phpMyAdmin in XAMPP
- Multi-line strings in PHP
- Commands out of sync; you can’t run this command now
- Call to undefined method mysqli_stmt::get_result
- cURL error 60: SSL certificate: unable to get local issuer certificate
- retrieve data from db and display it in table in php .. see this code whats wrong with it?
- Count how many files in directory PHP
- php refresh current page?
- Simple PHP calculator
- What does it mean to escape a string?
- Convert from MySQL datetime to another format with PHP
- Creating default object from empty value in PHP?
- php foreach with multidimensional array
- Send attachments with PHP Mail()?
- PHP Error: Function name must be a string
- Uncaught Error: Call to undefined function mysql_escape_string()
- Warning: mysqli_query() expects at least 2 parameters, 1 given. What? [duplicate]
- PHP cURL custom headers
- Parsing domain from a URL
- PHP class not found but it’s included
- How to fix the session_register() deprecated issue?
- Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201:
- How to convert string to boolean php
- PHP “&” operator
- Are There Any Cron Jobs Alternative?
- How to Create Multiple Where Clause Query Using Laravel Eloquent?
- PHP: How to get referrer URL?
- What is ?
- Connection reset by peer: mod_fcgid: error reading data from FastCGI server
- Warning: A non-numeric value encountered
- How to import csv file in PHP?
- What is the syntax for accessing PHP object properties?
- Proper Format of iframe in PHP?
- How to find the last day of the month from date?
- php_network_getaddresses: getaddrinfo failed: Name or service not known (0) Failed To Connect..!
- Composer: Command Not Found
- * failed to open vchiq instance
- Undefined variable: $_SESSION
- Mysql where id is in array
- How to extract and access data from JSON with PHP?
- Warning “Do not Access Superglobal $_POST Array Directly” on Netbeans 7.4 for PHP
- Notice: Undefined offset: 0 in
- How to Sort a Multi-dimensional Array by Value
- How to get time difference in minutes in PHP
- How to write a link like which link to the same page in PHP?
- Call a REST API in PHP
- Fatal error: Call to a member function query() on null
- How can I write php code in notepad++?
- How to run a PHP function from an HTML form?
- How to use data-saferedirecturl in a tag in PHP?
- How to insert TIMESTAMP into my MySQL table?
- Remove warning messages in PHP
- PHP date yesterday [duplicate]
- Clear cache in Symfony: `cache:clear` or `rm -rf`?
- create php live clock
- Converting a UNIX Timestamp to Formatted Date String
- PHP Call to undefined function
- Formatting a number with leading zeros in PHP
- Undefined index with $_POST [duplicate]
- file_get_contents() how to fix error “Failed to open stream”, “No such file”
- POST an array from an HTML form without javascript
- wordpress menu dropdown item not showing after first dropdown