Hi guys,

How can I configure php.ini file via .htaccess file?

It seems that session.use_trans_sid is disabled with me, so my WebHost told that I have to reconfigure the php.ini file from .htaccess file that lied in the public_html directory, I tried in so many ways, but everytime it gave "Internal Server Error" when I borwose my script via IE!!!

My scripts to test the SID insertion in the URL if the cookies are disabled failed:

Session1.php:

<?
session_start();
$IPAddress = getenv ("REMOTE_ADDR"); 
session_register("IPAddress");
echo "My IPAddress is $IPAddress";
?>
<a href="Session2.php?<?=SID?>"> Click here to test session variable</a>

and Session2.php:

<?
session_start();
$IPAddress = $HTTP_SESSION_VARS[IPAddress];
echo "My IPAddress is $IPAddress";
?>

If you set:

IE 6.0.26 -> Tools -> Internet Options -> Privacy -> Advance -> Select Prompt for First-Party Cookies

and Test the first script "Session1.php" you'll be prompt to accept the requested cookie, just block it, and then if you click on the link provided you'll be prompt one more time, just block that cookie, finally, the SID is not sent automaticaly when the cookies are disabled!

Please help me to test these 2 scripts with your server, will you get the same problem that I have? if not, then I have to re-configure the .htaccess file to enable session.use_trans_sid.

I tried to set session.use_trans_sid on by the follwoing command:

php_flag session.use_trans_sid = on

as its mentioned at http://www.faqts.com/knowledge_base/view.phtml/aid/13037/fid/51

and I tried to set it like this:

<IfModule mod_php4.c>
php_flag session.use_trans_sid = on
</IfModule>

as its mentioned at http://www.php.net/manual/en/printwn/configuration.php

But none of them worked fine with me? why?

Please anyone can help?

    After configuring the .htaccess file with:

    <IfModule mod_php4.c>
    php_flag session.use_trans_sid on;
    </IfModule>

    Now, it stopped giving me the "Internal Server Error" but still its not inserting the SID automaticaly in the URL if the cookies are disabled!!!

    What do I have to do? Isn't supposed that the SID should be inserted automaticaly if the cookies are disabled? Because this way, it's not working.

    Please HELP.

      This is maybe not the problem but it's the only thing I can think of at the moment and I'm kind of tired.

      If you have register_globals enabled in the php.ini file then this may be the cause of the problem. If this is enabled then due to the order which PHP initializes variables then the Cookie will take precedence over either a GET or POST method of passing the SID.

      Maybe this is what is happening - the GET attribute is being overwritten by the cookie value.

      1 other thing I've just thought of is you can turn off the PHPSESSID cookie in the php.ini file by setting session.use_cookies to 0. At least that should stop the problem - let me know.

      Dan.

        Hi dancahill,

        Thanx 4 ur help, I apreciate it.

        Well, I configured the .htaccess file by the following:

        <IfModule mod_php4.c>
        php_value register_globals off
        php_value session.use_cookies off
        php_value session.use_trans_sid on
        </IfModule>

        And the results now, it stopped using the cookies, but the SID is not passing automaticaly to the second script!

        Is this has anything to do with my PHP version 4.0.6?

        One more thing, Did you test these scripts with your webserever? I just want to be sure that my code is workgin fine and the problem is with my webServer not with the code.

        Please I need help, just to overcome this problem 🙂

          As its clear in http://www.php.net/manual/en/ref.session.php

          in the Passing the Session ID section:

          its mentioned:

          Passing the Session ID
          There are two methods to propagate a session id:

          Cookies

          URL parameter

          The session module supports both methods. Cookies are optimal, but since they are not reliable (clients are not bound to accept them), we cannot rely on them. The second method embeds the session id directly into URLs.

          PHP is capable of doing this transparently when compiled with --enable-trans-sid. If you enable this option, relative URIs will be changed to contain the session id automatically. Alternatively, you can use the constant SID which is defined, if the client did not send the appropriate cookie. SID is either of the form session_name=session_id or is an empty string.

          Note: The arg_separator.output php.ini directive allows to customize the argument seperator.

          The following example demonstrates how to register a variable, and how to link correctly to another page using SID. Example 5. Counting the number of hits of a single user

          <?php
          if (!session_is_registered('count')) {
          session_register('count');
          $count = 1;
          }
          else {
          $count++;
          }
          ?>

          Hello visitor, you have seen this page <?php echo $count; ?> times.<p>;

          <?php

          the <?php echo SID?> (<?=SID?> can be used if short tag is enabled)

          is necessary to preserve the session id

          in the case that the user has disabled cookies

          ?>

          To continue, <A HREF="nextpage.php?<?php echo SID?>">click here</A>

          The <?=SID?> is not necessary, if --enable-trans-sid was used to compile PHP.

          Please take a look to that page, maybe it'll help you to make you help me 🙂

            Write a Reply...