Window Name in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Window Name in PHP

Post by phppage »

Could any one tell me how I could retrieve the name of the window as a PHP variable. I want to ensure the user is visiting the page through the correct window that is opened and configured via JS. And so ensure the user has not opened the URL via a history link or other means.

Many Thanks for your time.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Impossible. You have absolutely no control over the user.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You can talk to the window that opened a window via the "opener" object. Once there you could talk to the server using Ajax.
(#10850)
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Post by phppage »

Not sure if I have confused the matter too much here please let me clarify.

A user clicks on a link that excutes a bit of JS that opens a window called popadmin say. In this window a certain php page is opened. What I would like is to say in my PHP script If the window is not called popadmin then redirect to another page. The only problem I have in doing this is getting the PHP script to know what the window name is that it is being run in.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You would need to use Ajax to do that. Once the PHP page is loaded, some javascript would communicate with the PHP page (or another PHP page) a second time to verify the page name. If it is determined to be not valid, then use javascript to redirect or change the page contents. There are probably other ways to achieve a similar result using opener checks instead.
(#10850)
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Post by phppage »

arborint wrote:You would need to use Ajax to do that. Once the PHP page is loaded, some javascript would communicate with the PHP page (or another PHP page) a second time to verify the page name. If it is determined to be not valid, then use javascript to redirect or change the page contents. There are probably other ways to achieve a similar result using opener checks instead.
Your Right!

Long time since I worked with JS in any great detail but opener dose what I want. Many thanks for your time and help! :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

instead of using the window title to identify server side behavour use a get variable that goes directly to the server in the first place.

Code: Select all

var sToOpen = 'somepage.php?action=redirect'; // this string can be built by whatever js you like
window.open(sToOpen); // or whatever the args for that function are
then in somepage.php

Code: Select all

<?php
// this page generates the title based on the get var
switch($_GET['action']) {
   case 'redirect': {
       $title = 'Redirecting...Please wait';
       break;
   }
   default: $title = 'Untitled';
}
?>
<html>
  <head>
    <title><?php echo $title?></title>
    ...
and so on and so forth. A lot easier than creating the title on the client and AJAXing back to PHP
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Post by phppage »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Im sorry Ole, I don't understand how that would work. Some of the pages have GET data in them with certain combinations deleting data. With this in mind I want to prevent the user from clicking their history links and inevertently deleting data by accident.

I used the following script below but relised I had a flaw.

[syntax="javascript"]    if (opener) {
if (opener.location.href != "http://www.somedomain.com/folder/page.php") {
window.location="http://www.google.com";
}    } else {
   window.location="http://www.google.com";
   }
I dont echo any HTML or JS till the PHP script deletes the data on the SQL database so the page dose not redirect till the damage is done. The page works in the following way.

URL is entered into a normal page or clicked on the history link by the user.
From the GET data in the URL the PHP scripts runs deleting the data and by PHP header is redirected back to the same page but different GET data, this time round HTML and JS is echoed and so users is redirected by the script above instead of getting the delete confirm screen.

You may look at the above and think I need to rewrite my PHP using a different method of confirming deletes rather than using GET data but I would like to avoid the user opening the page in the wrong window anyway so really think I need a PHP solution to this rather than JS. Could any one give any AJAX and PHP pointers for this or any good tutorials.

Many Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Some of the pages have GET data in them with certain combinations deleting data.
That kind of data should probably be POST. And there is no reason why you can't add one other bit called action telling PHP what it is supposed to to.

Like so many I think you are going about this the wrong way. But hey I don't know the full story so I'll give you the benefit of the doubt.
Try this http://www.xul.fr/en-xml-ajax.html
Post Reply