Jump to content

Archived

This topic is now archived and is closed to further replies.

t.bo

Problem with PHP linking system

Recommended Posts

Hey all,

I made 2 systems where the user inputs the url and it should output that url in a hyperlink but there are weird problems.
In the 2 systems (event & affiliatesystem) it should display the event title with the url. I used this code in php :
[code]echo  "<tr><td><a href='$url'>$event</a></td>";[/code]

Everything sould be correct (input in database and so on..) but the link that comes out is really weird. In the first system the links are like this : http://www.currentwebsite.com/www.thelinkthatwasinputted.com

And in the second system the links are like so : http://www.currentwebsite.com/$url

Can anyone help me?

The form looks like this :
[code]<form action="affilexe.php" method="post">
<br>Naam van nieuwe partner/link/organisatie :
<br><input name="title" type="text" value="Title">
<br>Categorie van de nieuwe link (Let op schrijfwijze) :
<br><input name="categorie" type="text" value="categorie">
<br>URL van nieuwe partner/link/organisatie (OPGELET: "http://" voor het adres niet vergeten!) :
<br><textarea name="url" cols="60" rows="3" value="Message"> </textarea>
<br><input name="submit" type="submit" value="Submit">[/code]

Another question : Does the user has to input http:// before the actual url or doens't that matter?

grtz and thanks in advance !!

T.bo

Share this post


Link to post
Share on other sites
With <a href=""> tags you will need to have http:// if they don't do it else it does exactly what you see.

[code]
<?php

echo "<tr><td><a href=\"http://{$url}\">{$event}</a></td>";

?>
[/code]

Share this post


Link to post
Share on other sites
Issue #1: http://www.currentwebsite.com/www.thelinkthatwasinputted.com

If the user fails to put a http:// link in front of their link, the browser acts like it is a local file with a relative path. You should do a more comprehensive error checking of your data, probably using PCRE or EREG, but here's the little code that could fix that specific problem:
[code]
<?php
if (strpos($url,'http://')===FALSE) {
  $url = 'http://'.$url;
}
?>[/code]

Issue #2: http://www.thelinkthatwasinputted.com/$url

This appears to me to be a problem with your register globals setting, because if you are sending url as a form variable, then you should reference it with $_POST['url'], not as $url. If register_globals is off, then $url is not a valid variable, so there is nothing for the parser to do with it except display the literal text "$url";

Share this post


Link to post
Share on other sites
Weel now I have a third weird problem.
I thought everything was solved but not.
The 2 systems work fine on 1 website , but they make the same mistake on another.
http://www.djvik.be =>check the links section.

Here is the code:
[code]<link href="vikcontent.css" rel="stylesheet" type="text/css">
<h1>Links</h1>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">

<?php
include('dbconnect.php');
$sql = mysql_query("select * from affiliate order by catfield") or die(mysql_error());

$prevCat='';
while($row = mysql_fetch_array($sql))
{
$title = $row["titlefield"];
$id = $row["idfield"];
$url = $row["urlfield"];
$categorie = $row["catfield"];

// has category changed ?
// if so, print it
if ($categorie != $prevCat)  {
echo "<tr><td><h2>$categorie</h2></td></tr>";
}
echo  "<tr><td><a href=\"http://$url\">$title</a></td></tr>";

$prevCat = $categorie;
}
?>
</table>[/code]

Share this post


Link to post
Share on other sites
try this ok
[code]
<link href="vikcontent.css" rel="stylesheet" type="text/css">
<h1>Links</h1>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">

<?php
include('dbconnect.php');
$sql = mysql_query("select * from affiliate order by catfield") or die(mysql_error());

$prevCat='';
while($row = mysql_fetch_assoc($sql))
{
$title = $row["titlefield"];
$id = $row["idfield"];
$url = $row["urlfield"];
$categorie = $row["catfield"];

// has category changed ?
// if so, print it
if ($categorie != $prevCat)  {
echo "<tr><td><h2>$categorie</h2></td></tr>";
}
?>

<tr><td><a href="http://<?php echo $url ?>"><?php echo $title?></a></td></tr>";

<? php $prevCat = $categorie;?>
<?}?>

</table>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.