0

I'll try to make a script if the user is redirected to

http://example.com/?url=http://badsite.com

that the script reacts at the URL and displays an echo saying "Not secure", just like the Twitter and Google system, they also check if the URL is harmful.

I've found something, but this isn't what I was seaching for. Google couldn't help me, it gave me all vague answers.

<?php
$badsite = "http://badsite.com";
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if($host == $badsite) {
    echo "Secure, redirecting you";
} else {
    echo "NOT SECURE";
}
?>

It isn't working as it should, it always displays "Not secure", while the link is secure. I think there's a error somewhere, but I need help fining it.

EDIT

<?php
$badsite = "http://badsite.com";
$host = $_GET['url'];

if($host == $badsite) {
    echo "Secure, redirecting you";
} else {
    echo "NOT SECURE";
}
?>

Ive tried, but it's still not working :(

Let me make the question a littlebit easier, how can I make it so if the url is

http://example.com/?url=Texthere

that there will be an echo on the page with "this is the page of texthere" and if "Texthere" isn't in the URL, that the echo won't be displayed?

11
  • And your question is now? Commented Feb 28, 2015 at 11:33
  • @Rizier123 What's wrong with this script, and if someone has a better script, maybe can they link me to that page? Commented Feb 28, 2015 at 11:36
  • What's wrong with this script Nothing, what should be wrong? What do you want/need? Commented Feb 28, 2015 at 11:36
  • @Rizier123 It isn't working as it should, it always displays "Not secure", while the link is secure. I think there's a error somewhere, but I'm a starter so I don't know where Commented Feb 28, 2015 at 11:39
  • @CarlJohnson Try: $host = $_GET["url"]; Commented Feb 28, 2015 at 11:40

1 Answer 1

1

Change your $host variable and if statement like that:

$host = "http://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if($host != $badsite) {
echo "Secure, redirecting you";
}

This worked just fine for me (tested). You need to include http:// into your variable, and your if statement was wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.