Forum Moderators: coopster
The code that generates the query is like the following:
tep_db_query("update " . TABLE_WHOS_ONLINE . " set customer_id = '" . (int)$wo_customer_id . "', full_name = '" . tep_db_input($wo_full_name) . "', ip_address = '" . tep_db_input($wo_ip_address) . "', time_last_click = '" . tep_db_input($current_time) . "', last_page_url = '" . tep_db_input($wo_last_page_url) . "' where session_id = '" . tep_db_input($wo_session_id) . "'");
Which turns into:
update whos_online set customer_id = '0', full_name = 'Guest', ip_address = '192.168.1.2', time_last_click = '1213204988', last_page_url = 'www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html' where session_id = '17fa0fb5d7c00179e37426b294c4a6ac'
Now, when I am using Firefox and I am seeing a product page, the information stored on the field last_page_url on the database will be just 'www.example.com' instead of 'www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html'
If I do the SQL query by hand with phpmyadmin, the information is inserted ok on the DB. If I modify the PHP code like the following, the information is inserted ok:
tep_db_query("update " . TABLE_WHOS_ONLINE . " set customer_id = '" . (int)$wo_customer_id . "', full_name = '" . tep_db_input($wo_full_name) . "', ip_address = '" . tep_db_input($wo_ip_address) . "', time_last_click = '" . tep_db_input($current_time) . "', last_page_url = '" . tep_db_input('www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html') . "' where session_id = '" . tep_db_input($wo_session_id) . "'");
So, if I use $wo_last_page_url, it won't work; if I use 'www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html', it does work!
Even more strange, this works ok with Explorer. It just won't work with Firefox (I do not even understand why the client browser woule make a difference).
If I do s strcmp with $wo_last_page_url and 'www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html', I get a 0, which means that both should be the same. I can not understand then why it doesn't work with $wo_last_page_url, but it works with the cardcoded value...!
Any hints will be greatly appreciated, thanks!
echo $wo_last_page_url;
exit;
I had already tried outputing many text on screen for debuging purposes. Things like:
- print_r($wo_last_page_url);
www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html
- print_r(strlen($wo_last_page_url));
88 (this was to see if there was some strange char at the end, doesn't look like it, note that the string is now 87char in length, since my domain is one letter longer than example.com)
- echo $wo_last_page_url;
www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html
- $temp = 'www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html';
- if ($wo_last_page_url == $temp) { print_r('SAME'); }
SAME
Maybe my PHP knowledge is too limited, but I think this last IF would imply that $wo_last_page_url and $temp are exactly the same. Well, if I call the query with $temp the string gets inserted ok on the database. If I do it with $wo_last_page_url I only get the "www.securame.com" part.
Now, where it can get even more strange: it does work ok if I am browsing it with Explorer, it fails only if I am browsing with Firefox. And again, this is a OSCommerce store, it does work ok with other kind of URLs (index, categories, articles, whatever), from what I have been able to see it only fails when the URL being viewed is a product (?¿?)
Thanks you!
Aitor
This one shows SAME and works when inserting $temp on the DB.
$temp = 'www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html';
if ($wo_last_page_url == $temp) { print_r('SAME'); }
$temp = $wo_last_page_url;
This one shows SAME and does not work when inserting $temp on the DB on Firefox. It does work if I am using Explorer...?!
I wasted hours yesterday trying to find out what is wrong. The who's online module is really not worth the trouble, since it is not such a big problem that if someone does happen to be seeing a product and is using Firefox, I will think they are on /. But I just hate this glitches that I am unable to solve and understand.
Also, for your information, although this has nothing to do with your problem, you can just use echo [php.net] to print strings to the browser. print_r [php.net] is used to print array information.
$wo_last_page_url comes from $_SERVER['SERVER_NAME'] and $_SERVER['REQUEST_URI'] (on its own function with a couple of ifs). $wo_last_page_url actually stores the correct value, on Explorer and Firefox, so I doubt the error is coming from there. If I echo $wo_last_page_url I seem to be geting the full URL ok.
-----
function request_uri() {
if (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
}
else {
if (isset($_SERVER['argv'])) {
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
}
else {
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
}
}
//return check_url($uri);
return $uri;
}
....
$wo_last_page_url = $_SERVER['SERVER_NAME'] . request_uri();
-----
I know that it doesn't make much sense that a SQL query is not working right with Firefox, but it is with Explorer. I know that it doesn't make sense that the query is not just failing, but that it is storing just 'www.domain.com' instead of 'www.domain.com/full_url_to_product-p-1.html'. But it is indeed hapening to me... :?
Thanks on the echo hint, I started using print_r long ago since most of the times I am dealing with arrays, and by default I always use print_r now whener I just want something on screen.
Here I am seeing the web page with Firefox and then Explorer.
<snip>
When I look at the who's module on the admin section, my Firefox session is not showing the full URL.
<snip>
If I check the DB with phpmyadmin, I see that indeed the Firefox session did not enter the full data $wo_last_page_url contained on the database. It had a full URL, but it only stored the first part.
<snip>
This is the code that inserts the info on the DB. All the comented crap on the top is debuging. You can see that now I have a print there that is a copy of what the script is doing.
<snip>
So now when I see the page on Firefox, the info is still not stored ok on the DB. I see on top the query it is supposed to be using.
<snip>
Now, if I copy that query EXACTLY as it is being shown on screen, and execute it on phpmyadmin, it is working ok. Phpmyadmin on Firefox, yeah (should not make a difference). Woot? The query is passed ok to OSCommerce function tep_db_query, which I am able to see with a print_r($query) here. But I do not know how to debug this any more, and I am unable to understand why this would be failing only with firefox, and only with product URLs...
----------
function tep_db_query($query, $link = 'db_link') {
// LINE CHANGED: Added $debug
global $$link, $debug;
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
//print_r($query);
$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
$result_error = mysql_error();
error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
// LINE ADDED
$debug['QUERIES'][] = $query;
return $result;
}
----------
Just found out another hint right now, so I'll keep looking at it...!
[edited by: eelixduppy at 11:07 pm (utc) on June 12, 2008]
[edit reason] removed URLs [/edit]
I promise I am not making this up. I do hope that someone can point me to the obvious reason why this is happening, so I can stop banging my head against a wall.
So I try to find out what is wrong with the string I am trying to push to the DB with Firefox. One of the things I do is a str_shuffle() on it so I will get randomness.
<snip>
Now, again reload with Firefox and Explorer, and I will get the URl scrambled.
<snip>
But, when I look at what has been entered on the DB, HUGE surprise. Note, that I have also tried it from a different computer here just in case, so you see the info two times.
<snip>
Now, where you see a long URL, I can see the EXACT same randomness that has been shown to me on Explorer. But on Firefox, it is not even related. Where is that info coming from?
What I got on screen from the print_r($wo_last_page_url); was:
mdld-2jrscgoroetatoocn.empotr/umdtmae-e-.uea.-v5ilbsmgr-oo-hmvob-aowcua9-snewo-cwlp-arrn
And what has been stored on the DB is the following, which happens to be a str_shuffle() of JUST the DOMAIN...!:
wmcue.os/awce.mwr
For a moment that kinda made me think of programming and passing variables ByVal or ByRef. Something like if there were actually different "copies" of $wo_last_page_url , where one would contain just the domain name, and the other one would contain the full URL. But I did not find much sense on that.
(more)
[edited by: eelixduppy at 11:24 pm (utc) on June 12, 2008]
[edit reason] removed URLs, please see sticky [/edit]
If I go to a real product URL with Firefox, it is not working (note that I use Ultimate SEO URL, the following URL actually is for product 257):
http://www.example.com/real-product-p-257.html
If it is a product that I do not have, of course I see no product information, but the URL is stored ok on the database (like it is stored ok with everything else, index, categories, articles, specials, whatever)
http://www.example.com/this-product-number-does-not-exist-p-6666.html
This kinda makes me think that there must be SOMETHING on product_info that is messing up. Since from my previous post I could start thinking that the tep_update_whos_online() function is being called two times, I have done a grep on all my web site, to find out that it is only on two places, where it should be:
/includes/functions/whos_online.php
/includes/application_top.php
So I would say that is only being called one time on each page show, from application_top.php
But I thought let's try to move it from application_top.php to application_bottom.php , so it will be the last thing it runs. And you know what? For a moment, it worked. It did, I swear, but it didn't last long. I visited a few products, and I could see it on who's online. Not just categories, but also products!
And then it stoped, and started showing me just the URLs again. So I dropped the whos_online table on the DB, created it again empty, reloaded, and it worked again. And it stoped working again. So I dropped the whos_online table on the DB, created it again empty, reloaded, and it DID NOT work this time.
So all I can say right now is, to hell with it. I can not find any explanation to the behaviour I am seeing, if anyone has read this far, any comments will be welcome. In fact I do not understand why am I bothering so much, after all, who cares about what product is seeing on a given moment someone who is browsing with Firefox? :(
As variable variables have a habit of getting a little twisted. So maybe you are using more than 1 table, so it works on one table, but not on the other.
If you are not changing $link then you dont need to use a variable variable. So you must be changing link, or maybe a typo.
Changing $link will result in a different link identifier being used at different points, hence you strange problem, depending on the value of $link.
<edit>
Have you tried Opera?
[edited by: penders at 11:00 pm (utc) on June 13, 2008]
The only extension common on both Firefoxs where I had tried this was (is) Ad Block Plus. I just tried it again on a VMware mnachine with a plain Firefox 2.0.0.14 installation, and the same thing happens.
I even tried Firefox 3, and the results do not seem to change; it fails only when I am seeing a product page.
---
rob7591,
I do not even know what is the funcion tep_db_input() for, but an echo tep_db_input($wo_last_page_url); will output the same text on both browsers, the URL I am visiting at the moment. It outputs the correct URL, I guess that function is for removing "strange" characters not accepted on some mysql versions/installs.
---
PHP_Chimp,
I have to admit I hadn't even noticed the double $ on $$link, I hadn't looked much at the code on tep_db_query() since that is just standard code from a plain OSCommerce installation. No idea on why it comes that way, or how to output the value of $$link, since an echo will output nothing.
$$link must contain the SQL connection information, this tep_db_connect() function is also from /includes/functions/database.php
function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
global $$link;
if (USE_PCONNECT == 'true') {
$$link = mysql_pconnect($server, $username, $password);
} else {
$$link = mysql_connect($server, $username, $password);
}
if ($$link) mysql_select_db($database);
return $$link;
}
The only other thing I would try is
$url = tep_db_input($wo_last_page_url);
echo $url; //for debugging
tep_db_query("update " . TABLE_WHOS_ONLINE . " set customer_id = '" . (int)$wo_customer_id . "', full_name = '" . tep_db_input($wo_full_name) . "', ip_address = '" . tep_db_input($wo_ip_address) . "', time_last_click = '" . tep_db_input($current_time) . "', last_page_url = '$url' where session_id = '" . tep_db_input($wo_session_id) . "'");
echo '<br />request_uri:' . request_uri(); //see if it's the request_uri messing it up somehow..
Just tried your code and the SQL query with '$url' instead of tep_db_input($wo_last_page_url) , and same results. With Firefox only the www.example.com part is being stored on the DB, with Explorer all of it gets stored.
With both of them the debugging code is the same:
www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html
request_uri:/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html
All the information seems to be correct up to the point on which the URL is passed to tep_db_query(). Very strange that passed this point it could make a difference if you are with FF or IE.
Two things bother me now.
1 - If I go to a non existent product URL like the following, the URL does get stored on the DB: http://www.example.com/randomness-p-1111.html
2 - If I do a str_shuffle() on the URL I am pushing on tep_db_query(), with IE all the string is shuffled. On FF, only the www.example.com part. The only explanation I can find to that is that all this code on tep_update_whos_online() is being run two times with FF, just once on IE. And that for whatever reason, the second time $url is just the domain, and that all my debuging is not doing anything the second time since I am not seeing any repeated output on screen. Could this be happening, or make sense to anyone?
2. I understand what you're saying.. If you have echo $url right next to the tep_db_query() it would output twice..
This is the nuttiest problem I've ever seen.. What's the tep_db_query() code?
Maybe try:
$url = 'http://www.example.com/grabador-video-dvr-autonomo-canales-mjpeg-usb-control-remoto-p-259.html'
echo $url;
tep_db_query("update " . TABLE_WHOS_ONLINE . " set customer_id = '" . (int)$wo_customer_id . "', full_name = '" . tep_db_input($wo_full_name) . "', ip_address = '" . tep_db_input($wo_ip_address) . "', time_last_click = '" . tep_db_input($current_time) . "', last_page_url = '$url' where session_id = '" . tep_db_input($wo_session_id) . "'");
$url = 'www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html';
echo $url;
if ($wo_last_page_url == $url) { echo(' - WE ARE THE SAME'); } else { echo(' - WE ARE NOT'); }
Output will be:
www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html - WE ARE THE SAME
And of course, if I tep_db_query() $url, URL is stored ok on the DB. If I do it with tep_db_input($wo_last_page_url), it is not. And they are supposed to be the same, there is not a WE ARE NOT anywhere on the page source code.
The original tep_db_query code is the one at the very beginning of the thread, with the query posted there being a real query generated and echoed on screen, and with that query actually working ok if I copy+paste it on phpmyadmin.
The fact that it is only happening on product pages, and that it is not happening if the product is non existant, seems to me more important than the fact that it only happens on Firefox... Since it is a non critical issue, I should just trash it an keep going on the next one, but it bugs me a lot to be unable to understand why it is happening hehe
$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
print_r ('query : ' . $query);
print_r (' - result : ' . $result);
I get the same result with both FF (first) and IE (second):
query : update whos_online set customer_id = '0', full_name = 'Guest', ip_address = '1.2.3.4', time_last_click = '1213829888', last_page_url = 'www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html' where session_id = '189b756d9f7ef5b3bcff545747901d76' - result : 1
query : update whos_online set customer_id = '0', full_name = 'Guest', ip_address = '1.2.3.4', time_last_click = '1213829876', last_page_url = 'www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html?osCsid=58b53073c68c5013c46e2cd4965f98a2' where session_id = '58b53073c68c5013c46e2cd4965f98a2' - result : 1
I actually did a copy+paste of both queries to have them side by side and see the differences, IE url contains the osCsid, it doesn't on FF. With IE the full url gets stored on the DB as shown above (the who's online module later removes all osCsid's when showing people online), with FF only www.example.com/
So mysql_query() is returning TRUE on both cases, it succeed. I will try to activate the loging part on tep_db_query() (tried it previously and didn't succeed) since the only reason I can see this happening is if it is being called somehow again with a different URL.
I was able to active the loging capabilities on my host/OSC to make it create a log of all queries done to the database, and I am seeing two queries done when seeing a product page with FF, and just one with IE.
With FF, what I get is:
QUERY update whos_online set customer_id = '0',
full_name = 'Guest', ip_address = '1.2.3.4',
time_last_click = '1213838181', last_page_url = 'www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html'
where session_id = '189b756d9f7ef5b3bcff545747901d76'
RESULT 1
...
QUERY update whos_online set customer_id = '0',
full_name = 'Guest', ip_address = '1.2.3.4',
time_last_click = '1213838182', last_page_url = 'www.example.com/'
where session_id = '189b756d9f7ef5b3bcff545747901d76'
RESULT 1
And with IE:
QUERY update whos_online set customer_id = '0',
full_name = 'Guest', ip_address = '1.2.3.4',
time_last_click = '1213838184', last_page_url = 'www.example.com/tarjeta-dvr-pci-entradas-de-video-25fps-p-103.html'
where session_id = '68a76fddf7de41384625330455b3e3cf'
RESULT 1
Now that is something to start thinking about. I won't post all the logs since I want to study all the queries before to know what's going on, but what I see is that when I load a product on IE, it generates 75 entries on the log file. When I load the same exact product on FF, it generates the same 75 queries... and then an extra 55.
It actually seems I could have fixed this without the need of touching ANY code at all, since the problem was actually with my product descriptions. My products have originally been imported from ebay/turbo lister, so they have some code that maybe should not be here on the store, but that it works on ebay to give it some text formating:
----------
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; font-variant: normal; text-transform: none; color: #000000; text-decoration: none; background-attachment: fixed; background-color: #FFFFFF; background-image: url(); background-repeat: repeat-y; background-position: left top}
td {border-style:solid; border-width:0px; border-color:#000000}
.style1 {font-size: 18px; font-weight: bold; }
.style2 {font-size: 16px}
.style3 {font-size: 12px}
.style4 {font-size: 12px; font-weight: bold; }
-->
</style>
</head>
(Description starts here)
----------
If I remove the part that reads: <style type="text/css"> ... </style>
my problem goes away. I lose text formating on the description, but the whos online works - guess I will have to move all that styles to my main store stylesheet, since they have to be on the product descripcion on ebay to work, but I do not need them on each product description here.
I will have to look at it a little bit more until I fix it ok and move the styles somewhere else so my products stay the same when removing, but for now I have no clue on what this is exactly causing Firefox to do. I am sure there might be something "wrong" with changing the body style in there, or having <head></head> that probably should have not been there in the beginning. I do not see though how this could cause the effect it has been causing, and why it would only be happening with Firefox, since it seems more something server side than client side...
As g1smd pointed, "whatever it is, will ultimately turn out to be something fairly simple."