NYCPHP Meetup

NYPHP.org

[nycphp-talk] More Client-Side Grief

Adam Fields fields at surgam.net
Tue Oct 29 17:08:25 EST 2002


On Tue, Oct 29, 2002 at 04:36:20PM -0500, Hans Zaunere wrote:
> After picking bits from each post, I've finally done something like:
> 
> -- the PHP script that handles the form POST prints this to the popup:
> 
> <script language="JavaScript">
>    if( opener ) {
>       opener.location.assign('<?=$next?>');
>       opener.location.reload(true);
>       window.close();
>    } else {
>       window.location.assign('<?=$next?>');
>    }
> </script>

I have one further enhancement to suggest, drawn from a function I use
elsewhere. In the latter case, if the headers have not yet been sent,
you'll want to use PHP to generate a redirect header for you instead
of loading the page and redirecting with javascript. This is basically
what I'm thinking, although I have yet to test it to see if it works
consistently:

--------------------

function REDIRECT ($url) 
{
  if (substr($url, 0, 7) != 'http://') {
    if (substr($url, 0, 1) == '/') {
      $url = 'http://'.$_SERVER['HTTP_HOST'].$url;
    } else {
      $url = 'http://'.$_SERVER['HTTP_HOST'].'/'.$url;
    }
  }
  if (!headers_sent()) {
    header('Location: '.$url);
  } else {
    print '<script>';
    print "location.href='".$url."';";
    print '</script>';
  }
}

> where $next is where I want the main browser window to go.  I had
> considered passing the next URL in through the JavaScript call to
> create the popup (and this does seem to give the most flexibility), but
> really wanted to maintain my redirects from the server (I have a DB of
> "if posted from there, you now go here" that changes frequently).  This
> isn't as direct as sending a HTTP header, but heck, it seems to work
> (and still covers non-popups).

I got most of the functionality of my session-based jumpback stack
working today. Don't know if that'll help you at all.

> Ideally, I would have wished there was a way to read the HTTP headers
> sent from PHP into JavaScript/JScript and then act on them.  Supposedly
> there is
> (http://msdn.microsoft.com/workshop/author/dhtml/reference/constants/response_headers.asp)
> but as with so much client-side, I could never get them to do anything.
> :)
> 
> Thanks again,
> 
> H
> 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> HotJobs - Search new jobs daily now
> http://hotjobs.yahoo.com/
> 
> 
> --- Unsubscribe at http://nyphp.org/list ---
> 
> 
> 

-- 
				- Adam

-----
Adam Fields, Managing Partner, fields at surgam.net
Surgam, Inc. is a technology consulting firm with strong background in
delivering scalable and robust enterprise web and IT applications.
http://www.adamfields.com



More information about the talk mailing list