Jump to content


Photo

How to forward all variables to another URL ?


  • Please log in to reply
9 replies to this topic

#1 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 08 August 2006 - 08:50 PM

Hello.


I have a script that receives some variables form another server.
I would like to forward all these variables to another URL.
Any ideas on hwo to do that? I am not very familiar with PHP but it must have some functions for that.

Thank you.
Let me know if I wasn't clear enough.

- Adrian.

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 09:00 PM

More detail would be nice... Does your page recieve it through POST or GET and does the other page recieve it thru POST or GET?
Why doesn't anyone ever say hi, hey, or whad up world?

#3 arianhojat

arianhojat
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 08 August 2006 - 09:02 PM

1. Can redirect to that url. but append the variables maybe like url2.php?var1=xxx&var2=xxx&var3=xxx
Definately works but not secure since variables in the url are seen.
2. that or maybe store variables in a Session and get those variables in the other file if its on same server. if the otehr file is on another server, i dont think you can pass the session info along


#4 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 08 August 2006 - 09:08 PM

Hello.

The script I am trying to modify is an "Instant Payment Notiffication" script for 2checkout.com (like paypal.com), when I sell something this IPN service sends info to my site, variables contain order amount, client name, amount paid, so that my scrit can process the order and send emails, etc.

2co.com sends variables to my site (by Post I think) but for some reason I need to forward that to another URL that will process the variables, I suppose this second URL reads the variables by GET, as I said I dont know much about php and get/post. Let me know if you need more info, maybe the script code would help.



#5 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 09:31 PM

$p = array(); 
if($_POST) {
foreach ($_POST as $key => $value) {
$p[$key] = $value;
}
}
foreach ($p as $key => $value) {
if(!$url) {
$url = "?" . $key. "=" . $value;
}
else { $url .= "&" . $key . "=" . $value; }
}
$url = "http://somesite.com/page.php" . $url;
echo "<meta http-equiv=\"refresh\" content=\"0;url=" . $url . "\">"
will forward it with any post variables set converted into get variables... Theres prolly a better way to do this but its what i came up with :D
Why doesn't anyone ever say hi, hey, or whad up world?

#6 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 08 August 2006 - 09:48 PM

I don't really understand why you couldn't process the variables passed to your site directly from 2co.com, but if you have to redirect payment information, I would most certainly avoid passing that information through a URL.

How many servers are involved in this process, just the 2co.com and your web server? If so, you could create a session and register the information you received in the session, redirect to the new URL and grab the information on the new page in the $_SESSION array.

If you have a database that you can save the information to, create a table to hold your sales transactions, and give each transaction a unique ID number, and the you could pass just that ID number through a URL, and then pull the information from the database at the new location.

Barring sessions or a database, you could save the information to a file on your server, and give the file name a randomly generated name, pass that random name through the URL and then pull the information back out of the file for processing.

However, the best method would be to find a way to process that information right after receiving it from 2co.com.

Good luck.

#7 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 08 August 2006 - 09:56 PM

Ever thought of using CuRL? That way you can POST all your variables to the other form. Info on cURL can be found in the PHP documentation, the Zend and a lot of other sites, e.g.

http://nl2.php.net/m...en/ref.curl.php
http://curl.haxx.se/libcurl/php/
http://www.zend.com/...orials/curl.php
http://www.phpit.net...using-curl-php/

I could get you a simple sample on what you are looking for.


RTFM is an almost extinct art form, it should be subsidized.

#8 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 08 August 2006 - 10:00 PM

Thanks for the replies guys.

HeyRay2, I will try to explain why I needed this and how it worked.
2Co.com (payment processor) asks for a script where it sends the payment info, this script needs to be on a certain site, the site that is set in my account. But i have more domains, one is a photo store. The photo store is at a different URL, so I told 2CO: "OK, Send the payment data to www.mysite.com/redirector.php" and redirector.php reads all the data that 2CO sent and forwards it to where I needed it (to the photo store site to a certain script).
The script at the end should be safe because it checks back with 2CO to see if info it received is same as on 2CO server so only after that it sends emails to buyers and process the order.


I just tried corbin's solution (above code) and worked perfect so far, I think everything is OK now.

Thanks for all the replies, I posted first time here and looks like a nice forum.

#9 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 11:03 PM

Uhhh from your description of your problem it seems to me like you have an un-needed step... Why not have 2co.com send the info straight to your final site that is involved?
Why doesn't anyone ever say hi, hey, or whad up world?

#10 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 08 August 2006 - 11:07 PM

Uhhh from your description of your problem it seems to me like you have an un-needed step... Why not have 2co.com send the info straight to your final site that is involved?

Because as I said above "this script needs to be on a certain site, the site that is set in my account".
2Co, the processor, says that they will only send the variables to my main domain, but I need it to send the variables to another domain, so I tricked them :) I made it send to my main domain as they request but that script forwards it to another domain, they do not let me send directley to that domain because is not the one that I have set in my 2co.com account profile. It worked ok with your script :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users