Jump to content

Problem with PHP linking system


t.bo

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
Link to comment
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";
Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.