LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Why do I get a broken connection when I try to compare SID with a variable (PHP 4) (https://www.linuxquestions.org/questions/programming-9/why-do-i-get-a-broken-connection-when-i-try-to-compare-sid-with-a-variable-php-4-a-341575/)

vharishankar 07-09-2005 08:08 AM

Why do I get a broken connection when I try to compare SID with a variable (PHP 4)
 
I have a little function where I am checking whether the SID constant has any value so that I can avoid the annoying little ? in the URL window. I want to append the SID when the cookies are disabled and I don't want to when cookies are enabled. This works fine without checking, except that the annoying little ? appears after the URL in the browser following by nothing.

Here's what I tried
PHP Code:

    function append_sid ($url)
    {
        
$sessionid strval(constant('SID'));
        if (
strlen($sessionid) != 0)
            
$sid_url $url '?' SID;
        else
            
$sid_url $url;
        return 
$sid_url;
    } 

However, the moment I try this, the connection refuses to work and the application seems to crash the connection.

What is the problem here?

keefaz 07-09-2005 08:40 AM

You don't need this hack, the function you want to accomplish
is supposed to be done by php internally.

What I don't get is the ? being added to your url, could you ellaborate ?

vharishankar 07-09-2005 09:00 AM

No it isn't. It depends on a special PHP.INI directive. If this directive is off, then it won't work.

I know, because before I used this function, the program works properly only with cookies enabled. If cookies aren't enabled then you need to pass the SID through the URL.

The point is, I want to check whether the SID constant is present or not. Because when cookies are enabled, then the constant is not present. This leads to an annoying ? in the URL followed by nothing.

Whenever I try to check this though, it works not.

I found that the actual problem here is nothing to do with what I originally thought but due to when I try to return something like this (nothing to do with the SID):
PHP Code:

function func ($var)
{
      
$new $var;
      return 
$new;


Then this breaks the web server connection. Any ideas?

vharishankar 07-09-2005 09:07 AM

I noticed that I am passing constants to the function above.

as defined by
PHP Code:

define ('CONSTANT''Value'); 

Could that be a reason as to why the above not only fails, but absolutely crashes the connection as well? Could it be a memory leak or something?

AnanthaP 07-09-2005 10:34 AM

The "book" recommends.

if(IsSet($session_id) ..

End

keefaz 07-09-2005 10:35 AM

For my part, I let the session.use_cookies = 1 in php.ini
if I disable coockie in the web browser client, the
session identifier (SID) is automatically added in the URL
so I don't see where the problem is.

vharishankar 07-09-2005 10:57 AM

As I said keefaz, in my local server the PHP.INI value

session.use_trans_sid

is set to off.

Maybe I'll just avoid the whole function and leave it as it is.


All times are GMT -5. The time now is 12:11 AM.