unrelenting
07-08-2007, 06:19 PM
Can anyone tell me how to fix this. I have this link click counting script that works great except if a link has an "&" symbol in it. If it does then it disregards the & and the rest of the url and writes only the part up until that point into the database. It also redirects to the shortened url afterwards.
What can I add to get around that?
<?php
require 'connect.php';
if(!empty($HTTP_GET_VARS['j']))
{
$b=mysql_select_db("news", $con);
$date = time();
$j=addslashes($HTTP_GET_VARS['j']);
$c=mysql_query("select id from click_counter where url='$j' order by id desc limit 1");
$d=mysql_fetch_object($c);
if(is_object($d))
{
mysql_query("update click_counter set hits=hits+1 where id={$d->id}");
}
else
{
mysql_query("insert into click_counter (url, date)values('$j',' $date')");
}
header("Location: $j");
}
else
{
header("Location: http://{$HTTP_SERVER_VARS['SERVER_NAME']}");
}
?>
unrelenting
07-08-2007, 06:46 PM
try urlencode()
No luck. It still stops at that &.
CFMaBiSmAd
07-08-2007, 06:54 PM
If you post an example of the link/data that does not work and also show what the results should be, it would help someone see what you are trying to accomplish.
unrelenting
07-08-2007, 07:00 PM
If you post an example of the link/data that does not work and also show what the results should be, it would help someone see what you are trying to accomplish.
This is the link that I use. It works fine on any links I've used except for this one with the & symbol in it.
http://woopig.net/news/cc.php?j=http://www.hogwired.com/ViewArticle.dbml?DB_OEM_ID=6100&ATCLID=1064637
This is what gets written to my database as well as where I am directed to:
http://www.hogwired.com/ViewArticle.dbml?DB_OEM_ID=6100
_Aerospace_Eng_
07-08-2007, 07:04 PM
Do a string replace, replacing instances of & with &
unrelenting
07-08-2007, 07:06 PM
Do a string replace, replacing instances of & with &
Can that be automated or will I have to do it every time someone posts a link?
CFMaBiSmAd
07-08-2007, 07:20 PM
The encoded & will be interpreted as & when received by the server and it will terminate the $_GET['j'] variable (I just tested it.) To use a $_GET variable, you would need to change the & into something else in the link and then change it back within your code (messy.)
You might want to look at the $_SERVER['QUERY_STRING'] variable and parse that to get what you want. For your example, this would give (tested) -
j=http://www.hogwired.com/ViewArticle.dbml?DB_OEM_ID=6100&ATCLID=1064637
unrelenting
07-08-2007, 07:32 PM
The encoded & will be interpreted as & when received by the server and it will terminate the $_GET['j'] variable (I just tested it.) To use a $_GET variable, you would need to change the & into something else in the link and then change it back within your code (messy.)
You might want to look at the $_SERVER['QUERY_STRING'] variable and parse that to get what you want. For your example, this would give (tested) -
j=http://www.hogwired.com/ViewArticle.dbml?DB_OEM_ID=6100&ATCLID=1064637
I can't seem to make much since out of the $_SERVER['QUERY_STRING'] idea. I'm a novice and I got this code on a google search. I don't understand where to use it and/what to replace with it.
unrelenting
07-08-2007, 08:00 PM
Diligence and determination finally paid off. I got it working with your suggestion and parsing it with substr.
$m=addslashes($_SERVER['QUERY_STRING']);
$j=substr($m,2);