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.

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" => "[email protected]",
);

$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.

according to here:

http://us2.php.net/manual/en/language.types.array.php

 

"Using variables as array names no longer works in PHP5."

 

SO is there a way that i can make a variable be pulled as not a variable if you understand what i mean? Like convert a variable into just the text they entered so that way it will work with the array?

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.