Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Host of parent frame in PHP

Posted on 2002-06-12
1
Medium Priority
?
376 Views
Last Modified: 2008-02-01
Hi,

I have one index.php as parent frame with an top.php, menu.php and an main.php

The index.php is on server A and the other pages on server B. In the page main.php I want to show the host name where index.php is, in this case server A. The reason why I want this is that there is also an index.php on server C and main.php must show in different ways, denpend if he is frame in from the index.php from server A or C. It can be done with JavaScript but can it be done with PHP?


Jeffeny
0
Comment
Question by:harryv
1 Comment
 
LVL 7

Accepted Solution

by:
axis_img earned 600 total points
ID: 7074883
Once the page is rendered, you will not be able to get the hostname from one of the pages in the frameset without using a client-side language such as javascript (which you already mentioned). Since PHP is server-side, it is already parsed by the time the frame pages are loaded, so you cannot dynamically grab this information once they are loaded.

A work-a-round for what you need would be to simply pass the hostname to the frame pages when they are loaded inside the frameset. Here is what I mean:

** index.php [on server A] **
<html>
<head>
</head>

<frameset rows="100,*,100">
  <frame src="top.php?host=<?=$_HTTP_SERVER_VARS['SERVER_NAME']?>">
  <frame src="main.php?host=<?=$_HTTP_SERVER_VARS['SERVER_NAME']?>">
  <frame src="menu.php?host=<?=$_HTTP_SERVER_VARS['SERVER_NAME']?>">
</frameset>
</html>

** END **

So basically it just passes the host in the query string to those scripts that are getting loaded in the frameset.

This is just a pseudo-example just to give you an idea of how you can pass that value to your scripts. If you are using PHP4.1 or above, you can change the $HTTP_SERVER_VARS to $_SERVER. ie: $_SERVER['SERVER_NAME'].

If this does not fully answer your question, please let me know and I will try to assist further.

Regards,
Barry
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question