How can i get my current full path? (and use it in the header)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sims

    How can i get my current full path? (and use it in the header)

    Hi,

    I have a few 'secure' area where the user needs to log-in b4 they can make
    view it.
    I know how to redirect them to the login page but how can I return them to
    the page they were?

    if I get the path ...and save it, (in a cookie or in MySQL ).

    $ReturnUrl = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];

    the path is relative to the root directory,
    (http://uk.php.net/reserved.variables).

    And then try and use it (b4 all the headers are sent).

    header( 'refresh: 20; url='.$ReturnUr l );

    It does not work properly, ( the query strings is truncated). if I place it
    in quotes then the system adds http:\\ in the string.

    What is the best way to return to a page full path, (including the query
    string).

    Many thanks Sims


  • Andreas Paasch

    #2
    Re: How can i get my current full path? (and use it in the header)

    Attempting to reach the Kolinahr, Sims wrote:
    [color=blue]
    > Hi,
    >
    > I have a few 'secure' area where the user needs to log-in b4 they can make
    > view it.
    > I know how to redirect them to the login page but how can I return them to
    > the page they were?
    >
    > if I get the path ...and save it, (in a cookie or in MySQL ).
    >
    > $ReturnUrl = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
    >
    > the path is relative to the root directory,
    > (http://uk.php.net/reserved.variables).
    >
    > And then try and use it (b4 all the headers are sent).
    >
    > header( 'refresh: 20; url='.$ReturnUr l );
    >
    > It does not work properly, ( the query strings is truncated). if I place
    > it in quotes then the system adds http:\\ in the string.
    >
    > What is the best way to return to a page full path, (including the query
    > string).
    >
    > Many thanks Sims[/color]

    $_SERVER["HTTP_REFER ER"] might be what you are looking for.

    /Andreas

    --
    #Peace and long life ...
    Registeret Linux user #292411


    Comment

    • Sims

      #3
      Re: How can i get my current full path? (and use it in the header)

      >[color=blue]
      > $_SERVER["HTTP_REFER ER"] might be what you are looking for.
      >
      > /Andreas
      >[/color]

      According to the manual that value might not be set. So I cannot rely on it.

      "HTTP_REFER ER

      The address of the page (if any) which referred the user agent to the
      current page. This is set by the user agent. Not all user agents will set
      this, and some provide
      the ability to modify HTTP_REFERER as a feature. In short, it cannot really
      be trusted."



      Sims


      Comment

      • Markus Ernst

        #4
        Re: How can i get my current full path? (and use it in the header)

        "Sims" <siminfrance@ho tmail.com> schrieb im Newsbeitrag
        news:c6ikdh$c6e nj$1@ID-162430.news.uni-berlin.de...[color=blue]
        > Hi,
        >
        > I have a few 'secure' area where the user needs to log-in b4 they can make
        > view it.
        > I know how to redirect them to the login page but how can I return them to
        > the page they were?
        >
        > if I get the path ...and save it, (in a cookie or in MySQL ).
        >
        > $ReturnUrl = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
        >
        > the path is relative to the root directory,
        > (http://uk.php.net/reserved.variables).
        >
        > And then try and use it (b4 all the headers are sent).
        >
        > header( 'refresh: 20; url='.$ReturnUr l );
        >
        > It does not work properly, ( the query strings is truncated). if I place[/color]
        it[color=blue]
        > in quotes then the system adds http:\\ in the string.
        >
        > What is the best way to return to a page full path, (including the query
        > string).
        >
        > Many thanks Sims
        >[/color]

        I usually do things like that without a login page but by including the
        login form into every page that requires login:

        <?php

        $logged = false;

        if(isset($_POST['login'])) {
        if([check for correct username and password here]) {
        [write cookie here];
        $logged = true;
        }
        else {
        $message = "Incorrect login, try again!";
        $logged = false;
        }
        }

        else if([check for cookie]) {
        $logged = true;
        }

        ?>
        <html>
        <head>
        </head>
        <body>
        [put navigation or whatever comes before the contents here]
        <div id="contents">
        <?php

        if(!$logged) {
        if(isset($messa ge)) echo "<p><strong>".$ message."</strong></p>";
        include("mylogi nform.php");
        }

        else {
        ?>
        [put page contents here]
        <?php
        }
        ?>
        </div>
        [put footer or whatever comes after the contents here]
        </body>
        </html>

        Like that you don't have redirection problems, and the user that does not
        have access to the protected area will not be taken out of his navigation
        flow.

        HTH
        Markus


        Comment

        • Sims

          #5
          Re: How can i get my current full path? (and use it in the header)

          [color=blue][color=green]
          > > Hi,
          > >
          > > I have a few 'secure' area where the user needs to log-in b4 they can[/color][/color]
          make[color=blue][color=green]
          > > view it.
          > > I know how to redirect them to the login page but how can I return them[/color][/color]
          to[color=blue][color=green]
          > > the page they were?
          > >
          > > if I get the path ...and save it, (in a cookie or in MySQL ).
          > >
          > > $ReturnUrl = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
          > >
          > > the path is relative to the root directory,
          > > (http://uk.php.net/reserved.variables).
          > >
          > > And then try and use it (b4 all the headers are sent).
          > >
          > > header( 'refresh: 20; url='.$ReturnUr l );
          > >
          > > It does not work properly, ( the query strings is truncated). if I place[/color]
          > it[color=green]
          > > in quotes then the system adds http:\\ in the string.
          > >
          > > What is the best way to return to a page full path, (including the query
          > > string).
          > >
          > > Many thanks Sims
          > >[/color]
          >[/color]

          Thanks all for the replies,

          Just as an aside, the reason my header(... ) was not working was because I
          was replacing the '&' with the html equivalent &amp;

          Sims


          Comment

          Working...