Aren't session variable preserved using "Header('Location: xxx')"?

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

    #1

    Aren't session variable preserved using "Header('Location: xxx')"?

    I am trying to pass some info to another page on my site. I set
    "session_start( )" in page 1, assign a session variable to a value, then
    execute a "header('Locati on: ....')." But on the target page I don't get
    any session variable values! BTW, I used a relative location in the
    Location header, not an absolute URL. The behavior looks like it started
    another session, but it should not have.

    Ideas?

    TIA,

    Larry Woods


  • d

    #2
    Re: Aren't session variable preserved using "Header('L ocation: xxx')"?

    "lwoods" <larry@lwoods.c om> wrote in message
    news:RPqzf.8953 $JT.6285@fed1re ad06...[color=blue]
    >I am trying to pass some info to another page on my site. I set
    >"session_start ()" in page 1, assign a session variable to a value, then
    >execute a "header('Locati on: ....')." But on the target page I don't get
    >any session variable values! BTW, I used a relative location in the
    >Location header, not an absolute URL. The behavior looks like it started
    >another session, but it should not have.
    >
    > Ideas?[/color]

    Before the header("locatio n: "), call session_write_c lose().

    That gave me some serious headaches with mac-based browsers hanging.
    Terrible stuff :)

    Oh, and you should always use absolute URLs with location. Relative ones do
    work, but that's not guaranteed. You could make a function like this to
    take care of that for you:

    function bounce($url) {
    if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url;
    session_write_c lose();
    header("Locatio n: ".$url);
    exit();
    }

    or just use that one :-P
    [color=blue]
    > TIA,
    >
    > Larry Woods
    >[/color]


    Comment

    • lwoods

      #3
      Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

      Thanks, but I still can't get it to work. Check the following:

      Originating Page:

      <?
      if($_POST['repost']=='y') {
      session_start() ;
      $_SESSION['xxx']='test';
      session_write_c lose();
      header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
      exit();
      }
      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitl ed Document</title>
      </head>
      <body>
      <form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
      <input type="submit" name="submit" value="Submit" />
      <input type="hidden" name="repost" value="y" />
      </form>
      </body>
      </html>

      Target Page - testsess2.php:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitl ed Document</title>
      </head>

      <body>
      <?
      echo "xxx=".$_SESSIO N['xxx'];
      ?>
      </body>
      </html>

      Try these pages and see if they work for you....

      Larry Woods

      "d" <d@example.co m> wrote in message
      news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...[color=blue]
      > "lwoods" <larry@lwoods.c om> wrote in message
      > news:RPqzf.8953 $JT.6285@fed1re ad06...[color=green]
      >>I am trying to pass some info to another page on my site. I set
      >>"session_star t()" in page 1, assign a session variable to a value, then
      >>execute a "header('Locati on: ....')." But on the target page I don't get
      >>any session variable values! BTW, I used a relative location in the
      >>Location header, not an absolute URL. The behavior looks like it started
      >>another session, but it should not have.
      >>
      >> Ideas?[/color]
      >
      > Before the header("locatio n: "), call session_write_c lose().
      >
      > That gave me some serious headaches with mac-based browsers hanging.
      > Terrible stuff :)
      >
      > Oh, and you should always use absolute URLs with location. Relative ones
      > do work, but that's not guaranteed. You could make a function like this
      > to take care of that for you:
      >
      > function bounce($url) {
      > if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url;
      > session_write_c lose();
      > header("Locatio n: ".$url);
      > exit();
      > }
      >
      > or just use that one :-P
      >[color=green]
      >> TIA,
      >>
      >> Larry Woods
      >>[/color]
      >
      >[/color]


      Comment

      • d

        #4
        Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

        "lwoods" <larry@lwoods.c om> wrote in message
        news:NIrzf.8954 $JT.3009@fed1re ad06...[color=blue]
        > Thanks, but I still can't get it to work. Check the following:
        >
        > Originating Page:
        >
        > <?
        > if($_POST['repost']=='y') {
        > session_start() ;
        > $_SESSION['xxx']='test';
        > session_write_c lose();
        > header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
        > exit();
        > }
        > ?>
        > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
        > <html xmlns="http://www.w3.org/1999/xhtml">
        > <head>
        > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        > <title>Untitl ed Document</title>
        > </head>
        > <body>
        > <form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
        > <input type="submit" name="submit" value="Submit" />
        > <input type="hidden" name="repost" value="y" />
        > </form>
        > </body>
        > </html>
        >
        > Target Page - testsess2.php:[/color]

        It looks like you're not starting your session in this script:
        [color=blue]
        > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
        > <html xmlns="http://www.w3.org/1999/xhtml">
        > <head>
        > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        > <title>Untitl ed Document</title>
        > </head>
        >
        > <body>
        > <?
        > echo "xxx=".$_SESSIO N['xxx'];
        > ?>
        > </body>
        > </html>
        >
        > Try these pages and see if they work for you....
        >
        > Larry Woods
        >
        > "d" <d@example.co m> wrote in message
        > news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...[color=green]
        >> "lwoods" <larry@lwoods.c om> wrote in message
        >> news:RPqzf.8953 $JT.6285@fed1re ad06...[color=darkred]
        >>>I am trying to pass some info to another page on my site. I set
        >>>"session_sta rt()" in page 1, assign a session variable to a value, then
        >>>execute a "header('Locati on: ....')." But on the target page I don't get
        >>>any session variable values! BTW, I used a relative location in the
        >>>Location header, not an absolute URL. The behavior looks like it started
        >>>another session, but it should not have.
        >>>
        >>> Ideas?[/color]
        >>
        >> Before the header("locatio n: "), call session_write_c lose().
        >>
        >> That gave me some serious headaches with mac-based browsers hanging.
        >> Terrible stuff :)
        >>
        >> Oh, and you should always use absolute URLs with location. Relative ones
        >> do work, but that's not guaranteed. You could make a function like this
        >> to take care of that for you:
        >>
        >> function bounce($url) {
        >> if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url;
        >> session_write_c lose();
        >> header("Locatio n: ".$url);
        >> exit();
        >> }
        >>
        >> or just use that one :-P
        >>[color=darkred]
        >>> TIA,
        >>>
        >>> Larry Woods
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Pedro Graca

          #5
          Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

          lwoods top-posted (corrected):[color=blue]
          > "d" <d@example.co m> wrote in message
          > news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...[color=green]
          >> "lwoods" <larry@lwoods.c om> wrote in message
          >> news:RPqzf.8953 $JT.6285@fed1re ad06...[color=darkred]
          >>>I am trying to pass some info to another page on my site. I set
          >>>"session_sta rt()" in page 1, assign a session variable to a value, then
          >>>execute a "header('Locati on: ....')." But on the target page I don't get
          >>>any session variable values! BTW, I used a relative location in the
          >>>Location header, not an absolute URL. The behavior looks like it started
          >>>another session, but it should not have.
          >>>
          >>> Ideas?[/color]
          >>
          >> Before the header("locatio n: "), call session_write_c lose().[/color][/color]
          [color=blue]
          > Thanks, but I still can't get it to work. Check the following:
          >
          > Originating Page:
          >
          > <?
          > if($_POST['repost']=='y') {
          > session_start() ;
          > $_SESSION['xxx']='test';
          > session_write_c lose();
          > header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
          > exit();
          > }
          > ?>[/color]
          <snip>
          [color=blue]
          > Target Page - testsess2.php:[/color]

          You need a session_start() right here!

          <?php session_start() ?>[color=blue]
          > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
          > <html xmlns="http://www.w3.org/1999/xhtml">
          > <head>
          > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          > <title>Untitl ed Document</title>
          > </head>
          >
          > <body>
          > <?
          > echo "xxx=".$_SESSIO N['xxx'];
          > ?>
          > </body>
          > </html>
          >
          > Try these pages and see if they work for you....[/color]

          With the session_start they do ... but I didn't test it :-)

          --
          If you're posting through Google read <http://cfaj.freeshell. org/google>

          Comment

          • lwoods

            #6
            Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

            You have to do a "start_session( )" in EVERY script where you use SESSION
            variables? I thought that you only had to start the session once.

            Larry
            "d" <d@example.co m> wrote in message
            news:ryszf.3377 $wl.838@text.ne ws.blueyonder.c o.uk...[color=blue]
            > "lwoods" <larry@lwoods.c om> wrote in message
            > news:NIrzf.8954 $JT.3009@fed1re ad06...[color=green]
            >> Thanks, but I still can't get it to work. Check the following:
            >>
            >> Originating Page:
            >>
            >> <?
            >> if($_POST['repost']=='y') {
            >> session_start() ;
            >> $_SESSION['xxx']='test';
            >> session_write_c lose();
            >> header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
            >> exit();
            >> }
            >> ?>
            >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
            >> <html xmlns="http://www.w3.org/1999/xhtml">
            >> <head>
            >> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
            >> />
            >> <title>Untitl ed Document</title>
            >> </head>
            >> <body>
            >> <form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
            >> <input type="submit" name="submit" value="Submit" />
            >> <input type="hidden" name="repost" value="y" />
            >> </form>
            >> </body>
            >> </html>
            >>
            >> Target Page - testsess2.php:[/color]
            >
            > It looks like you're not starting your session in this script:
            >[color=green]
            >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
            >> <html xmlns="http://www.w3.org/1999/xhtml">
            >> <head>
            >> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
            >> />
            >> <title>Untitl ed Document</title>
            >> </head>
            >>
            >> <body>
            >> <?
            >> echo "xxx=".$_SESSIO N['xxx'];
            >> ?>
            >> </body>
            >> </html>
            >>
            >> Try these pages and see if they work for you....
            >>
            >> Larry Woods
            >>
            >> "d" <d@example.co m> wrote in message
            >> news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...[color=darkred]
            >>> "lwoods" <larry@lwoods.c om> wrote in message
            >>> news:RPqzf.8953 $JT.6285@fed1re ad06...
            >>>>I am trying to pass some info to another page on my site. I set
            >>>>"session_st art()" in page 1, assign a session variable to a value, then
            >>>>execute a "header('Locati on: ....')." But on the target page I don't
            >>>>get any session variable values! BTW, I used a relative location in the
            >>>>Location header, not an absolute URL. The behavior looks like it
            >>>>started another session, but it should not have.
            >>>>
            >>>> Ideas?
            >>>
            >>> Before the header("locatio n: "), call session_write_c lose().
            >>>
            >>> That gave me some serious headaches with mac-based browsers hanging.
            >>> Terrible stuff :)
            >>>
            >>> Oh, and you should always use absolute URLs with location. Relative
            >>> ones do work, but that's not guaranteed. You could make a function like
            >>> this to take care of that for you:
            >>>
            >>> function bounce($url) {
            >>> if (sustr($url, 0, 1)=="/")
            >>> $url="http://".$_SERVER["HTTP_HOST"].$url;
            >>> session_write_c lose();
            >>> header("Locatio n: ".$url);
            >>> exit();
            >>> }
            >>>
            >>> or just use that one :-P
            >>>
            >>>> TIA,
            >>>>
            >>>> Larry Woods
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • lwoods

              #7
              Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

              You have to do a "start_session( )" in EVERY script where you use SESSION
              variables? I thought that you only had to start the session once.

              Larry
              "Pedro Graca" <hexkid@dodgeit .com> wrote in message
              news:slrndssk63 .h04.hexkid@ID-203069.user.ind ividual.net...[color=blue]
              > lwoods top-posted (corrected):[color=green]
              >> "d" <d@example.co m> wrote in message
              >> news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...[color=darkred]
              >>> "lwoods" <larry@lwoods.c om> wrote in message
              >>> news:RPqzf.8953 $JT.6285@fed1re ad06...
              >>>>I am trying to pass some info to another page on my site. I set
              >>>>"session_st art()" in page 1, assign a session variable to a value, then
              >>>>execute a "header('Locati on: ....')." But on the target page I don't
              >>>>get
              >>>>any session variable values! BTW, I used a relative location in the
              >>>>Location header, not an absolute URL. The behavior looks like it
              >>>>started
              >>>>another session, but it should not have.
              >>>>
              >>>> Ideas?
              >>>
              >>> Before the header("locatio n: "), call session_write_c lose().[/color][/color]
              >[color=green]
              >> Thanks, but I still can't get it to work. Check the following:
              >>
              >> Originating Page:
              >>
              >> <?
              >> if($_POST['repost']=='y') {
              >> session_start() ;
              >> $_SESSION['xxx']='test';
              >> session_write_c lose();
              >> header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
              >> exit();
              >> }
              >> ?>[/color]
              > <snip>
              >[color=green]
              >> Target Page - testsess2.php:[/color]
              >
              > You need a session_start() right here!
              >
              > <?php session_start() ?>[color=green]
              >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
              >> <html xmlns="http://www.w3.org/1999/xhtml">
              >> <head>
              >> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
              >> />
              >> <title>Untitl ed Document</title>
              >> </head>
              >>
              >> <body>
              >> <?
              >> echo "xxx=".$_SESSIO N['xxx'];
              >> ?>
              >> </body>
              >> </html>
              >>
              >> Try these pages and see if they work for you....[/color]
              >
              > With the session_start they do ... but I didn't test it :-)
              >
              > --
              > If you're posting through Google read <http://cfaj.freeshell. org/google>[/color]


              Comment

              • Jerry Stuckle

                #8
                Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                lwoods wrote:[color=blue]
                > Thanks, but I still can't get it to work. Check the following:
                >
                > Originating Page:
                >
                > <?
                > if($_POST['repost']=='y') {
                > session_start() ;
                > $_SESSION['xxx']='test';
                > session_write_c lose();
                > header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
                > exit();
                > }
                > ?>
                > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                > <html xmlns="http://www.w3.org/1999/xhtml">
                > <head>
                > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                > <title>Untitl ed Document</title>
                > </head>
                > <body>
                > <form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
                > <input type="submit" name="submit" value="Submit" />
                > <input type="hidden" name="repost" value="y" />
                > </form>
                > </body>
                > </html>
                >
                > Target Page - testsess2.php:
                >
                > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                > <html xmlns="http://www.w3.org/1999/xhtml">
                > <head>
                > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                > <title>Untitl ed Document</title>
                > </head>
                >
                > <body>
                > <?
                > echo "xxx=".$_SESSIO N['xxx'];
                > ?>
                > </body>
                > </html>
                >
                > Try these pages and see if they work for you....
                >
                > Larry Woods
                >
                > "d" <d@example.co m> wrote in message
                > news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...
                >[color=green]
                >>"lwoods" <larry@lwoods.c om> wrote in message
                >>news:RPqzf.89 53$JT.6285@fed1 read06...
                >>[color=darkred]
                >>>I am trying to pass some info to another page on my site. I set
                >>>"session_sta rt()" in page 1, assign a session variable to a value, then
                >>>execute a "header('Locati on: ....')." But on the target page I don't get
                >>>any session variable values! BTW, I used a relative location in the
                >>>Location header, not an absolute URL. The behavior looks like it started
                >>>another session, but it should not have.
                >>>
                >>>Ideas?[/color]
                >>
                >>Before the header("locatio n: "), call session_write_c lose().
                >>
                >>That gave me some serious headaches with mac-based browsers hanging.
                >>Terrible stuff :)
                >>
                >>Oh, and you should always use absolute URLs with location. Relative ones
                >>do work, but that's not guaranteed. You could make a function like this
                >>to take care of that for you:
                >>
                >>function bounce($url) {
                >> if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url;
                >> session_write_c lose();
                >> header("Locatio n: ".$url);
                >> exit();
                >>}
                >>
                >>or just use that one :-P
                >>
                >>[color=darkred]
                >>>TIA,
                >>>
                >>>Larry Woods
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Larry,

                You need to call session_start() at the beginning of EVERY page which
                needs session support.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • lwoods

                  #9
                  Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                  Wow,

                  Thanks, Jerry. Kinda' crude, no?

                  Larry
                  "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                  news:Z4ydnfUhzc Qz_1PeRVn-pw@comcast.com. ..[color=blue]
                  > lwoods wrote:[color=green]
                  >> Thanks, but I still can't get it to work. Check the following:
                  >>
                  >> Originating Page:
                  >>
                  >> <?
                  >> if($_POST['repost']=='y') {
                  >> session_start() ;
                  >> $_SESSION['xxx']='test';
                  >> session_write_c lose();
                  >> header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
                  >> exit();
                  >> }
                  >> ?>
                  >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                  >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                  >> <html xmlns="http://www.w3.org/1999/xhtml">
                  >> <head>
                  >> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                  >> />
                  >> <title>Untitl ed Document</title>
                  >> </head>
                  >> <body>
                  >> <form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
                  >> <input type="submit" name="submit" value="Submit" />
                  >> <input type="hidden" name="repost" value="y" />
                  >> </form>
                  >> </body>
                  >> </html>
                  >>
                  >> Target Page - testsess2.php:
                  >>
                  >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                  >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                  >> <html xmlns="http://www.w3.org/1999/xhtml">
                  >> <head>
                  >> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                  >> />
                  >> <title>Untitl ed Document</title>
                  >> </head>
                  >>
                  >> <body>
                  >> <?
                  >> echo "xxx=".$_SESSIO N['xxx'];
                  >> ?>
                  >> </body>
                  >> </html>
                  >>
                  >> Try these pages and see if they work for you....
                  >>
                  >> Larry Woods
                  >>
                  >> "d" <d@example.co m> wrote in message
                  >> news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...
                  >>[color=darkred]
                  >>>"lwoods" <larry@lwoods.c om> wrote in message
                  >>>news:RPqzf.8 953$JT.6285@fed 1read06...
                  >>>
                  >>>>I am trying to pass some info to another page on my site. I set
                  >>>>"session_st art()" in page 1, assign a session variable to a value, then
                  >>>>execute a "header('Locati on: ....')." But on the target page I don't
                  >>>>get any session variable values! BTW, I used a relative location in the
                  >>>>Location header, not an absolute URL. The behavior looks like it
                  >>>>started another session, but it should not have.
                  >>>>
                  >>>>Ideas?
                  >>>
                  >>>Before the header("locatio n: "), call session_write_c lose().
                  >>>
                  >>>That gave me some serious headaches with mac-based browsers hanging.
                  >>>Terrible stuff :)
                  >>>
                  >>>Oh, and you should always use absolute URLs with location. Relative ones
                  >>>do work, but that's not guaranteed. You could make a function like this
                  >>>to take care of that for you:
                  >>>
                  >>>function bounce($url) {
                  >>> if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url;
                  >>> session_write_c lose();
                  >>> header("Locatio n: ".$url);
                  >>> exit();
                  >>>}
                  >>>
                  >>>or just use that one :-P
                  >>>
                  >>>
                  >>>>TIA,
                  >>>>
                  >>>>Larry Woods
                  >>>>
                  >>>
                  >>>[/color]
                  >>
                  >>[/color]
                  >
                  >
                  > Larry,
                  >
                  > You need to call session_start() at the beginning of EVERY page which
                  > needs session support.
                  >
                  > --
                  > =============== ===
                  > Remove the "x" from my email address
                  > Jerry Stuckle
                  > JDS Computer Training Corp.
                  > jstucklex@attgl obal.net
                  > =============== ===[/color]


                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                    lwoods wrote:[color=blue]
                    > You have to do a "start_session( )" in EVERY script where you use SESSION
                    > variables? I thought that you only had to start the session once.
                    >
                    > Larry
                    > "Pedro Graca" <hexkid@dodgeit .com> wrote in message
                    > news:slrndssk63 .h04.hexkid@ID-203069.user.ind ividual.net...
                    >[color=green]
                    >>lwoods top-posted (corrected):
                    >>[color=darkred]
                    >>>"d" <d@example.co m> wrote in message
                    >>>news:T2rzf.3 315$wl.1860@tex t.news.blueyond er.co.uk...
                    >>>
                    >>>>"lwoods" <larry@lwoods.c om> wrote in message
                    >>>>news:RPqzf. 8953$JT.6285@fe d1read06...
                    >>>>
                    >>>>>I am trying to pass some info to another page on my site. I set
                    >>>>>"session_s tart()" in page 1, assign a session variable to a value, then
                    >>>>>execute a "header('Locati on: ....')." But on the target page I don't
                    >>>>>get
                    >>>>>any session variable values! BTW, I used a relative location in the
                    >>>>>Location header, not an absolute URL. The behavior looks like it
                    >>>>>started
                    >>>>>another session, but it should not have.
                    >>>>>
                    >>>>>Ideas?
                    >>>>
                    >>>>Before the header("locatio n: "), call session_write_c lose().[/color]
                    >>[color=darkred]
                    >>>Thanks, but I still can't get it to work. Check the following:
                    >>>
                    >>>Originatin g Page:
                    >>>
                    >>><?
                    >>>if($_POST['repost']=='y') {
                    >>>session_star t();
                    >>>$_SESSION['xxx']='test';
                    >>>session_writ e_close();
                    >>>header('Loca tion: http://www.mysite.com/test/testsess2.php') ;
                    >>>exit();
                    >>>}
                    >>>?>[/color]
                    >>
                    >><snip>
                    >>[color=darkred]
                    >>>Target Page - testsess2.php:[/color]
                    >>
                    >>You need a session_start() right here!
                    >>
                    >> <?php session_start() ?>
                    >>[color=darkred]
                    >>><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                    >>>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                    >>><html xmlns="http://www.w3.org/1999/xhtml">
                    >>><head>
                    >>><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                    >>>/>
                    >>><title>Untit led Document</title>
                    >>></head>
                    >>>
                    >>><body>
                    >>><?
                    >>>echo "xxx=".$_SESSIO N['xxx'];
                    >>>?>
                    >>></body>
                    >>></html>
                    >>>
                    >>>Try these pages and see if they work for you....[/color]
                    >>
                    >>With the session_start they do ... but I didn't test it :-)
                    >>
                    >>--
                    >>If you're posting through Google read <http://cfaj.freeshell. org/google>[/color]
                    >
                    >
                    >[/color]

                    Nope, you need it in every page.

                    Also, I mistyped - it's session_start() .

                    And please don't top post.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                      lwoods wrote:[color=blue]
                      > Wow,
                      >
                      > Thanks, Jerry. Kinda' crude, no?
                      >
                      > Larry
                      > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                      > news:Z4ydnfUhzc Qz_1PeRVn-pw@comcast.com. ..
                      >[color=green]
                      >>lwoods wrote:
                      >>[color=darkred]
                      >>>Thanks, but I still can't get it to work. Check the following:
                      >>>
                      >>>Originatin g Page:
                      >>>
                      >>><?
                      >>>if($_POST['repost']=='y') {
                      >>>session_star t();
                      >>>$_SESSION['xxx']='test';
                      >>>session_writ e_close();
                      >>>header('Loca tion: http://www.mysite.com/test/testsess2.php') ;
                      >>>exit();
                      >>>}
                      >>>?>
                      >>><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      >>>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                      >>><html xmlns="http://www.w3.org/1999/xhtml">
                      >>><head>
                      >>><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                      >>>/>
                      >>><title>Untit led Document</title>
                      >>></head>
                      >>><body>
                      >>><form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
                      >>><input type="submit" name="submit" value="Submit" />
                      >>><input type="hidden" name="repost" value="y" />
                      >>></form>
                      >>></body>
                      >>></html>
                      >>>
                      >>>Target Page - testsess2.php:
                      >>>
                      >>><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      >>>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                      >>><html xmlns="http://www.w3.org/1999/xhtml">
                      >>><head>
                      >>><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                      >>>/>
                      >>><title>Untit led Document</title>
                      >>></head>
                      >>>
                      >>><body>
                      >>><?
                      >>>echo "xxx=".$_SESSIO N['xxx'];
                      >>>?>
                      >>></body>
                      >>></html>
                      >>>
                      >>>Try these pages and see if they work for you....
                      >>>
                      >>>Larry Woods
                      >>>
                      >>>"d" <d@example.co m> wrote in message
                      >>>news:T2rzf.3 315$wl.1860@tex t.news.blueyond er.co.uk...
                      >>>
                      >>>
                      >>>>"lwoods" <larry@lwoods.c om> wrote in message
                      >>>>news:RPqzf. 8953$JT.6285@fe d1read06...
                      >>>>
                      >>>>
                      >>>>>I am trying to pass some info to another page on my site. I set
                      >>>>>"session_s tart()" in page 1, assign a session variable to a value, then
                      >>>>>execute a "header('Locati on: ....')." But on the target page I don't
                      >>>>>get any session variable values! BTW, I used a relative location in the
                      >>>>>Location header, not an absolute URL. The behavior looks like it
                      >>>>>started another session, but it should not have.
                      >>>>>
                      >>>>>Ideas?
                      >>>>
                      >>>>Before the header("locatio n: "), call session_write_c lose().
                      >>>>
                      >>>>That gave me some serious headaches with mac-based browsers hanging.
                      >>>>Terrible stuff :)
                      >>>>
                      >>>>Oh, and you should always use absolute URLs with location. Relative ones
                      >>>>do work, but that's not guaranteed. You could make a function like this
                      >>>>to take care of that for you:
                      >>>>
                      >>>>function bounce($url) {
                      >>>> if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url;
                      >>>> session_write_c lose();
                      >>>> header("Locatio n: ".$url);
                      >>>> exit();
                      >>>>}
                      >>>>
                      >>>>or just use that one :-P
                      >>>>
                      >>>>
                      >>>>
                      >>>>>TIA,
                      >>>>>
                      >>>>>Larry Woods
                      >>>>>
                      >>>>
                      >>>>
                      >>>[/color]
                      >>
                      >>Larry,
                      >>
                      >>You need to call session_start() at the beginning of EVERY page which
                      >>needs session support.
                      >>
                      >>--
                      >>============= =====
                      >>Remove the "x" from my email address
                      >>Jerry Stuckle
                      >>JDS Computer Training Corp.
                      >>jstucklex@att global.net
                      >>============= =====[/color]
                      >
                      >
                      >[/color]

                      Not really. You call session_start() on those pages which require
                      session support, and don't on those which don't need sessions. Saves a
                      little unnecessary processing time.

                      Maybe session_connect () might be a better name? :-)

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • d

                        #12
                        Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                        "lwoods" <larry@lwoods.c om> wrote in message
                        news:Tftzf.8958 $JT.5294@fed1re ad06...[color=blue]
                        > You have to do a "start_session( )" in EVERY script where you use SESSION
                        > variables? I thought that you only had to start the session once.[/color]

                        You have to do that every time you want to use the session.
                        [color=blue]
                        > Larry
                        > "d" <d@example.co m> wrote in message
                        > news:ryszf.3377 $wl.838@text.ne ws.blueyonder.c o.uk...[color=green]
                        >> "lwoods" <larry@lwoods.c om> wrote in message
                        >> news:NIrzf.8954 $JT.3009@fed1re ad06...[color=darkred]
                        >>> Thanks, but I still can't get it to work. Check the following:
                        >>>
                        >>> Originating Page:
                        >>>
                        >>> <?
                        >>> if($_POST['repost']=='y') {
                        >>> session_start() ;
                        >>> $_SESSION['xxx']='test';
                        >>> session_write_c lose();
                        >>> header('Locatio n: http://www.mysite.com/test/testsess2.php') ;
                        >>> exit();
                        >>> }
                        >>> ?>
                        >>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                        >>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                        >>> <html xmlns="http://www.w3.org/1999/xhtml">
                        >>> <head>
                        >>> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                        >>> />
                        >>> <title>Untitl ed Document</title>
                        >>> </head>
                        >>> <body>
                        >>> <form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
                        >>> <input type="submit" name="submit" value="Submit" />
                        >>> <input type="hidden" name="repost" value="y" />
                        >>> </form>
                        >>> </body>
                        >>> </html>
                        >>>
                        >>> Target Page - testsess2.php:[/color]
                        >>
                        >> It looks like you're not starting your session in this script:
                        >>[color=darkred]
                        >>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                        >>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                        >>> <html xmlns="http://www.w3.org/1999/xhtml">
                        >>> <head>
                        >>> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                        >>> />
                        >>> <title>Untitl ed Document</title>
                        >>> </head>
                        >>>
                        >>> <body>
                        >>> <?
                        >>> echo "xxx=".$_SESSIO N['xxx'];
                        >>> ?>
                        >>> </body>
                        >>> </html>
                        >>>
                        >>> Try these pages and see if they work for you....
                        >>>
                        >>> Larry Woods
                        >>>
                        >>> "d" <d@example.co m> wrote in message
                        >>> news:T2rzf.3315 $wl.1860@text.n ews.blueyonder. co.uk...
                        >>>> "lwoods" <larry@lwoods.c om> wrote in message
                        >>>> news:RPqzf.8953 $JT.6285@fed1re ad06...
                        >>>>>I am trying to pass some info to another page on my site. I set
                        >>>>>"session_s tart()" in page 1, assign a session variable to a value, then
                        >>>>>execute a "header('Locati on: ....')." But on the target page I don't
                        >>>>>get any session variable values! BTW, I used a relative location in
                        >>>>>the Location header, not an absolute URL. The behavior looks like it
                        >>>>>started another session, but it should not have.
                        >>>>>
                        >>>>> Ideas?
                        >>>>
                        >>>> Before the header("locatio n: "), call session_write_c lose().
                        >>>>
                        >>>> That gave me some serious headaches with mac-based browsers hanging.
                        >>>> Terrible stuff :)
                        >>>>
                        >>>> Oh, and you should always use absolute URLs with location. Relative
                        >>>> ones do work, but that's not guaranteed. You could make a function
                        >>>> like this to take care of that for you:
                        >>>>
                        >>>> function bounce($url) {
                        >>>> if (sustr($url, 0, 1)=="/")
                        >>>> $url="http://".$_SERVER["HTTP_HOST"].$url;
                        >>>> session_write_c lose();
                        >>>> header("Locatio n: ".$url);
                        >>>> exit();
                        >>>> }
                        >>>>
                        >>>> or just use that one :-P
                        >>>>
                        >>>>> TIA,
                        >>>>>
                        >>>>> Larry Woods
                        >>>>>
                        >>>>
                        >>>>
                        >>>
                        >>>[/color]
                        >>
                        >>[/color]
                        >
                        >[/color]


                        Comment

                        • d

                          #13
                          Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                          "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                          news:FNednSNTNI LI-lPeRVn-iw@comcast.com. ..[color=blue]
                          > lwoods wrote:[color=green]
                          >> Wow,
                          >>
                          >> Thanks, Jerry. Kinda' crude, no?
                          >>
                          >> Larry
                          >> "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                          >> news:Z4ydnfUhzc Qz_1PeRVn-pw@comcast.com. ..
                          >>[color=darkred]
                          >>>lwoods wrote:
                          >>>
                          >>>>Thanks, but I still can't get it to work. Check the following:
                          >>>>
                          >>>>Originati ng Page:
                          >>>>
                          >>>><?
                          >>>>if($_POST['repost']=='y') {
                          >>>>session_sta rt();
                          >>>>$_SESSION['xxx']='test';
                          >>>>session_wri te_close();
                          >>>>header('Loc ation: http://www.mysite.com/test/testsess2.php') ;
                          >>>>exit();
                          >>>>}
                          >>>>?>
                          >>>><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                          >>>>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                          >>>><html xmlns="http://www.w3.org/1999/xhtml">
                          >>>><head>
                          >>>><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                          >>>>/>
                          >>>><title>Unti tled Document</title>
                          >>>></head>
                          >>>><body>
                          >>>><form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
                          >>>><input type="submit" name="submit" value="Submit" />
                          >>>><input type="hidden" name="repost" value="y" />
                          >>>></form>
                          >>>></body>
                          >>>></html>
                          >>>>
                          >>>>Target Page - testsess2.php:
                          >>>>
                          >>>><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                          >>>>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                          >>>><html xmlns="http://www.w3.org/1999/xhtml">
                          >>>><head>
                          >>>><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                          >>>>/>
                          >>>><title>Unti tled Document</title>
                          >>>></head>
                          >>>>
                          >>>><body>
                          >>>><?
                          >>>>echo "xxx=".$_SESSIO N['xxx'];
                          >>>>?>
                          >>>></body>
                          >>>></html>
                          >>>>
                          >>>>Try these pages and see if they work for you....
                          >>>>
                          >>>>Larry Woods
                          >>>>
                          >>>>"d" <d@example.co m> wrote in message
                          >>>>news:T2rzf. 3315$wl.1860@te xt.news.blueyon der.co.uk...
                          >>>>
                          >>>>
                          >>>>>"lwoods" <larry@lwoods.c om> wrote in message
                          >>>>>news:RPqzf .8953$JT.6285@f ed1read06...
                          >>>>>
                          >>>>>
                          >>>>>>I am trying to pass some info to another page on my site. I set
                          >>>>>>"session_ start()" in page 1, assign a session variable to a value,
                          >>>>>>then execute a "header('Locati on: ....')." But on the target page I
                          >>>>>>don't get any session variable values! BTW, I used a relative
                          >>>>>>locatio n in the Location header, not an absolute URL. The behavior
                          >>>>>>looks like it started another session, but it should not have.
                          >>>>>>
                          >>>>>>Ideas?
                          >>>>>
                          >>>>>Before the header("locatio n: "), call session_write_c lose().
                          >>>>>
                          >>>>>That gave me some serious headaches with mac-based browsers hanging.
                          >>>>>Terrible stuff :)
                          >>>>>
                          >>>>>Oh, and you should always use absolute URLs with location. Relative
                          >>>>>ones do work, but that's not guaranteed. You could make a function
                          >>>>>like this to take care of that for you:
                          >>>>>
                          >>>>>function bounce($url) {
                          >>>>> if (sustr($url, 0, 1)=="/")
                          >>>>> $url="http://".$_SERVER["HTTP_HOST"].$url;
                          >>>>> session_write_c lose();
                          >>>>> header("Locatio n: ".$url);
                          >>>>> exit();
                          >>>>>}
                          >>>>>
                          >>>>>or just use that one :-P
                          >>>>>
                          >>>>>
                          >>>>>
                          >>>>>>TIA,
                          >>>>>>
                          >>>>>>Larry Woods
                          >>>>>>
                          >>>>>
                          >>>>>
                          >>>>
                          >>>
                          >>>Larry,
                          >>>
                          >>>You need to call session_start() at the beginning of EVERY page which
                          >>>needs session support.
                          >>>
                          >>>--
                          >>>============ ======
                          >>>Remove the "x" from my email address
                          >>>Jerry Stuckle
                          >>>JDS Computer Training Corp.
                          >>>jstucklex@at tglobal.net
                          >>>============ ======[/color]
                          >>
                          >>
                          >>[/color]
                          >
                          > Not really. You call session_start() on those pages which require session
                          > support, and don't on those which don't need sessions. Saves a little
                          > unnecessary processing time.[/color]

                          Not to mention the default session handler will only allow two scripts to
                          use the same session at the same time - if sessions were "always on", then
                          you'd get timeouts all over the place.
                          [color=blue]
                          > Maybe session_connect () might be a better name? :-)
                          >
                          > --
                          > =============== ===
                          > Remove the "x" from my email address
                          > Jerry Stuckle
                          > JDS Computer Training Corp.
                          > jstucklex@attgl obal.net
                          > =============== ===[/color]


                          Comment

                          • lwoods

                            #14
                            Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                            Jerry,

                            What does "top post" mean?

                            TIA,

                            Larry
                            [color=blue]
                            > Nope, you need it in every page.
                            >
                            > Also, I mistyped - it's session_start() .
                            >
                            > And please don't top post.
                            >
                            > --
                            > =============== ===
                            > Remove the "x" from my email address
                            > Jerry Stuckle
                            > JDS Computer Training Corp.
                            > jstucklex@attgl obal.net
                            > =============== ===[/color]


                            Comment

                            • lwoods

                              #15
                              Re: Aren't session variable preserved using &quot;Header('L ocation: xxx')&quot;?

                              First, I really enjoy working with PHP so I don't want to get something
                              started, but I also work with ASP and there is no such thing as "turning on
                              and off" session support. It's just there! The only problem that you run
                              into is if someone has cookies turned off...but I live with that.

                              Anyway, I'll remember to put "session_start( )" at the top of each page...and
                              before any headers...which I also discovered the hard way.

                              Thanks to all...

                              Larry
                              [color=blue][color=green]
                              >> Not really. You call session_start() on those pages which require
                              >> session support, and don't on those which don't need sessions. Saves a
                              >> little unnecessary processing time.[/color]
                              >
                              > Not to mention the default session handler will only allow two scripts to
                              > use the same session at the same time - if sessions were "always on", then
                              > you'd get timeouts all over the place.
                              >[color=green]
                              >> Maybe session_connect () might be a better name? :-)
                              >>
                              >> --
                              >> =============== ===
                              >> Remove the "x" from my email address
                              >> Jerry Stuckle
                              >> JDS Computer Training Corp.
                              >> jstucklex@attgl obal.net
                              >> =============== ===[/color]
                              >
                              >[/color]


                              Comment

                              Working...