hey101 Posted May 7, 2009 Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/ Share on other sites More sharing options...
jmurch Posted May 7, 2009 Share Posted May 7, 2009 Does the other site receive the data POST or GET? If it's GET put it in the URL. If it POST put the URL of the other site in the form action. Jeff Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828696 Share on other sites More sharing options...
hey101 Posted May 7, 2009 Author Share Posted May 7, 2009 they receive it through post. I dont want the user to have to refill in the form so passing it along in an invisible form would be nice if its possible Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828699 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Put them in a session. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828705 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Look into curl as that will allow you to send data via POST to an outside website. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828706 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Oh I assumed it would be the same site. Don't mind my previous post. Sorry! Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828708 Share on other sites More sharing options...
hey101 Posted May 7, 2009 Author Share Posted May 7, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828714 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 PHP Curl Send Post Data Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828725 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 We can't tell you if cURL is installed on both servers. We assume it is. As long as PHP is installed, it should have it. cURL Edit - if you think you'll understand cURL by reading, you're sadly mistaken. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828728 Share on other sites More sharing options...
hey101 Posted May 7, 2009 Author Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828745 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 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. PHP Using Variables Inside an Array Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828750 Share on other sites More sharing options...
hey101 Posted May 7, 2009 Author Share Posted May 7, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828772 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 That's not what that person is trying to say. Don't worry about that post. Just figure out what *you* need to do. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828775 Share on other sites More sharing options...
hey101 Posted May 7, 2009 Author Share Posted May 7, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-828997 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 What are you trying to pass over? Other than that copied code you got off somewhere, you haven't given us anything to help you with. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-829014 Share on other sites More sharing options...
hey101 Posted May 8, 2009 Author Share Posted May 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-829107 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 var_dump($returndata); Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-829131 Share on other sites More sharing options...
hey101 Posted May 8, 2009 Author Share Posted May 8, 2009 which script do i place that in and where do i place it? Im guessing the first script at the end? Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-829139 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 *Ken2k7 glares at hey101 You only have *ONE* script that has the variable $returndata in it. Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-829141 Share on other sites More sharing options...
hey101 Posted May 8, 2009 Author Share Posted May 8, 2009 Sorry i wasn't even thinking before i posted that. sorry I will ttest it in a minute Quote Link to comment https://forums.phpfreaks.com/topic/157257-php-pass-variables-to-another-php-script/#findComment-829145 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.