Hi,

don't now exactly, maybe some kind of buffer overflow: I wonder if something like this would also cause such problems:

<?php 
$host_ad = $_SESSION['sess_host_ad'];
$array = array("1" => 
        array("1" => "Home", "/index.php", 1, 0, $host_ad."'s Home"), 
        array("1" => "Trick-Tips", "/trick-tips.php", 1, 0, "Skateboarding Trick-Tips"),  
array("1" => "Games", "/games.php", 1, 0, "Flash And Java Games"),
array("1" => "Cheats", "/cheats.php", 1, 0, "PS2/GC/GBA/XBOX Cheats"),
array("1" => "Waypoints", "/waypoints.php", 1, 0, "Download Counter-Strike PODBot Waypoints"),
array("1" => "Forum", "http://www.".$host_ad."/forum/", 1, 1, $host_ad."'s forum"), array("1" => "Blogs", "http://www.".$host_ad."/blogs.php", 1, 0, $host_ad."'s Blogs (Web Logs)"), array("1" => "Jokes", "http://www.".$host_ad."/jokes.php", 1, 0, $host_ad."'s Jokes"), array("1" => "Poll", "http://www.".$host_ad."/poll.php", 1, 0, $host_ad."'s Poll") ); ?>

btw... I'd suggest not to use reserved words as variable names like e.g. $array.

Thomas

    ok thanks for that reserved words tip

    i cant use $host_ad inside the function, thats why i was using $_SESSION['host_ad']

    another thing

    <?php
    $host_ad = str_replace("www.", "", $_SERVER['HTTP_HOST']);
    echo $host_ad; // echos theutherfish.com
    $_SESSION['sess_host_ad'] = $host_ad;
    echo $_SESSION['sess_host_ad']; // echos theutherfish.com<and then garbage>
    
    $_SESSION['sess_host_ad'] = str_replace("www.", "", $_SERVER['HTTP_HOST']);
    
    echo $_SESSION['sess_host_ad']; // echos theutherfish.com
    ?>
    

    i wonder what exactly happens during this process
    $_SESSION['sess_host_ad'] = $host_ad;

    that causes the garbage

      Hi,

      this seems to be a buffer problem.

      What happens with this code:

      <?php 
      $host_ad = str_replace("www.", "", $_SERVER['HTTP_HOST']); 
      echo $host_ad; // echos theutherfish.com 
      $_SESSION['sess_host_ad'] = $host_ad; 
      session_write_close();
      session_start();
      echo $_SESSION['sess_host_ad']; // echos theutherfish.com<and then garbage> 
      
      $_SESSION['sess_host_ad'] = str_replace("www.", "", $_SERVER['HTTP_HOST']); 
      
      echo $_SESSION['sess_host_ad']; // echos theutherfish.com 
      ?> 
      

      Thomas

        for that i get

        theutherfish.comtheutherfish.comtheutherfish.com<garbled code>
        Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/theuther/public_html/includes/template.php on line 50

          Which parts of the output relate to which lines ?

            i'm guessing

            echo $host_ad; // echos theutherfish.com
            echo $_SESSION['sess_host_ad']; // echos theutherfish.com

            and the last one
            echo $_SESSION['sess_host_ad']; // echos theutherfish.com <garbled code>

            the mysql error was caused by code later on, so i seperated what you gave me from the rest and heres the output

            http://www.theutherfish.com/sess_test.php

              Hi,

              change the test script to this code (no other code) and see what it does:

              <?php  
              session_start(); $text = ""; if (isset($_SESSION['sess_host_ad'])) { $text = $_SESSION['sess_host_ad']."<br>\n"; } else { $host_ad = str_replace("www.", "", $_SERVER['HTTP_HOST']);
              $_SESSION['sess_host_add'] = $host_ad; $text = "Session data: ".$host_ad; } ?>
              <html> <head> <title>Test</title> </head> <body> Text: <?=$text?><br> <a href="<?=$_SERVER['PHP_SELF']?>">Klick</a> </body> </html>

              Do you get any garbled output clicking on the link ?

              Thomas

                So you tried it first in the browser window where you had the problems before and then in a new browser window (new session) and the garbled code disappeared ?

                Thomas

                  yeh, it goes, but even with the first problem if i open a new window and session then click a link the session becomes garbled where as in what you gave me it doesnt

                  would this be a server issue?

                    I think I know what the problem is ... maybe some server problem, but I think it goes more in the direction how PHP handles sessions ... I didn't have such problems so far but this is what I think:

                    Let's say you have a script where you set a session variable.
                    The line $_SESSION['sess_host_ad'] = $host_ad doesn't write the session data to the disk but rather holds the value in memory.
                    As soon as the script execution ends the session data is written to the disk. Seems like you can't expect the session data to be reliable in any case until it is written to the disk. This might be an issue with the OS, don't know.

                    I think the solution is simple:

                    In any script where you have something like:

                    $avar = .....;
                    $_SESSION['sess_avar'] = $avar;

                    dont't use $_SESSION['sess_avar'] further on in the script but rather just $avar. After execution of the script the session data will be written and will contain the data expected if you access it in other scripts. I think doing so will solve the problems.

                    Thomas

                      right, it all seems reasonable enough

                      i will make sure i use these guidelines again when necessary

                      thank you again for your time thomas

                      Jon

                        Write a Reply...