473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Where is SID?

OK, I'll admit I've been doing it wrong (using session_register()), 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

Jul 17 '05 #1
13 16495
Michael Satterwhite wrote:
OK, I'll admit I've been doing it wrong (using session_register()), 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?


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.derekfountain.org/">Derek Fountain</a>
Jul 17 '05 #2
Derek Fountain wrote:
Michael Satterwhite wrote:

OK, I'll admit I've been doing it wrong (using session_register()), 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?

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.

Would $SID help?
Jul 17 '05 #3
> 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.derekfountain.org/">Derek Fountain</a>
Jul 17 '05 #4
Michael Satterwhite wrote:
<snip>
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?


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/

Jul 17 '05 #5
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from R. Rajesh
Jeba Anbiah contained the following:
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.


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/
Jul 17 '05 #6
.oO(Derek Fountain)
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.


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
Jul 17 '05 #7
Michael Satterwhite <mi*****************@weblore.com> wrote in
news:02******************@fe2.texas.rr.com:
OK, I'll admit I've been doing it wrong (using session_register()), 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?


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.

http://www.php.net/manual/en/ref.session.php

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=session_id. Otherwise, it expands to an empty string.
Thus, you can embed it unconditionally into URLs.

--
Dave Patton
Canadian Coordinator, Degree Confluence Project
http://www.confluence.org/
My website: http://members.shaw.ca/davepatton/
Jul 17 '05 #8
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
Michael Satterwhite wrote:
<snip>
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?
It is quite sad that most of the people are manually suffixing the
SID. In PHP there is *no* need to append it manually


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
http://www.confluence.org/
My website: http://members.shaw.ca/davepatton/
Jul 17 '05 #9
Dave Patton wrote:
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:

<snip>
It is quite sad that most of the people are manually suffixing the SID. In PHP there is *no* need to append it manually


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.


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/

Jul 17 '05 #10
Geoff Berrow wrote:
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from R. Rajesh Jeba Anbiah contained the following:
It is quite sad that most of the people are manually suffixing theSID. In PHP there is *no* need to append it manually--there are some
elegant settings for that and also good way to do that.
But many people do not have control over the server and ini_set will

not enable trans_sid


Without using htaccess:

1. To turn on
session_start();
output_add_rewrite_var(session_name(), session_id());

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

*Warning: Not tested thoroughly

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

Jul 17 '05 #11
R. Rajesh Jeba Anbiah wrote:
Geoff Berrow wrote: <snip>
But many people do not have control over the server and ini_set

will not
enable trans_sid


Also, this is not true in PHP 5.

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

Jul 17 '05 #12
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from R. Rajesh
Jeba Anbiah contained the following:
But many people do not have control over the server and ini_set will

not
enable trans_sid


Without using htaccess:

1. To turn on
session_start();
output_add_rewrite_var(session_name(), session_id());

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

*Warning: Not tested thoroughly

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/
Jul 17 '05 #13
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from R. Rajesh
Jeba Anbiah contained the following:
> But many people do not have control over the server and ini_set

will
not
> enable trans_sid


Also, this is not true in PHP 5.


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/
Jul 17 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Andrey Tatarinov | last post by:
Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable...
3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
3
by: Xiangliang Meng | last post by:
Hi, all. In 1998, I graduated from Computer Science Dept. in a university in China. Since then, I've been using C Language for almost 6 years. Although I'm using C++ in my current job, I'm also...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
5
by: comp.lang.php | last post by:
if ($willLimitByDB) $sql = preg_replace('/#(+)#/i', '$$1', $sql); This does not give me the results I want, instead of the value of $where in $sql, I literally get '$where' instead. How do I...
5
by: John | last post by:
I just cannot manage to perform a SELECT query with NULL parameter... My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB null value). TCATEGORYID and TCATEGORYPARENTID...
0
NeoPa
by: NeoPa | last post by:
Background Whenever code is used there must be a way to differentiate the actual code (which should be interpreted directly) with literal strings which should be interpreted as data. Numbers don't...
1
by: not_a_commie | last post by:
I was hoping for increased functionality with the where clause in C# 3.0. Using the new keyword 'var' would really allow us to take nice advantage of these. Specifically: 1. I want to limit it...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.