Where is SID?

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

    #1

    Where is SID?

    OK, I'll admit I've been doing it wrong (using session_registe r()), so I'm
    trying to correct my ways, but...

    My script starts with
    <?php
    session_start() ;
    ?>

    In the body of my page a link as follows:

    <a href="targetUrl .php?<php print SID; ?>">Target text</a>

    Problem: SID is an empty string. I even tried
    echo "SID: " . SID . '<br />';

    and SID echoes as an empty string. Why?

    ---Michael

  • Derek Fountain

    #2
    Re: Where is SID?

    Michael Satterwhite wrote:
    [color=blue]
    > OK, I'll admit I've been doing it wrong (using session_registe r()), so I'm
    > trying to correct my ways, but...
    >
    > My script starts with
    > <?php
    > session_start() ;
    > ?>
    >
    > In the body of my page a link as follows:
    >
    > <a href="targetUrl .php?<php print SID; ?>">Target text</a>
    >
    > Problem: SID is an empty string. I even tried
    > echo "SID: " . SID . '<br />';
    >
    > and SID echoes as an empty string. Why?[/color]

    I asked this a few weeks back - you might be able to do a search for the
    thread, although none of the answers were especially illuminating. It
    appears the SID constant is only set under certain circumstances. I never
    did work out what they were. Use the session_id() function to get the
    session ID - that appears to be the correct and reliable way to do it.

    --
    The email address used to post is a spam pit. Contact me at
    http://www.derekfountain.org : <a
    href="http://www.derekfounta in.org/">Derek Fountain</a>

    Comment

    • Steve

      #3
      Re: Where is SID?

      Derek Fountain wrote:[color=blue]
      > Michael Satterwhite wrote:
      >
      >[color=green]
      >>OK, I'll admit I've been doing it wrong (using session_registe r()), so I'm
      >>trying to correct my ways, but...
      >>
      >>My script starts with
      >><?php
      >> session_start() ;
      >>?>
      >>
      >>In the body of my page a link as follows:
      >>
      >> <a href="targetUrl .php?<php print SID; ?>">Target text</a>
      >>
      >>Problem: SID is an empty string. I even tried
      >> echo "SID: " . SID . '<br />';
      >>
      >>and SID echoes as an empty string. Why?[/color]
      >
      >
      > I asked this a few weeks back - you might be able to do a search for the
      > thread, although none of the answers were especially illuminating. It
      > appears the SID constant is only set under certain circumstances. I never
      > did work out what they were. Use the session_id() function to get the
      > session ID - that appears to be the correct and reliable way to do it.
      >[/color]
      Would $SID help?

      Comment

      • Derek Fountain

        #4
        Re: Where is SID?

        > Would $SID help?

        No, SID is a constant, not a variable.

        The page at http://www.php.net/session_id makes a feeble effort at
        explanation, including the sentence "Note that SID is only defined if the
        client didn't send the right cookie." No definition of what the "right
        cookie" might be, of course...

        --
        The email address used to post is a spam pit. Contact me at
        http://www.derekfountain.org : <a
        href="http://www.derekfounta in.org/">Derek Fountain</a>

        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: Where is SID?

          Michael Satterwhite wrote:
          <snip>[color=blue]
          > In the body of my page a link as follows:
          >
          > <a href="targetUrl .php?<php print SID; ?>">Target text</a>
          >
          > Problem: SID is an empty string. I even tried
          > echo "SID: " . SID . '<br />';
          >
          > and SID echoes as an empty string. Why?[/color]

          It is quite sad that most of the people are manually suffixing the
          SID. In PHP there is *no* need to append it manually--there are some
          elegant settings for that and also good way to do that. It is better to
          start using the function after knowing the concept--in this case "What
          is session?" <http://in.php.net/session>

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

          Comment

          • Geoff Berrow

            #6
            Re: Where is SID?

            I noticed that Message-ID:
            <1109048833.964 372.192680@o13g 2000cwo.googleg roups.com> from R. Rajesh
            Jeba Anbiah contained the following:
            [color=blue]
            > It is quite sad that most of the people are manually suffixing the
            >SID. In PHP there is *no* need to append it manually--there are some
            >elegant settings for that and also good way to do that.[/color]

            But many people do not have control over the server and ini_set will not
            enable trans_sid

            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • Michael Fesser

              #7
              Re: Where is SID?

              .oO(Derek Fountain)
              [color=blue]
              >I asked this a few weeks back - you might be able to do a search for the
              >thread, although none of the answers were especially illuminating. It
              >appears the SID constant is only set under certain circumstances.[/color]

              It's set if no session cookies are allowed. If the session ID is stored
              in a cookie you don't need to append it to URLs, so SID will be empty.

              Micha

              Comment

              • Dave Patton

                #8
                Re: Where is SID?

                Michael Satterwhite <michael.XREMOV ETHIS@weblore.c om> wrote in
                news:02xSd.2907 5$cW2.7823@fe2. texas.rr.com:
                [color=blue]
                > OK, I'll admit I've been doing it wrong (using session_registe r()), so
                > I'm trying to correct my ways, but...
                >
                > My script starts with
                ><?php
                > session_start() ;
                > ?>
                >
                > In the body of my page a link as follows:
                >
                > <a href="targetUrl .php?<php print SID; ?>">Target text</a>
                >
                > Problem: SID is an empty string. I even tried
                > echo "SID: " . SID . '<br />';
                >
                > and SID echoes as an empty string. Why?[/color]

                Because you have cookies enabled, and are accepting
                a cookie from your domain with the PHP page, and using
                a browser that supports cookies ;-)

                Do yourself a favour and use the Firefox browser, and
                get the LiveHTTPHeaders extension. You can then see
                the 'HTTP conversation' between your browser and the
                server, and you'll see the session cookie being set,
                and returned.



                Predefined Constants
                --------------------
                SID (string)
                Constant containing either the session name and session ID in
                the form of "name=ID" or empty string if session ID was set in
                an appropriate session cookie.

                Passing the Session ID
                ----------------------
                Alternatively, you can use the constant SID which is always defined.
                If the client did not send an appropriate session cookie, it has the
                form session_name=se ssion_id. Otherwise, it expands to an empty string.
                Thus, you can embed it unconditionally into URLs.

                --
                Dave Patton
                Canadian Coordinator, Degree Confluence Project

                My website: http://members.shaw.ca/davepatton/

                Comment

                • Dave Patton

                  #9
                  Re: Where is SID?

                  "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in
                  news:1109048833 .964372.192680@ o13g2000cwo.goo glegroups.com:
                  [color=blue]
                  > Michael Satterwhite wrote:
                  > <snip>[color=green]
                  >> In the body of my page a link as follows:
                  >>
                  >> <a href="targetUrl .php?<php print SID; ?>">Target text</a>
                  >>
                  >> Problem: SID is an empty string. I even tried
                  >> echo "SID: " . SID . '<br />';
                  >>
                  >> and SID echoes as an empty string. Why?[/color][/color]
                  [color=blue]
                  > It is quite sad that most of the people are manually suffixing the
                  > SID. In PHP there is *no* need to append it manually[/color]

                  That's not entirely true.
                  If cookies are disabled, PHP may append SID to the URL query
                  string, depending on the PHP configuration(e .g. use_trans_sid),
                  but redirections using header() will not be affected, so you
                  may want to include the use of SID in your header() calls.

                  --
                  Dave Patton
                  Canadian Coordinator, Degree Confluence Project

                  My website: http://members.shaw.ca/davepatton/

                  Comment

                  • R. Rajesh Jeba Anbiah

                    #10
                    Re: Where is SID?

                    Dave Patton wrote:[color=blue]
                    > "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in
                    > news:1109048833 .964372.192680@ o13g2000cwo.goo glegroups.com:[/color]
                    <snip>[color=blue][color=green]
                    > > It is quite sad that most of the people are manually suffixing[/color][/color]
                    the[color=blue][color=green]
                    > > SID. In PHP there is *no* need to append it manually[/color]
                    >
                    > That's not entirely true.
                    > If cookies are disabled, PHP may append SID to the URL query
                    > string, depending on the PHP configuration(e .g. use_trans_sid),
                    > but redirections using header() will not be affected, so you
                    > may want to include the use of SID in your header() calls.[/color]

                    I hope, I didn't give wrong info--I was talking about url rewriting
                    alone. Anyway, thanks for pointing out. Keep visiting c.l.php often.

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

                    Comment

                    • R. Rajesh Jeba Anbiah

                      #11
                      Re: Where is SID?

                      Geoff Berrow wrote:[color=blue]
                      > I noticed that Message-ID:
                      > <1109048833.964 372.192680@o13g 2000cwo.googleg roups.com> from R.[/color]
                      Rajesh[color=blue]
                      > Jeba Anbiah contained the following:
                      >[color=green]
                      > > It is quite sad that most of the people are manually suffixing[/color][/color]
                      the[color=blue][color=green]
                      > >SID. In PHP there is *no* need to append it manually--there are some
                      > >elegant settings for that and also good way to do that.[/color]
                      >
                      > But many people do not have control over the server and ini_set will[/color]
                      not[color=blue]
                      > enable trans_sid[/color]

                      Without using htaccess:

                      1. To turn on
                      session_start() ;
                      output_add_rewr ite_var(session _name(), session_id());

                      2. To turn off
                      ini_set('url_re writer.tags', '');
                      session_start() ;

                      *Warning: Not tested thoroughly

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

                      Comment

                      • R. Rajesh Jeba Anbiah

                        #12
                        Re: Where is SID?

                        R. Rajesh Jeba Anbiah wrote:[color=blue]
                        > Geoff Berrow wrote:[/color]
                        <snip>[color=blue][color=green]
                        > > But many people do not have control over the server and ini_set[/color][/color]
                        will[color=blue]
                        > not[color=green]
                        > > enable trans_sid[/color][/color]

                        Also, this is not true in PHP 5.

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

                        Comment

                        • Geoff Berrow

                          #13
                          Re: Where is SID?

                          I noticed that Message-ID:
                          <1109145322.542 052.302100@o13g 2000cwo.googleg roups.com> from R. Rajesh
                          Jeba Anbiah contained the following:
                          [color=blue][color=green]
                          >> But many people do not have control over the server and ini_set will[/color]
                          >not[color=green]
                          >> enable trans_sid[/color]
                          >
                          >Without using htaccess:
                          >
                          >1. To turn on
                          >session_start( );
                          >output_add_rew rite_var(sessio n_name(), session_id());
                          >
                          >2. To turn off
                          >ini_set('url_r ewriter.tags', '');
                          >session_start( );
                          >
                          >*Warning: Not tested thoroughly[/color]
                          If it works, it will be great!

                          --
                          Geoff Berrow (put thecat out to email)
                          It's only Usenet, no one dies.
                          My opinions, not the committee's, mine.
                          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                          Comment

                          • Geoff Berrow

                            #14
                            Re: Where is SID?

                            I noticed that Message-ID:
                            <1109145422.241 184.327150@o13g 2000cwo.googleg roups.com> from R. Rajesh
                            Jeba Anbiah contained the following:
                            [color=blue][color=green][color=darkred]
                            >> > But many people do not have control over the server and ini_set[/color][/color]
                            >will[color=green]
                            >> not[color=darkred]
                            >> > enable trans_sid[/color][/color]
                            >
                            > Also, this is not true in PHP 5.[/color]

                            True, but I doubt it is widely implemented ATM.

                            --
                            Geoff Berrow (put thecat out to email)
                            It's only Usenet, no one dies.
                            My opinions, not the committee's, mine.
                            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                            Comment

                            Working...