Avatar of Ramy Mohsen
Ramy Mohsen
 asked on

how to tell link is safe and trusted

I am developing a PHP web application through Yii2 framework that enable the user to enter any link and display it within iframe I need to know

    is it safe for the web application and user to use this feature (iframe) with his own link
    how to avoid risks
    if the user has entered a link how to tell this link is safe and trusted

Avatar of undefined
Last Comment
Ramy Mohsen

8/22/2022 - Mon
Dave Baldwin

There isn't any way to tell.  If you display it in an iframe, your server code never sees that content because it gets loaded by the user's browser directly into the iframe.
Brittk McGhee

The most excellent proposal I can offer is to browse smart. That means you have to twice check the URL of your,social networking site, and e-mail site before you log in. Its very safe for web application uses this aspect.
Ramy Mohsen

if the user has entered a link can I use a service to tell this link is safe and trusted  or not
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ray Paseur

if the user has entered a link can I use a service to tell this link is safe and trusted  or not
No, you cannot.  Your strategy is risky and dangerous.  It should be avoided.  Here's why.

When you see the link, all you can know is the character string that makes up the URL.  You cannot know what is going to be loaded from that URL.  It can be "safe and trusted" one moment and "toxic and damaging" the next.  You have no control at all.  A client visit to the URL, which is caused by loading in the iframe or browser window, causes your browser to run JavaScript immediately and without warning.  What does the JavaScript contain?  You cannot know what the JavaScript will do to the client machine until the client runs the JavaScript code.

This is part of PHP Security.  There are well-documented standard practices that are necessary to keep users of your web site safe from one another.  You may also want to learn about OWASP and become involved.
Ray Paseur

Couple of thoughts about MyWOT.
I have no way to evaluate these claims, but "buyer beware."

The only way to accomplish your objective is to use a third-party validation service.  I have used MyWOB for this and it meets my needs nicely.  Of course any popular service will have its haters, including this website!  I am not going to argue with Ray anymore about this, but I will say I have used the MyWOB API for three years with great results.

Here is a working prototype accomplishing the request made in your original post.  If you find that it blocks too many sites, you can lower the value of $sensitivity.

$sensitivity = 95;

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

<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />


<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, "utf-8"); ?>" method="post" target="f">
 URL: <input type="text" name="url" />
 <input type="submit" />

 <iframe width="80%" height="200" name="f"></iframe>

else {

$site = $_POST['url'];

$urlinfo = parse_url($site);
if (!isset($urlinfo['host'])) $urlinfo = parse_url('http://' . $site);

$host = preg_replace('/[^a-z0-9\-\.]/i', '', $urlinfo['host']);

$siteReport = json_decode(file_get_contents('http://api.mywot.com/0.4/public_link_json2?hosts='. $host .'/&key=59e026a43597840e5ddefba4d692be8212926801'));

if( !empty($siteReport->{$host}->categories->{'501'}) && $siteReport->{$host}->categories->{'501'} > $sensitivity ) {
 header('Location: ' . $urlinfo['scheme'] . '://' . $host . (empty($urlinfo['path']) ? '' : $urlinfo['path'])  . (empty($urlinfo['query']) ? '' : '?' . $urlinfo['query']), TRUE, 307);
else {
  echo 'Bad Site!'; 



Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ramy Mohsen