windowsdan Posted October 21, 2013 Share Posted October 21, 2013 I'm looking to post links in a 'href=' that are echo'd from a variable, that is gotten from a 'file_get_contents' command, to the next page when they are clicked on. Is this possible?? Example: <?php $html = file_get_contents('http://www.DOMAIN.com/file.html'); echo $html //HERE I NEED THE file.html TO HAVE THE href= ADDRESSES INSIDE IT POSTED TO NEXT PAGE WHEN CLICKED ON //THE HTML MAY CONTAIN: <body>something <a href="/file4.html"</body> AND I WOULD NEED THAT ANCHOR TO POST THE 'href'TO THE NEXT PAGE i.e. POST /file4.html > page.php ?> I hope this has been explained enough, ask if more info is required thanks! Quote Link to comment Share on other sites More sharing options...
.josh Posted October 22, 2013 Share Posted October 22, 2013 use DOMDocument::loadHTMLFile to load the page and DOMDocument::getElementsByTagName to get the links off the page. Quote Link to comment Share on other sites More sharing options...
windowsdan Posted October 22, 2013 Author Share Posted October 22, 2013 (edited) IT HALF WORKS!! Thanks for the response, however, I haven't used that before; I did get somewhere though. I have gotten to this point: <?php $link = $_POST['link']; $link = strtr($link, array(' ' => '+',)); $html = file_get_contents('http://www.DOMAIN.com/results?search='.$link.""); $html = strtr($html, array('href="/' => 'href="http://www.DOMAIN1.com/index.php?incoming=http://www.DOMAIN2.com/',)); echo $html; ?> But I would like to have the href link (stay clickable as a link) but POST the data instead so it's not show in the URL. The only problem is that I could only seem to use the GET command because passing a variable through a link click is written to a GET. Any ideas? Edited October 22, 2013 by windowsdan Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 22, 2013 Share Posted October 22, 2013 You'll need to use curl to send data via post. Data passed in the url will always be sent via GET To properly targer all links you need to do as .josh suggest. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 22, 2013 Share Posted October 22, 2013 Is there a reason you don't want to use GET? If you must use POST, you could look into using HTML forms and buttons instead of the links. Quote Link to comment Share on other sites More sharing options...
.josh Posted October 22, 2013 Share Posted October 22, 2013 maybe it would be more helpful if you explain what you are actually trying to do here. It *seems* that you are wanting to make a bot that automatically clicks links on a given page. Quote Link to comment Share on other sites More sharing options...
windowsdan Posted October 22, 2013 Author Share Posted October 22, 2013 Ok I'll explain what it is that's happening. I have built a Proxy within one of my websites that works fine until it comes to YouTube! When it comes to that I can get the users to search YouTube and have the page echo'd with the right results and change the video links to what I want i.e. a pass through to another php page. The reason I need to do this is because YouTube videos with ads or Vevo etc won't allow the video to stream to a separate WAN IP to the page load. I have achieved this perfectly by using PHP in combination with a command line program called 'Youtube-DL' where by the php calls the commands required to download user selected video to the server and then stream it back to the user in an HTML 5 embedded video (with flash fallback). Everything works great except the problem I have with the links. In order for it to look like the youtube page, I need the page to mostly be echo'd identical but for the user to be able to click the video link and be taken to the embedded player for playback. BUT .... the idea of a proxy is that none of the URL's that the pages are loading appear in the URL bar. I would just love to get over this last hurdle Quote Link to comment 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.