How can I redirect using a PHP script called from an SSI?

578 views Asked by At

On a WAMP server, I have a server-side include in a file, a.shtml, composed of the following code:

<!--#include virtual="./req.php"-->

The contents of req.php are:

<?php
Header("Location:index.php");
echo "still here";
?>

When I open a.shtml, I see the text still here, but the page has made no attempt to redirect itself. Why is this? And is there any way to make it work?

Thanks for the help

EDIT: The reason I want to do this is because I have some session variables that I want to influence the way the PHP script acts. If the session variables are not set, I need it to redirect to a login page. I know I can just write the entire thing in PHP, but I'd like to do it this way if possible. If it's not possible to change header information from an included PHP file from SSI, then I'll just do it entirely in PHP.

3

There are 3 answers

5
Your Common Sense On BEST ANSWER
  1. it's impossible

  2. you don't need that.

just address tour script that set session variables directly, not through ssi

1
Gelmir On

MAYBE (with capital letters Lol), you can pull this off if you call that script in an IFRAME and that IFRAME outputs some JScript like window.parent.location = <some_url_here> forcing its parent to change its location... Its just fast-thinking from my part, I might be wrong with IFRAMEs' parent-child relation to the original document, as I haven't tested the "idea" myself :)

0
Petrus On

If your req.php returns the following html code, the redirect will happen:

<html><head>
<title>HTTP 301 This page has been moved</title>
<meta http-equiv="Refresh" content="0;URL=https://www.example.com/index.php">
</head>
<body></body></html>

But: "Google Warning: Using The Meta Refresh Tag Is Bad Practice"