slpctrl Posted December 1, 2007 Share Posted December 1, 2007 Hello, I need to use cURL to get a page, then have it decrypt a random encrypted string, it's just on the page. How might I do this? The encryption type is base64. Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/ Share on other sites More sharing options...
Orio Posted December 1, 2007 Share Posted December 1, 2007 First you need to use a regular curl request to fetch the data of the page. Then you'll need to use some regex to keep only the part of the page you want, and then it's just about using base64_decode(). Getting the contents of the page shouldn't be a problem, a regular curl query. Obtaining the part of the text you need is generally the tricky part- but that depends on how the HTML of that page looks like. If you are having problems with this part, post here (or in the regex board) how the HTML looks like (some kind of an example), and someone will help you find out how get the part you need. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/#findComment-403476 Share on other sites More sharing options...
slpctrl Posted December 1, 2007 Author Share Posted December 1, 2007 The section of the page is seperated with the <div> tag like so: <div class='main-body'> <div style="text-align: center;"> <br /><br /> Random string: X3AtMGssLGB6KDZhY2lgXw==<br /><br /> </div> How do I use that to retrieve the text? The encoded text is surrounded by text. Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/#findComment-403797 Share on other sites More sharing options...
Orio Posted December 1, 2007 Share Posted December 1, 2007 So you can use a simple regular expression to get the data: <?php preg_match_all("/Random string: ([a-zA-Z0-9=+\/]*)/", $html, $matches); print_r($matches[1]); ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/#findComment-403847 Share on other sites More sharing options...
slpctrl Posted December 1, 2007 Author Share Posted December 1, 2007 So you can use a simple regular expression to get the data: <?php preg_match_all("/Random string: ([a-zA-Z0-9=+\/]*)/", $html, $matches); print_r($matches[1]); ?> Orio. Alright, this is very close to what I need. Now, after some adjusting I've got the random string however it's in an array with only 1 element. How can I get that array to be a plain text variable with only the string? Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/#findComment-403866 Share on other sites More sharing options...
MadTechie Posted December 1, 2007 Share Posted December 1, 2007 <?php $str = $matches[1]; echo $str; ?> if that doesn't work can you post the results of print_r($matches[1]); Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/#findComment-403885 Share on other sites More sharing options...
Orio Posted December 2, 2007 Share Posted December 2, 2007 The result is in $matches[1][0] Orio. Quote Link to comment https://forums.phpfreaks.com/topic/79642-solved-retrieve-random-string-from-page-using-curl/#findComment-404112 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.