sphinx Posted September 24, 2010 Share Posted September 24, 2010 Hi I had it on my old site but forgot what I put in the index.php file. Basicly, I want something like this: http://site.com/index.php?go=home or: http://site.com/index.php?home Does anyone know what I put in the index.php file to specify link and where it redirects too? Thank you. Quote Link to comment Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 everything behind the question mark is called the query string. To get it you use $_SERVER['QUERY_STRING']; for example: echo $_SERVER['QUERY_STRING']; http://localhost/index.php?home will show 'home' http://localhost/index.php?go=home will show 'go=home' Using $_GET will give you an array of all the keys and values in the query string: echo $_GET['go']; will show 'home'. Quote Link to comment Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 yes but it's not a search query, just a link. Quote Link to comment Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 thanks, im getting there, i tried this: <?php $id=5; $location="index.php?id=go"; header( 'Location:http://www.google.com'); ?> if i access my website root, it redirects me too google even without the ?id=go in the link. Quote Link to comment Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 header("location: http://google.com/?id=go"); If you want it in variables: $str = "id=go"; header("location: http://google.com/?". $str ); Quote Link to comment Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 That still redirects on root, Basicly, when user clicks a link which is: http://mysite.com/?redirect it takes them to another part of the site, that code does: http://www.google.com/?id=go when i access root. Quote Link to comment Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 I'm confused. Quote Link to comment Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 this is what i mean: <?php $link = 'http://www.google.com'; if (@$_GET['id'] == 'go') header('Location: ' . $link); ?> but i want it to work like: site.com/?go = redirects to google. instead of: site.com/index.php?id=go Quote Link to comment Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 $link = 'google.com'; if( !empty($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'go' ) { header("location:" . $link); } 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.