php


How do I prevent an included PHP script from changing the Location URL?


I'm including a PHP script that changes the URL.
// index.php
ob_start();
include "script.php";
// This script redirects using header("Location:");
$out = ob_get_clean();
// I use the $out data for calculations
echo $out;
Is there a simple way to counter or undo this unwanted redirect? How about:
header("Location: index.php"); // redirect back to self
But this causes an endless redirect loop... any ideas?
Or is there a way to strip out the header() calls from the $out buffer, preventing it from ever reaching the client?
Just for future references. As of PHP 5.3 there's a new function called header_remove() which helps dealing with such situations.
You could try to overwrite that header field with an invalid value, such as:
header('Location: ', true);
But I don’t know how the clients react on that.
There isn't really a good way to do that. Two things come to mind:
Open script.php as a text file, strip out any header() commands and then eval() the result.
Echo a space before you include script.php and then trap the warning that PHP generates about issuing a header() after the output has already started. You'd need to echo the space before your output buffering.
What about including the file first as a variable with file_get_contents(), stripping out the unwanted headers and then running it with PHP code (I won't mention the evil word used to parse a PHP string as PHP code)?
If you don't have PHP5.3 at your disposal (you probably don't), Gumbo's answer does not work and you don't want to use eval, then the only other option I can see, is the use of streams. This is however yet another, more flexible but complex, form of eval. Streams, combined with tokenizer, and you'll be able to get rid of that function call with a simple:
require 'no-header://script.php';
Since you have the complete text in a string before you output it, you can simple remove the headers you want with a search and replace (using a regex for example).

Related Links

how to convert a json_encoded data to an associative array in php?
Mysql character set decoding from utf8_unicode_ci to shift jis
Managing Locale in Laravel 5.2, local not setting
Grab tag styling with php domxpath
Magento | Currency switcher not working when product is already in cart
Can php session_set_cookie_params and setcookie be used in different instances or does 1 override the other
Sum user working time in a given MySQL table
How do I reorganize an array in PHP?
Php code not updating the Database [duplicate]
Cant find a way to send bcc on this script
Can't change PHP variables in Joomla docker official container
How to measure requests per user and minute
php regex from java regex
Laravel relation table user and adress
After importing mySql database i have Strange Characters in database text: Ã, Ã, ¢, â‚ €
PHP email issue only working within my domain

Categories

HOME
firebase
mc
automapper
gaming
shinyapps
vagrant
android-fragments
opencv-python
initialization
openlayers-3
tabs
repair
ui-automation
mithril.js
heuristics
csrf
vimeo
angular4
mailgun
dma
fresco
twisted
rest-assured
robolectric
android-custom-view
uislider
jpa-2.1
pubxml
onchange
amazon-cloudtrail
region
guice
publishing
advanced-filter
nest
keyboard-layout
uivisualeffectview
rdp
microkernel
jacoco-maven-plugin
klee
hdiv
fluid-mac-app-engine
react-intl
audio-converter
music21
aws-kinesis-firehose
android-5.0-lollipop
sony-future-lab-n
sharpdx
embedded-v8
watir-webdriver
mura
asp.net-web-api-routing
alertify
gmaps.js
degrees
email-injection
allegro
scheduledexecutorservice
streamwriter
clp
livecycle
xcode8-beta4
dpkg
android-sdcard
vimperator
json-spirit
smart-tv
decidable
directx-9
chicagoboss
knife
apple
gql
darwin
abstract-factory
quercus
symja
cakephp-2.2
qt5.4
stripe.net
django-sites
autonumber
infinite
django-facebook
insertion
reentrancy
xmlwriter
tridion-2011
chronometer
getopt-long
websphere-6.1
flymake
algol68
fbml
django-apps
expression-web
sql-parametrized-query
dip
anonymous-types
raw-data
.net-services
server-load
remote-working
community-server
webclient.uploaddata

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App