edwardsmarkf
edwardsmarkf

Reputation: 1417

running another script inside of php

i have been using a php script to call the contents of an ordinary html file and display the contents like so:

echo file_get_contents('./login.html');

this has worked fine for a long time. however, login.html now needs to become a php script.

so, i need to have the php 'parent' script internally redirect to a php 'child' script, but retain the parent script name in the url.

i have tried the following so far:

1 - using "header":

header('Location: http://mydomain(dot)com/login.php');

this replaces the parent URL with the login script url which is unacceptable.

2 - window.location.href

<script type='text/javascript'>
window.location.href='http://mydomain(dot)com/login.php';
</script>

same problem as #1 - the parent URL is getting replaced.

3 - jquery load

$('#loginPage').load('http://mydomain(dot)com/login.php');

very close, but some of the jquery/css is getting lost along the way

4 - using iframe

<iframe frameborder='0' width='100%' height='100%' src= 'http://mydomain(dot)com/login.php'></iframe>

this actually displays properly, but window.location.href now contains the name of the child script, not the parent script.

i am sure there is a way to do this with minimal code. please let me know if this question is clear enough.

any suggestions?


edit:

my login.php page still needs to be able to be referenced as a stand-alone page as before.

Upvotes: 1

Views: 94

Answers (1)

Mihai P.
Mihai P.

Reputation: 9357

What you are looking for is include: http://php.net/manual/en/function.include.php
rename your html script to login.php then just use

include('./login.php'); 

where you want to in your main php script.

I am not sure what you are trying to do with your tests, in some cases 1,2 you are taking them to a new page, in others 3,4 you are embedding it in your page.

Upvotes: 3

Related Questions