0

I'm still learning PHP and just starting to get to grips with it.

$url = $_SERVER['REQUEST_URI'];
$user = $_SERVER['HTTP_USER_AGENT'];

if ($url == "/example.php" && $user == "HelloWorld")
	echo "";
else 
	Header("Location: http://www.google.co.uk");

Basically what I'm trying to achieve is when the useragent is "HelloWorld" and the URL is [root]/example.php the user stays on the page ... otherwise they're redirected to google...

But, I'm being redirected to Google both when my useragent IS HelloWorld, and even when the URL ISN'T /example.php ...

All help is hugely appreciated!
Brownie. :)

Edited by brown23: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by pietpiraat
0

I think your problemen is The url.
Try echoing it, you Will see THE problem then.

You are comparing à part of THE url with == this is only possible if you use THE complete url.

Excuse my iPad typing...lol

Edited by pietpiraat: n/a

0

I think your problemen is The url.
Try echoing it, you Will see THE problem then.

You are comparing à part of THE url with == this is only possible if you use THE complete url.

Excuse my iPad typing...lol

Hey man thanks for the reply!

The reason why I did the "/example.php" is because when I echoed it, that' what it said:

$url = $_SERVER['REQUEST_URL'];

echo $url;

I'll have a go at sticking in the full URL - the problem I've got is that I'm using WAMP on my localhost ... so perhaps that could be the problem?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.