Redirecting a page during an xmlRequest script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mherman3@gmail.com

    Redirecting a page during an xmlRequest script

    I have a page that sends a request to another PHP page on my site.
    If I try and set the header in the page that is being called, with
    header(Location : ...), the site doesn't get redirected like I'd like it
    to, it just writes a response to the original page. The response that
    it writes is the HTML of the page that I'd like the site to be
    redirected to.
    Is there a way that I can redirect from the script that is being called
    through an xmlRequest?
    Thanks a lot for any help.

  • Rik

    #2
    Re: Redirecting a page during an xmlRequest script

    mherman3@gmail. com wrote:[color=blue]
    > I have a page that sends a request to another PHP page on my site.
    > If I try and set the header in the page that is being called, with
    > header(Location : ...), the site doesn't get redirected like I'd like
    > it to, it just writes a response to the original page. The response
    > that it writes is the HTML of the page that I'd like the site to be
    > redirected to.
    > Is there a way that I can redirect from the script that is being
    > called through an xmlRequest?[/color]

    This is logical, and has more to do with javascript then PHP:
    1. You make a request using js.
    2. Requested page is a PHP-script.
    3. PHP-script answers that requests should be redirected to other page.
    4. javascript requests the page where it is redirected to, as it should, and
    prints it on the current page.

    If there is a possibility you get content, and not just redirects, from the
    PHP page, ask in a javascript group how to achieve this.

    If the request is dependant on other javascript actions, ask in a javascript
    group how to achieve this.

    If the script in questions only redirects, and the request isn't dependant
    on other js actions/functions: don't use javascript, just link to the
    script.

    Grtz,
    --
    Rik Wasmus


    Comment

    • ImOk

      #3
      Re: Redirecting a page during an xmlRequest script

      Are you by any chance writing anything prior to the header()?

      Even a blank line prior would invalidate the header() and the bnrowser
      would just display it.

      Comment

      • Herman

        #4
        Re: Redirecting a page during an xmlRequest script

        So then is this script illegal? If so, how do you redirect a page after
        you check to see if the user is logged in?

        <?php

        if ($_SESSION['cmpid'] == '')
        header('Locatio n: http://campaigns.hoopl ah.ca/Host/noCampaign.htm' );
        else
        $cmpid = $_SESSION['cmpid'];

        ?>

        Comment

        • dimo414

          #5
          Re: Redirecting a page during an xmlRequest script

          That scropt looks legal, but you have to make sure it comes before
          ANYTHING being written or sent to the browser.

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: Redirecting a page during an xmlRequest script

            Herman wrote:[color=blue]
            > So then is this script illegal? If so, how do you redirect a page after
            > you check to see if the user is logged in?
            >
            > <?php
            >
            > if ($_SESSION['cmpid'] == '')[/color]

            Use isset() for safe.

            --
            <?php echo 'Just another PHP saint'; ?>
            Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

            Comment

            Working...