dannyluked Posted November 29, 2009 Share Posted November 29, 2009 Hi, I have this code; <?php if(!$_POST[id]){ header('Location: HTTP://EXAMPLE.COM');exit; }else{ } ?> The code works fine! I was just wondering how I can change the 'http://example.com' to a variable that is in a seperate file (config.php)? I am guessing it is something like this although this code dosent work! <?php include "config.php"; if(!$_POST[id]){ header('Location: $thesite');exit; }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/ Share on other sites More sharing options...
Vytas Posted November 29, 2009 Share Posted November 29, 2009 header("Location: $thesite"); This should work. Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967526 Share on other sites More sharing options...
rajivgonsalves Posted November 29, 2009 Share Posted November 29, 2009 you should use double quotes also use isset <?php include "config.php"; if(!isset($_POST[id])){ header("Location: $thesite");exit; }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967528 Share on other sites More sharing options...
mrMarcus Posted November 29, 2009 Share Posted November 29, 2009 in theory will work, if done right. you can't use single-quotes in this situation. you can use double-quotes as any PHP within double-quotes will be parsed, or you can use concatenation: <?php include "config.php"; if(!$_POST[id]){ header('Location:' . $thesite); exit; }else{ } ?> -OR- <?php include "config.php"; if(!$_POST[id]){ header("Location: $thesite");exit; }else{ } ?> all assuming $thesite has been declared in config.php Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967529 Share on other sites More sharing options...
dannyluked Posted November 29, 2009 Author Share Posted November 29, 2009 Thanks guys, they all work! Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967532 Share on other sites More sharing options...
dannyluked Posted November 29, 2009 Author Share Posted November 29, 2009 Just one question! How do I make it go to $thesite/FOLDER Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967533 Share on other sites More sharing options...
mrMarcus Posted November 29, 2009 Share Posted November 29, 2009 using concatenation/string operators: <?php include "config.php"; if(!$_POST[id]){ header('Location:' . $thesite . '/FOLDER'); exit; }else{ } ?> -AND- <?php include "config.php"; if(!$_POST[id]){ header("Location: $thesite/FOLDER"); exit; }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.