poojajoshi Posted February 11, 2015 Share Posted February 11, 2015 if i have one url say www.example1.com.I want to display the same contents on another url say www.example2.com.How can i do it using php code? Quote Link to comment https://forums.phpfreaks.com/topic/294525-how-to-post-data-from-one-url-to-another-url/ Share on other sites More sharing options...
l0gic Posted February 11, 2015 Share Posted February 11, 2015 If it's exactly the same content, can you just redirect www.example2.com to www.example1.com ? Quote Link to comment https://forums.phpfreaks.com/topic/294525-how-to-post-data-from-one-url-to-another-url/#findComment-1505418 Share on other sites More sharing options...
kierany5 Posted February 11, 2015 Share Posted February 11, 2015 Not quite sure what you are asking exactly. If you want to redirect them, then <?php header('Location: http://www.example2.com'); die(); If you want to get the content from example2.com, then you have a couple of options. Remote file open or cURL (if you have it installed) are the two the spring to mind. Personally, I would use cURL: <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://www.example2.com'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // If 0, curl_exec will print data $content = curl_exec($curl); ?> This can slow down your script quite a bit though... Quote Link to comment https://forums.phpfreaks.com/topic/294525-how-to-post-data-from-one-url-to-another-url/#findComment-1505438 Share on other sites More sharing options...
Psycho Posted February 11, 2015 Share Posted February 11, 2015 Or, you can just set the target of the form (on Domain1) to point to the receiving page on Domain2. Of course, if you are doing this to POST data to a site you don't control, they may have safefuards in place to prevent such POSTs. If so, curl() woudl be the answer. Quote Link to comment https://forums.phpfreaks.com/topic/294525-how-to-post-data-from-one-url-to-another-url/#findComment-1505448 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.