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! Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/ 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.. } Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222396 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 Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222397 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... Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222417 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 Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222420 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 "); } ?> Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222421 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 "); ?> Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222422 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 "); ?> Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222430 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. Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222437 Share on other sites More sharing options...
spraypray12 Posted April 5, 2007 Share Posted April 5, 2007 Hey no problem man. Link to comment https://forums.phpfreaks.com/topic/45780-ifdo-nothing-else-do-something/#findComment-222457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.