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

Yoast breadcrumb plugin showing 1
How to wrap element with another element with php
Using PHP as a Backend with Ember.js
Using array from header in another page
How to detect hashed password length? [closed]
Add data to multiple data fields
How to destroy the APC cache in YII
.val() not capturing the textbox value when button is clicked
PHP calling in more than 1 Tweet
PHPExcel - How to apply borders to dynamic range of cells loaded from mysql data
CodeIgniter Active record update not working
Creating MySQL leaderboard
JSON_BIGINT_AS_STRING removed in php 5.5?
Calling a Model Function in View?
PHP Regex: Extracting content from piped curly braces
Merge these array values into a new array?

Categories

HOME
jboss
openshift
extjs
eclipse-plugin
seedstack
kendo-dropdown
embedded-resource
semantic-web
gentelella
amp
ipv6
repair
phpseclib
bellman-ford
xades4j
nexus3
fireloop
parsley.js
watch-os-3
mahout-recommender
pinterest
android-contacts
cocos2d-android
activeadmin
bosun
restier
mod-wsgi
onchange
oracleforms
ccavenue
microprocessors
materialize
openbr
intune
autodesk-model-derivative
riotjs
knights-tour
char-pointer
des
mars-simulator
llvm-ir
google-prediction
sendinput
apache-toree
oracle-bmcs
absolute
adblock
windows-media-player
image-registration
nothing
uiautomatorviewer
ilrepack
amazon-elastic-beanstalk
simple-schema
.when
ltrace
email-injection
controllers
bigdecimal
s-function
always-on-top
yii2-model
currency-exchange-rates
ioctl
pack
cortana
servicestack-bsd
json-spirit
juniper-network-connect
espresso
unhandled
mutators
lifetime
libgcc
webautomation
prism.js
forceclose
miglayout
windows-taskbar
strcmp
hyphen
san
acitree
node.js-stream
.net-remoting
blobstorage
semicolon
cmath
xmlwriter
system-requirements
jquery-dialog
playorm
arrow
qt-mobility
sql-parametrized-query
servlet-container
channelfactory
turbine
mongrel
ninject-interception
explicit
firephp
autobench
stretchblt

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App