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