Jump to content

Basic help needed......


ammar77

Recommended Posts

Hi guys,

 

This little code accept only alphabets and numbers but i want to customize it to accept "-" "_" and "."  values, kindly help me in this regard..thanks

 

code

===============

 

<?

include("config.php");

if (strstr($_SERVER['HTTP_REFERER'], $root));

else { header ("Location: $rooturl"); }

 

$ip = $_SERVER['REMOTE_ADDR'];

$url = mysql_real_escape_string($_POST['url']);

 

if(preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) {

if (empty($_POST['tag'])) {

$query = mysql_query("INSERT INTO $table (ip,url) VALUES ('$ip','$url')") or die('MySQL error: '.mysql_error());

$qs = mysql_insert_id();

} else {

if (ereg('^[a-zA-Z0-9]+[a-zA-Z0-9]+$', $_POST['tag'])) {

$tag = mysql_real_escape_string($_POST['tag']);

$query = mysql_query("select * from $table where `tag` = '$tag';") or die('MySQL error: '.mysql_error());

if (mysql_num_rows($query) != 0)

die("This tag has already been taken! Please press the back button on your browser and choose another tag!");

else {

$query = mysql_query("insert $table (ip,url,tag) VALUES ('$ip','$url','$tag')") or die('MySQL error: '.mysql_error());

$qs = $tag;

}

} else

die('Your tag consists of invalid characters! Only alphabets and numbers allowed! Please press the back button on your browser and choose another tag!');

}

$link = $destination . $qs;

require 'create_template.php';

} else

echo 'Your URL is invalid';

 

?>

===========================

 

Link to comment
https://forums.phpfreaks.com/topic/115896-basic-help-needed/
Share on other sites

Archived

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

×
×
  • 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.