Jump to content

How to forward all variables to another URL ?


adrianTNT

Recommended Posts

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

[code=php:0]
$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 . "\">"
[/code]
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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

[url=http://nl2.php.net/manual/en/ref.curl.php]http://nl2.php.net/manual/en/ref.curl.php[/url]
[url=http://curl.haxx.se/libcurl/php/]http://curl.haxx.se/libcurl/php/[/url]
[url=http://www.zend.com/pecl/tutorials/curl.php]http://www.zend.com/pecl/tutorials/curl.php[/url]
[url=http://www.phpit.net/article/using-curl-php/]http://www.phpit.net/article/using-curl-php/[/url]

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

Link to comment
Share on other sites

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: "[b]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)[/b].
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.


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

Thanks for all the replies, I posted first time here and looks like a nice forum.
Link to comment
Share on other sites

[quote author=corbin link=topic=103482.msg412114#msg412114 date=1155078236]
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?
[/quote]
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 :)
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.