R
Rhazz
Gamma
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
if(eregi($valid, $url))
if(preg_match('<'.quotemeta($valid).'>i', $url))
tienes
if(eregi($valid, $url))
if(stripos($url,$valid) !== false)
No entendí :ambivalence: no pude hacer lo que me indicas.Hola
lo puedes cambiar por preg_match pero posiblemente te de un error depéndiendo de las variables $valid, $url ya que no acepta delimitadores alfanuméricos ahi.
o sea en la url tienes que agregar por cada / una \
Pruaba
Saludos
Me da como resultado siempre "$l_invalidurl", es decir, me sale el mensaje de que el URL que inserté para acortar no es válido (el script que quiero arreglar es un acortador de URLs).Hola,
Reemplaza la primera línea:
PHP:if(eregi($valid, $url))
Por esta:
PHP:if(preg_match('<'.quotemeta($valid).'>i', $url))
Y prueba.
Saludos.
Esta función quedó obsoleta desde php 5.3
Editado: no dije nada XD
PHP: eregi - Manual
Funciones deprecated en PHP 5.3.x (ereg y eregi) | 3VASES BLOG
Me pasa lo mismo que con el código de [MENTION=737]gersun[/MENTION].tienes
PHP:if(eregi($valid, $url))
pon:
PHP:if(stripos($url,$valid) !== false)
<?php
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Short URL script</title>
<style type="text/css">
<!--
body {
font-family:Geneva, Arial, Helvetica, sans-serif;
font-size:0.9em;
}
a, a:hover, a:visited {
color:#d20000;
}
form {
padding:15px;
margin:0;
border:1px solid #dddddd;
width:50%;
}
form label {
font-weight:bold;
padding-right:10px;
}
form input {
border:1px solid #dddddd;
border-right:2px solid #cccccc;
border-bottom:2px solid #cccccc;
padding:4px;
}
form input.button {
background-color:#D20000;
font-weight:bold;
font-size:0.8em;
color:#ffffff;
border:1px solid #FF0505;
border-right-color:#9E0000;
border-bottom-color:#9E0000;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
//-->
</style>
</head>
<body>
<?php
/*
*
* script by spyka Webmaster - www.spyka.net
* version 1.0.2
* copyright (c) 2008 spyka Web Group
* license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0
* support: http://www.spyka.net/forums
*
*/
/*
location of file to store URLS
*/
$file = 'urls.txt';
/*
use mod_rewrite: 0 - no or 1 - yes
*/
$use_rewrite = 1;
/*
language/style/output variables
*/
$l_url = 'URL';
$l_nourl = '<strong>No URL supplied</strong>';
$l_yoururl = '<strong>Your short url:</strong>';
$l_invalidurl = '<strong>Invalid URL supplied.</strong>';
$l_createurl = 'Make shorter!';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if($action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if($action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
//////////////////// FEEL FREE TO EDIT BELOW ////////////////////
?>
<!-- start html output -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p class="response"><?=$output?></p>
<p>
<label for="s-url">URL:</label>
<input id="s-url" type="text" name="url" />
</p>
<p>
<input type="submit" class="button" name="create" value="<?=$l_createurl?>" />
</p>
</form>
<p>Short URL script (1.0.2) by <a href="http://www.spyka.net">spyka Webmaster</a></p>
<!-- end html output -->
</body>
</html>
<?php
ob_end_flush();
?>
if(eregi($valid, $url))
if(preg_match('<^(https?|ftp)://([a-z0-9\-]+\.)+[a-z]+(:[0-9]+)?/[a-z0-9_\-\?\&\=/]*>i',$url.'/'))
if(filter_var($url, FILTER_VALIDATE_URL))
Hola,
Sin información no podemos ayudarte. Ahora veo qué variables lee esa línea; $valid es una expresión regular (RegEx), muy poco optimizada por cierto. El uso de stripos() no corresponde, no funciona con RegEx.
Puedes reemplazar:
PHP:if(eregi($valid, $url))
Por esto otro:
PHP:if(preg_match('<^(https?|ftp)://([a-z0-9\-]+\.)+[a-z]+(:[0-9]+)?/[a-z0-9_\-\?\&\=/]*>i',$url.'/'))
Usa una RegEx más compleja si quieres.
Si tienes PHP 5.2 o sup, lo ideal sería:
PHP:if(filter_var($url, FILTER_VALIDATE_EMAIL))
Saludos
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?