473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script gets executed twice unless filename is in the URL

6 New Member
Sometimes my scripts calls the server twice even if is a simple stright-forward one.

I usually runs a trace in the background when I'm testing new scripts. And quite often I can see, that the server has been called two times.

Not very smart if you're maintaining a counter across calls.



First it was all voodoo, but I think I have found a pattern:
If I write http://domain.com or plain www.domain.com then the script allways runs twice

But if I add the name of the script as in http://domain.com/index.php the number of runs may be one or two.

Can somone explain what's going on?
May 26 '07 #1
7 1324
pbmods
5,821 Recognized Expert Expert
Changed thread title to better match contents.

Can somone explain what's going on?
Not likely, unless we had some relevant code snippets to work with.
May 26 '07 #2
oju
6 New Member
Pew... that's a lot of code... But here it goes
Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2. class c_tabsession {
  3. /* Change the values of following conatants if you like */
  4. const QRYNAME = "tbsi"; // "Tabbed browser session info"
  5. const TMPPATH = "/tmp/"; // Location to workfile 
  6. const GCPERIOD = 3600; // Number of seconds until a untouched workfile will be deleted
  7. /* 
  8. You will possible need some more constants 
  9. for your i encrypt/decrypt algorithm 
  10. */
  11. private $translink; // This is the encrypted filename and some other important data
  12.  
  13. private $important1; // integer
  14. private $important2; // 32 bit hex
  15. private $fileId; // reference top /tmp/workfile
  16.  
  17. public $qryin = array(); // Holds data passed by $_GET and $_POST
  18. public $session = array(); // Holds session data
  19.  
  20. public function __construct()
  21. {
  22. if ( self::transInfo( $this->translink ) )
  23.     self::transDecrypt( $this->translink );
  24. else
  25.     { /* Make an new identifyer and lock it by redirect to self */
  26.      $this->translink = self::transEncrypt( $this->userId, $this->mdPass, $this->fileId );
  27.      header( "location: " . self::href($_ENV['SCRIPT_URI'], http_build_query( $this->qryin )));
  28.      exit; 
  29.     }
  30. /* Invariant: All variables are initiated */
  31. self::getSession(); 
  32. }
  33.  
  34. public function __destruct()
  35. { /* Very important! Ensures that session-data are preserved */
  36. self::GarbageCollect();
  37. self::putSession();
  38. }
  39.  
  40. public function href( $uri, $QueryString = "" )
  41. { /* Creates URL. You are advised to use 'http_build_query()' to create the $QueryString */
  42.      $uri .= "?" . http_build_query( array( self::QRYNAME => $this->translink) );
  43. if ( ! empty( $QueryString ) ) $uri .= "&" . $QueryString;
  44. return $uri;
  45.  
  46. public function hidden( )
  47. { /* creates a hidden field to be used in forms */
  48. return '<input name="'
  49.         . self::QRYNAME
  50.      . '" type="hidden" value="'
  51.      . $this->translink
  52.      . '">'. "\n";
  53. }
  54.  
  55. public function dumpSess( $a_sess, $key = "SESSION_ROOT", $indent = "" )
  56. { /* Recursive dump of SESSION structure */
  57. if (is_array($a_sess) )
  58. {
  59.     echo "-ARRAY-<br>\n";
  60.     foreach($a_sess AS $key => $value) self::dumpSess( $value, $key, $indent . str_repeat("&nbsp;",3) );
  61.     return; // void
  62. }
  63. if (is_bool($a_sess)) echo (($a_sess)?"TRUE":"FALSE"), " #BOOLEAN#<br>\n";
  64. else echo $a_sess, " #", strtoupper( gettype( $a_sess )), "#<br>\n";
  65. return; // void
  66. private function transInfo(&$link)
  67. {
  68. $link = "";
  69. /* Emulate $_REQUEST without $_COOKIE */
  70. $this->qryin = array_merge($_GET, $_POST);
  71. if ( ! isset( $this->qryin[self::QRYNAME] ) )
  72. {
  73. /* First time - Generate the basic "session-id" */
  74.     $this->important1 = self::SOME_DEFAULT;
  75.     $this->important2 = md5( self::ANOTHER_DEFAULT );
  76.     $this->fileId = md5( uniqid( rand(), true ));
  77.     return false;
  78. }
  79. $link = $this->qryin[self::QRYNAME];
  80. unset( $this->qryin[self::QRYNAME] );
  81. return true;
  82. }
  83.  
  84. private function transEncrypt( $important1, $important2, $fileId )
  85. { // CHANGE function transDecrypt simultanious with this
  86. /* 
  87.     Make some encryption algorithm to mess up the parameters
  88.     (I'd rather not disclose my own)
  89. */
  90.      return $link;
  91. }
  92.  
  93. private function transDecrypt( $link )
  94. { // DEPENTING on function transEncrypt
  95. /* Bring string back in correct order
  96.     store result in object variables 
  97.     */
  98. return; // void
  99. }
  100.  
  101. private function getSession()
  102. { // Read session-file into object-storage
  103. $path = self::SessionPath();
  104. if (file_exists( $path ) ) 
  105. {
  106.     $file = file_get_contents($path);
  107.     $this->session = unserialize($file);
  108.     return; // void
  109. }
  110. $this->session = array();
  111. return; //void
  112. }
  113.  
  114. private function putSession()
  115. { // Save session-data on file. Invariant: $this->session in an array
  116. $path = self::SessionPath();
  117. $file = serialize( $this->session );
  118. file_put_contents( $path, $file );
  119. return; // void 
  120. }
  121. private function SessionPath()
  122. {
  123. $path = $_ENV['DOCUMENT_ROOT'] . self::TMPPATH;
  124. $file = base_convert( $this->fileId, 16, 35 ); // Compress filename
  125.              // don't worry it's still unique
  126. $path .= strtoupper(self::QRYNAME) . "_" . $file . ".txt";
  127. return $path;
  128. }
  129.  
  130. private function GarbageCollect()
  131. { // Removes sessionfiles older than GCPERIOD seconds
  132. $path = $_ENV['DOCUMENT_ROOT'] . self::TMPPATH;
  133. $path .= strtoupper(self::QRYNAME) . "_*.txt";
  134. $files = glob($path);
  135. foreach($files as $file){
  136.     if(is_file($file)) 
  137.     {
  138.      if ((filectime($file) + self::GCPERIOD) < time()) unlink($file);
  139.     }
  140. }
  141. return; // void
  142. }
  143. } // End of class c_tabsession
  144. ?>
  145. <?php 
  146. /*
  147. This class includes all elements that must be available to every page 
  148. */
  149. class c_masterpage extends c_tabsession {
  150.  
  151.  
  152. public function __construct()
  153. {
  154. $develop = new c_construction( true ); // This line will set all subdomains to test-mode
  155.              // move it to separate subdomains, when production starts
  156. parent::__construct(); self::test_input(); 
  157. }
  158.  
  159. public function __destruct() { self::test_output(); parent::__destruct(); } // IMPORTANT !!!
  160.  
  161. /***************************************************************************************** 
  162. *                             Test functions                                         * 
  163. *****************************************************************************************/
  164.  
  165. private function test_input()
  166. {
  167. // return;
  168. $log = new c_syslog( $_ENV['DOCUMENT_ROOT'] . "/_ress/log/trace.txt", "Input" );
  169. $log->log( print_r( $_GET, true ), "GET" );
  170. $log->log( print_r( $_POST, true ), "POST" );
  171. $log->log( print_r( $_COOKIE, true ), "COOKIE" );
  172. $log->log( print_r( $this->session, true ), "SESSION" );
  173. $log->log( print_r( $_ENV, true ), "ENV" );
  174. }
  175.  
  176. private function test_output()
  177. {
  178. // return;
  179. $log = new c_syslog( $_ENV['DOCUMENT_ROOT'] . "/_ress/log/trace.txt", "Output" );
  180. $log->log( print_r( $this->session, true ), "SESSION" );
  181. }
  182.  
  183. private function test_trace( $arg )
  184. {
  185. static $counter = 0; $counter++;
  186. $log = new c_syslog( $_ENV['DOCUMENT_ROOT'] . "/_ress/log/trace.txt", "Trace" );
  187. $log->log( $arg , $counter );
  188. }
  189.  
  190. } // End of class c_masterpage
  191. ?>
  192. <?php
  193. $page = new masterpage();
  194. $page->session['counter']++;
  195. ?>
  196. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  197. "http://www.w3.org/TR/html4/loose.dtd">
  198. <html>
  199. <head>
  200. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  201. <title>Dummy</title>
  202. </head>
  203. <body>
  204. </body>
  205. </html>
  206.  
May 27 '07 #3
oju
6 New Member
Cannot send my trace - gets wierd error-message :(
May 27 '07 #4
oju
6 New Member
Cannot send my trace - gets wierd error-message :(
You can read it on www.junne.dk/drill/double.txt
May 27 '07 #5
oju
6 New Member
I've found the perpetrator, but not the reason.

The last part of my HTML-code goes like this:
[HTML] <div id="siteInfo"> <img src="" width="44" height="22"> <a href="#">Om dette web-sted </a> | <a href="#">Tekniske Krav </a> | <a href="#">Din Sikkerhed </a> | <a href="#">Webmaster</a> | &copy;2007 Antvorskov Kirke </div>
[/HTML]
And it is id="siteInfo", that does the damage. When I remove this, the loop stops. "siteInfo" has a reference to my css stylesheet, saying:
Expand|Select|Wrap|Line Numbers
  1.  #siteInfo{
  2. clear: both;
  3. border-top: 1px solid #cccccc;
  4. font-size: small;
  5. color: #cccccc;
  6. padding: 10px 10px 10px 10px;
  7. margin-top: 0px;
  8. }
  9.  
But it looks quite stright-forward. So I'm clueless :((

Anyway - now I have removed the reference so I can get on with my work.
May 29 '07 #6
oju
6 New Member
It came back - this annoying double server-call. And this time I could count out errors in CSS. But then I noticed something. I'm working with a template of the fill-in-the-blanks kind, and I had'nt filled in the images yet, so I had a line like this:

[HTML] <img src="" alt="" width="119" height="180"> [/HTML]

- and BINGO! I got two calls to the server. Now examine the css-code I posted last time: It had an empty image-source too.

I still don't know why, but just take care out there :-)
Jul 20 '07 #7
pbmods
5,821 Recognized Expert Expert
Heya, Oju.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 20 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
4293
by: JimC | last post by:
Think I asked this once before. My apologies for asking twice. In a certain PHP document at my site, I have a link to a Word version of the same document. If the user downloads it, I want to...
6
6058
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
2
4054
by: Jeronimo Bertran | last post by:
A couple of questions I am having problems with converting my JavaScript to C#. I have the following code using JavaScript for the mouseover handler that works fine: <SCRIPT...
17
34666
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works...
3
5652
by: Ed Sonneveld | last post by:
Hi, I have hosted my webservice at a hosting company and it has been working fine for 2 years now. The webservice is called by winforms clients over the internet, using the proxy class generated...
9
20877
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
0
1996
by: norseman | last post by:
Gros Bedo wrote: ============================== Yes. man ps explains try ps -AFL | grep then kill -9 found (check it more than twice) 1) If your script is known to hang use what...
66
8109
by: happyse27 | last post by:
Hi All, my html code is sno 1) and perl code is sno 2). a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it...
1
47347
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
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,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.