Unstoppable Domains

Auto Link Code

Spacemail by SpaceshipSpacemail by Spaceship
Watch

antec

Established Member
Impact
1
Im trying to find a code html or java that allows people automaticly add there link to my blog. does anyone know the code?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
so you want people to add a button on there site and then when a visitor clicks on it, it blogs it on your site?
 
0
•••
I guess you need to code that, using MySQL?

Well, it is not an easy task. You can pay someone to do it for you? Or you can find a good tutorial for it.
 
0
•••
Ahm he has just to place a form that saves the URL and the name at the DB and the make a code to read from there!
 
0
•••
True... however, it is possible to do this flat file style, in case he doesn't have mysql!
 
0
•••
Here's a simple flat-file type thing i have done, i think it does what you need although please note that it includes no validation, or security measures

Form Code
Code:
<form action="add.php" method="post">
Name: <input type="text" name="name" />
<br />
URL: <input type="text" name="url" value="http://" />
<br />
<input type="submit" value="Submit" />
</form>

add.php adds the links
PHP:
<?php
//File where all links are stored
$file='links.txt';
//Variables Posted
$name=$_POST['name'];
$url=urldecode($_POST['url']);
//Open File and Add Link
$handle=fopen($file,'a');
//Check that all data is filled in
if($name == '' || $url == ''){
	die("Please fill in all fields correctly");
} else{
	fwrite($handle,$name.'=>'.$url.'
');
}
?>

parse.php - returns the links
PHP:
<?php
//Path to links file
$links='links.txt';
//Open
$links=file($links);
//print_r($links);
//Display
foreach($links as $line){
list($name,$url)=explode('=>',$line);
$url=str_replace('
','',$url);
echo '<a href="'.$url.'">'.$name.'</a>';
echo '<br /><br />';
}
?>

Then just create a blank file called links.txt in the same directory, and make sure it is writeable

Lee

EDIT:

MySQL

Create the following files:

config.inc.php
PHP:
<?php
$cfg['dbhost'] = 'localhost';
$cfg['dbuser'] = 'user';
$cfg['dbpass'] = 'pass';
$cfg['dbname'] = 'database';

//connect to the database
function connectdb(){
	global $cfg;
	mysql_connect($cfg['dbhost'],$cfg['dbuser'],$cfg['dbpass']);
	mysql_select_db($cfg['dbname']);
}
?>

add.php
PHP:
<?php
include_once('config.inc.php');
$action=$_POST['action'];
$name=$_POST['name'];
$url=$_POST['url'];
if($action == 'add'){
	//Add User and Link To DB
	connectdb();
	if($name == !'' || $url = !''){
		if(mysql_query("INSERT INTO `links` VALUES (NULL,'$name','$url')")){
			echo "Link Added";
		}
	}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="action" value="add" />
Name: <input type="text" name="name" />
<br />
URL: <input type="text" name="url" value="http://" />
<br />
<input type="submit" value="Submit" />
</form>

display.php
PHP:
<?php
include_once('config.inc.php');
connectdb();
$query=mysql_query("SELECT * FROM `links`");
$rows=mysql_numrows($query);
$i=0;
while($i < $rows){
	$name=mysql_result($query,$i,'name');
	$url=mysql_result($query,$i,'url');
	echo '<a href="'.$url.'">'.$name.'</a><br />';
	$i++;
}
?>

And run the SQL query through phpmyadmin or similar to create the database structure

Code:
CREATE TABLE `links` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` TEXT NOT NULL ,
`url` TEXT NOT NULL
)

Once again there is no security in here, so use at your own risk
 
Last edited:
1
•••
Am i the only one who believes in php standards anymore lol...Not nagging, i appreciate it's only an example but i do have to have a little rant when i see things like !=''
 
0
•••
Are you talking about the space that isn't there? In that code all I see that has something like != is == ! which I've never seen before.

I don't know if I use standards but I code for readability, etc.
 
0
•••
Just used this code on a site - easy and straightforward; many thanks!
-Allan :gl:
 
0
•••
No problem, just if you've used the MySQL version then please note that it won't protect against SQL injection attacks etc. So it needs some security adding to it

Lee :)
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back