Checking validity url in php [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Нi guуs. I russian php noob.
I have the following code:
if($rr['site']) echo '<a target="_blank" href="http://'.$rr['site'].'" class="">'.$rr['site'].'</a>';
Need to make a valid of the user a url HTTP there or not. Otherwise it outputs - http://http://siteurl
Prompt me how to do it? pliz
Maybe, there is a solution - How do I remove http, https and slash from user input in php
but i need an example with my code.
I would be grateful for any help.

I would do the opposite. Instead of removing http:// or https:// and then adding it again, I would just check if the string starts with http:// or https://, and add http:// only if it doesn't.
Something like:
if($rr['site']) {
$url = preg_match('/^https?:\/\//', $rr['site']) ? $rr['site'] : 'http://'.$rr['site'];
echo '<a target="_blank" href="http://'.$url.'" class="">'.$url.'</a>';
}

Related

Escaping regex in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have regexes stored in a txt file. How do I escape them in PHP? preg_quote doesn't help if I use the output in an array, throws fatal error. (The following each are on new lines in the txt file)
/[^a-z\/'"]eval\([^\)]+['"\s\);]+/i
/\$auth_pass\s*=.+;/i
/document\.write\((['"])<iframe .+<\/iframe>\1\);*/i
/preg_replace\s*\(.+[\/\#\|][i]*e[i]*['"].+\)/i
/<\?.+?exec\(.+?system\(.+?passthru\(.+fwrite\(.+/s
/RewriteRule [^ ]+ http\:\/\/(?!127\.).*/i
/<\?[\shp]*\#?error_reporting\(0\);.+?[a-z0-9\/\-\='"\.]{2000}.*?($|\?>)/i
/\<a [^\>]+\>\<span style="color\:\#F1EFE4;"\>(.+?)\<\/span\>\<\/a\>\<span style="color\:\#F1EFE4;"\>(.+?)\<\/span\>/i
/(<!\d)\$[\$\{]*[a-z\-\_0-9]+[\} \t]*(\[[^\]]+\][ \t]*)*\(.*?\)\;/i
/\#(\w+)\#.+?\#\/\1\#/is
/(\$[a-z_0-9]+[=\s\#]+)?create_function\([^,]+,[\s\$\.\[\]a-z_0-9]+[\s\)]+;*/i
/json2\.min\.js/i
/(RewriteCond \%\{HTTP_USER_AGENT\} .+\s+)+RewriteRule \^.*\$ http:\/\/(?!127\.).*/i
/<title>[^<]*hack[3e][rd]/i
I think you need to adjust your call to preg_quote(). Something like this:
Preg_match("|" . preg_quote($str, "|") . "|", $content->content)
See another post with a similar question:
PHP String to Regex

Redirect with email on "?" strange code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm doing a system to reset password and I need pass email on URL like this:
http://example.com/reset?email=email#domain.com&token=89s8ads9
I'm doing this:
return $this->redirect(array(
'controller'=> 'site',
'action'=> 'resetaSenha',
'?'=> array('email'=> 'email=email#domain.com', 'token'=> 89s8ads9)
)
);
But is returning this:
http://example.com/reset?email=email%40domain.com&token=89s8ads9
%40 is # urlencoded.
Something in your code is converting # to %40 for you. http://php.net/manual/en/function.urlencode.php
You can decode it with urlencode($_GET['email']); which will replace the %40 with an #
I did'nt realized that even on url with ?email=email%40domain, when we access from controller $this->request->query['email'], we obtain the email decoded in the right way email#domain.com.
Do a captcha check, and deny access to the e-mail sender after the session var is unset.

url encoding issue. instead %50 its passing space..how to pass %50 through urlencoded url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have tried to pass a variable trough url... its %50.
I am doing urlencoding to pass other languages through the url.
At that time %50 also been converted to a space or something else.
Can anyone help me to find out a way to send %50 as a variable through urlencoded link(url).
<?php
$string = '%50';
echo $encoded = urlencode($string);
// returns %2550
echo urldecode($encoded);
// returns %50
?>
So if you want to pass $string to a url you write something like:
http://yoursite.com/script.php?string=$encoded
To get your original string value you can just use $_GET in your script.php:
echo $_GET["string"];
// returns %50

How to convert to a link using Rrawurldecode()? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a host of files that generate link like this for hosted files:
http://endertec.com.br/hf/see-img.php?img=http://www.endertec.com.br/hf/do.php?imgf=Fav2.png
But when I see link like this on Facebook, it looks like this:
http://endertec.com.br/hf/see-img.php?img=http%3A%2F%2Fwww.endertec.com.br%2Fhf%2Fdo.php%3Fimgf%3Fav2.png
So I researched ways to convert it, and got the following code:
<?php
$str = 'http://www.endertec.com.br'.$_SERVER['REQUEST_URI'];
$src = str_replace('see-img.php?img=' , '' ,stristr($str , 'see-img.php?img='));
string rawurldecode ( string $src )
echo '<img src="'.$src.'"/>';
?>
But for some reason it does not work, does anyone know how it might work?
You need to store your rawurldecode in something.. try something like this:
$decoded_src = rawurldecode($src);
echo '<img src="'.$decoded_src.'" />';

how to wrap inside <a href> all URL occurrence in my query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
alright, i think the solution to my question is to use REGEX, but my current knowledge of it hinders me to achieve the result that i want.
so basically, how do i make all URL occurrence in my posts/text entries to wrap inside an <a href> element when being queried.
when i echo $content; from a database it will display as:
this is a link http://somerandomsite.com, check it out!
but how can i make the link inside a text to be contained in <a href> tag when displayed.
id be honest to say that i dont know how to properly write the syntax. but this is what ive come up with.
//get url from content
$link = strstr($content, 'http://');
//insert <a href> for all $link inside $content
//then display $content with all links wrapped in <href>
$a = 'this is a link http://somerandomsite.com, check it out!';
$a = preg_replace("/\b((?:http\:\/\/)|(?:www\.))([^ ,]+)/", "$1$2", $a);
echo $a;

Categories