Jump to content

Passing variables invisibly


Longlands

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'];

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.