Jump to content

PHP pass variables to another php script


hey101

Recommended Posts

Well basically here is what I have so far. I have a form where a user inputs things. Then It sends it to a php script which does some work with it. What I want it to do is have a user send enter the stuff in the form, it then gets submited to my script, and my script passes the variables onto another website.

 

Now I already have the variables sent via post to my script. I need them to be sent on to the other website using post too. I have no control over the other website. I just know what variables i have to send. And i do not want the user to have to enter his info all over again just so it gets sent to the other site.

 

So how can i pass along post variables?

 

I asked at another forum and they said i was trying to do something fishy. well im not because:

 

Its a guys website at my school. He just wants an extra layer of security to where u have to go through my site to get to his. Kinda weird i know but he already has it setup on his side and is reluctant to change it. So I already have everything setup accept this. cookies and all that.

Link to comment
Share on other sites

Look into curl as that will allow you to send data via POST to an outside website.

 

I have tried looking at curl but i do not understand it. It is installed on both servers. Can you post an example on how I could use it?

Link to comment
Share on other sites

I already know it is installed. ok I saw this example on the internet:

 

<?php
$urltopost = "http://somewebsite.com/script.php";
$datatopost = array (
"firstname" => "Mike",
"lastname" => "Lopez",
"email" => "my@email.com",
);

$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch);
?>

 

Well there is an array. And I think that is what gets sent on it looks like. If it is then how do i insert variables in an array.

Link to comment
Share on other sites

ok well i used the code above to send a variable. Well it atleast sends something to the other server because it logs it but it logs nothing. Like i just setup a demo script to test it. the first script logs what the user put in a text file. Then is sopposedly sends that variable to the other script. The other script logs it in a different text file. Both should say this in the text file

test: (whatever was entered in the variable)

 

The first text file is fine. The second text file has just this in it

test:

 

SO what code should i have at the receiving end to actually get the variable that i send?

Link to comment
Share on other sites

ok well heres is what im using to send the variables:

 

$test2 = $_POST['testing'];

$urltopost = "http://websitehere/test.php";
$datatopost = array (
$test2,
);

$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch);

?> 

 

I recieve it using

 

$test = $_POST['test2'];

$test3 = "Test: $test";

$file = fopen("test.txt", "a");
fputs($file, "$test3\r\n");
fputs($file, "\r\n");
fclose($file);

 

there you go. What am I doing wrong since the second file isn't receiving the variable.

 

 

For defining the first variable i use a html form.

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.