Boerboel649 Posted April 5, 2007 Share Posted April 5, 2007 This a super quick and easy question (I hope...) Basically I'm righting a little script that will check the HTTP Referer, and if it equals such and such then to do nothing (ie let the user remain on that page.) If it doesn't equal that then it's gonna redirect them to another page. Basically what I need is how to say "do nothing" in PHP... Would it go something like this? if(blahblahblah){ } ?? Thanks! Quote Link to comment Share on other sites More sharing options...
only one Posted April 5, 2007 Share Posted April 5, 2007 if(whateveritis==NULL){ }else{ do something.. } or if(!whateveritis==NULL){ do something } or if(!whateveritis){ }else{ do something.. } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Instead of testing for the positive and doing nothing, test for the false condtion and do the header: <?php if ($something != $condition) header(" ... "); ?> Ken Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 5, 2007 Author Share Posted April 5, 2007 Good idea kenrbnsn, however having trouble getting it to work... here's the code: <?php $condition = "www.myurl.com/referer.php"; if ($HTTP_REFERER != $condition) header("www.myurl.com/redirectpage.php "); ?> It isn't redirecting me at all... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 That probably should be written as: <?php if ($_SERVER['HTTP_REFERER'] != 'www.steamfootball.com/authorize.php') header("www.steamfootball.com/login.php "); ?> Ken Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 5, 2007 Share Posted April 5, 2007 try printing the value of $HTTP_REFERER to make sure it's the value you're looking for: <?php $condition = "www.steamfootball.com/authorize.php"; echo "condition: {$condition}<br />\n"; echo "http referer: {$_SERVER['HTTP_REFERER']}<br />\n"; if ($_SERVER['HTTP_REFERER'] != $condition){ echo "'if' condition passed requirements"; header("www.steamfootball.com/login.php "); } ?> Quote Link to comment Share on other sites More sharing options...
spraypray12 Posted April 5, 2007 Share Posted April 5, 2007 try: <?php if ($_SERVER['HTTP_REFERER'] != 'www.steamfootball.com/authorize.php') header("Location: www.steamfootball.com/login.php "); ?> Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 5, 2007 Author Share Posted April 5, 2007 Thanks spraypray12! That worked, I just had to change the URL to redirect to. Here's final code: <?php if ($_SERVER['HTTP_REFERER'] != 'www.steamfootball.com/authorize.php') header("Location:/login.php "); ?> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted April 5, 2007 Share Posted April 5, 2007 You might want to include a call to exit() after your call to header(), depending on what follows in the page. Quote Link to comment Share on other sites More sharing options...
spraypray12 Posted April 5, 2007 Share Posted April 5, 2007 Hey no problem man. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.