Log in

View Full Version : code adds my url to url for link?



I am Abby
08-18-2010, 05:06 PM
<?php
// Retrieve all the data from the "webcalendar_events" table
$result = mysql_query("SELECT * FROM webcalendar_events )
or die(mysql_error());

echo
"Decription: {$row['description']}</p>";
}


I got a calendar from PHPScripts which allows you to enter links in it.
The above script (I snipped) is used to get featured dates to place on the page. Works great, with the help of Traq, but for some reason my webpage added my url to links found in the description field. If the link in the calendar (which works correctly within the calendar) is
http://www.there.com the link I get using the above code gives me a link with the address
http://mysite.com/%22http://www.there.com

Is the problem the script? or the way the calendar puts it into the db?

djr33
08-18-2010, 06:08 PM
It's impossible to know why that is happening from the information you posted.
The first thing to do is check how it is stored in the database. Do you have phpmyadmin or another way to view it directly? If not, I'd recommend doing a much simpler query that just prints out all the data so you can look at it:

<?php
//run this as a new page
//then click view>source
/////
//connect to the database!!
/////
$q = mysql_query('SELECT * FROM `mytable`;');
while($r = mysql_fetch_assoc($q)) {
print_r($r);
}
?>

It may very well be how the calendar saves it, but we can't know that yet.

I am Abby
08-18-2010, 06:59 PM
Your script gave me an array...the same thing I was getting with the field names.

I looked at the fields in the database and the urls are stored like this


<a href=\"http://page.com\">link</a>

I am Abby
08-18-2010, 07:07 PM
Array ( [id] => 4 [calendar_id] => 1 [dt] => 2010-08-20 => ffff00 [description] => test of events to be printed on page. tiis is iit [COLOR="Red"]KCM )

The above is what I get from the script you gave me. KCM was a link...the link is gone now but the url was my site and the link seperated by %22

I cut all but one record to make it more readable.

djr33
08-18-2010, 10:20 PM
As I said, view it as source code, not as HTML.
The text output in the source code is what you are dealing with.
After that, it should be easy to figure out.
And yes, it will be an array. That is to view this if you do NOT have another way to view it directly. If you have phpmyadmin or another option like that, you should just view it that way.

This is all just to see what format it is stored in and whether it is even possible to do what you are attempting. Once you know that, then you can determine the next step.

I am Abby
08-19-2010, 07:43 PM
Not sure what do you mean "view it as source code"

When I look into the database at the record, the description field has "Another item to test <a href=\"http://uiuc.edu\">U of I</a>" in it.

when I run that code you gave me above...I get a list of everything in the array but the field looks like "Another item to test U of I (http://uiuc.edu)"

djr33
08-20-2010, 05:27 AM
"view as source" means viewing the HTML code as text, after it is generated by PHP. The easiest way to do that is to create a page on your server, save it, then go to the URL and click "edit>view source" (or whatever method works in your browser).
That was only to be able to view exactly what was being generated from your database. But since you found another way to view it, that is no longer important.

If you have the text stored containing HTML directly (such as the links) it will be a lot harder to modify than if it was stored separately. I'm not sure what to suggest aside from some complex form of search and replace operation.

I am Abby
08-23-2010, 12:51 PM
Wow, I was sick, sick, sick this weekend but I'm better now...don't you just hate getting sick on the weekend!

The source code looks like this...doesn't this look right?


<body>
<p><strong>August 20, 2010</strong><br />Decription: test of events to be printed on page.

this is it <a href=\"http://www.uiuc.edu\">U of I</a></p><p><strong>September 14, 2010</strong></p>

But when you move the mouse over the link on the page it looks like

http://mysite.com/%22http://www.there.com

djr33
08-23-2010, 01:09 PM
Interesting. Is there a base href on the page?

I am Abby
08-23-2010, 04:11 PM
Here is the complete code for the test page. Only thing I changed was the mysql_connect information...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// Make a MySQL Connection
mysql_connect("xxx.xxx.xxx.xx", "login", "password") or die(mysql_error());
mysql_select_db("nlchdb") or die(mysql_error());

// Retrieve all the data from the "webcalendar_events" table
$result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt")
or die(mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$monthnames = array(
"01"=>"January",
"02"=>"February",
"03"=>"March",
"04"=>"April",
"05"=>"May",
"06"=>"June",
"07"=>"July",
"08"=>"August",
"09"=>"September",
"10"=>"October",
"11"=>"November",
"12"=>"December");

list($year, $month, $day) = split('[/.-]', $row['dt']);
$month = $monthnames[$month];
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$row['description']}</p>";
}
$q = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt");
while($r = mysql_fetch_assoc($q)) {
print_r($r);
}
?>

</body>
</html>

Again the code does a good job with the exception of adding extra info to the link urls.

djr33
08-24-2010, 12:06 AM
Honestly I have no idea. Clearly some part of the process, unknown to us, is doing something odd. All I can say is double check all the code and be sure that it isn't like that in the database. Can you export/backup the db and go trough it manually?

I am Abby
08-25-2010, 01:56 PM
It looks correct in the database.
Well thanks for your time anyway:)

traq
08-25-2010, 02:36 PM
this is it <a href=\"http://www.uiuc.edu\">U of I</a></p><p><strong>September 14, 2010</strong></p>

But when you move the mouse over the link on the page it looks like

http://mysite.com/%22http://www.there.com

In your source code, are the backslashes present before the doublequotes ( \" )?

If something (some kind of server configuration, most likely) is automatically adding a base url to your links, it probably looks for href attributes that seem to be internal. The slashes (which shouldn't be there) might be interfering with that check...

Maybe. ( ??? )

Try running stripslashes() on the url the database returns and see if helps.

while($r = mysql_fetch_assoc($q)) {

// try it here - I think that'll catch it
stripslashes($r);

print_r($r);
}


Also try adding an external url ( <a href="http://www.othersite.com">external</a> ) directly into your html and see if the base url is added or not.

You could also contact your service provider and see if there is someway to turn that "feature" off.

I am Abby
08-25-2010, 03:03 PM
one of my friends said because the urls in the source code has slashes

<a href=\"http://page.com\">link</a>
I should do a remove slashes...so I tried


// Make a MySQL Connection
mysql_connect("xxx.xxx.xxx.xx", "login", "password") or die(mysql_error());
mysql_select_db("nlchdb") or die(mysql_error());

// Retrieve all the data from the "webcalendar_events" table
$result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt")
or die(mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
//remove code we don't need to see for this.
<snip>---</snip>
list($year, $month, $day) = split('[/.-]', $row['dt']);
$month = $monthnames[$month];
$str = stripslashes($row['description'];
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$str}</p>";
and that didn't remove them.
So I came back here and saw your post and tried...

// Make a MySQL Connection
mysql_connect("xxx.xxx.xxx.xx", "login", "password") or die(mysql_error());
mysql_select_db("nlchdb") or die(mysql_error());

// Retrieve all the data from the "webcalendar_events" table
$result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt")
or die(mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
stripslashes($row);
//remove code we don't need to see for this.
<snip>---</snip>
list($year, $month, $day) = split('[/.-]', $row['dt']);
$month = $monthnames[$month];
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$row['description']}</p>";
Again it did not take the slashes out...is there another way to do it?

I not only put
<a href="http://www.othersite.com">external</a> on the page I also placed

echo "<a href=\"http://www.othersite.com\">external</a>"; within the code tags...both worked correctly.

traq
08-25-2010, 03:28 PM
You might try stripslashes() in the individual entry that holds the link - I just noticed that $r is the entire row. Try stripslahes($r['link']) (or whatever the column that holds the link is called).

If you write a normal external link directly in your html, do you still get this problem? or is it limited to the links this script is generating?

I am Abby
08-25-2010, 03:52 PM
<snip>
list($year, $month, $day) = split('[/.-]', $row['dt']);
$month = $monthnames[$month];
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {stripslahes($row['description'])}</p>";
}
The above gave me an error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

I tried that earlier and it's the reason I tried


<snip>
$str = stripslashes($row['description'];
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$str}</p>";
which did not remove the slashes

I am Abby
08-25-2010, 04:45 PM
It worked.
Thanks Boys;)