Longlands Posted April 29, 2008 Share Posted April 29, 2008 At the moment I'm passing a bunch of variables from a script on one server to a script on a different server with header("location: http://www.newurl.com?var=$var") and then grabbing them with $vars = $_GET['var'] at the destination. It works fine, but the list of passed variables are displayed in the browser's address bar. Is there a way to pass variables to a script on a different domain without making them visible? Thanks, Martin Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 29, 2008 Share Posted April 29, 2008 Use post. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 Not sure if THAT type of POST will work for him... Easy solution to get the vars out of the address bar is to add some code on server2 that checks for the variables, if they are there, store them in a SESSION then use a header to forward them again to the same page without the variables: <?php session_start(); if(isset($_GET['var'])){ $_SESSION['var'] = $_GET['var']; header('Location: '.$_SERVER['PHP_SELF']); exit; } ?> The variables will still be in the HREF on server1, but the user won't really ever see them. Another option is along the lines of GuiltyGear, which is to use an invisible form (which is messy) where when the user clicks the link to server2, and the onclick fires a form post with a bunch of hidden fields. Do one of those options work for you? I can probably think up some more complicated ones if they don't. Quote Link to comment Share on other sites More sharing options...
Longlands Posted April 29, 2008 Author Share Posted April 29, 2008 Unfortunately, sessions and cookies don't work because the second script is on a different domain. Also, I don't think POST is suitable here because there is no user input to click on a submit button. I'm thinking that writing a text file may be the answer, but it isn't very elegant. Martin Quote Link to comment Share on other sites More sharing options...
Longlands Posted April 29, 2008 Author Share Posted April 29, 2008 Thinking about it, a txt file may not work either as several people could be accessing the script simultaneously, and the variables would be different for each user. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 The SESSION is not to transfer data from one server to another, it's to hold the data on server 2 while removing the data from the URL. POST doesn't have to be initiated by a submit button. You can send a post by adding a javascript onclick to an <a> tag how would a text file work? they are on different servers i thought? more on the SESSION option.... On server1, change nothing. Leave the header("location: http://www.newurl.com?var=$var"); On server2, in index.php, put the code I posted before at the top of the page. Here it is again with some comments: <?php session_start(); //Start the session to store the variables in if(isset($_GET['var'])){ //Check to see if data is being passed $_SESSION['var'] = $_GET['var']; //Store the data header('Location: '.$_SERVER['PHP_SELF']); //Send the user to the page without data in it exit; } //Now we have the var value stored in $_SESSION['var']; //And, the user won't have any data in their URL echo $_SESSION['var']; ?> Quote Link to comment Share on other sites More sharing options...
Longlands Posted April 29, 2008 Author Share Posted April 29, 2008 I see! And it works perfectly. Many thanks, indeed. Martin 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.