Jump to content

Dustin013

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

About Dustin013

  • Birthday 05/30/1984

Contact Methods

  • MSN
    dmanz013@hotmail.com

Profile Information

  • Gender
    Male
  • Location
    Sunny Arizona

Dustin013's Achievements

Member

Member (2/5)

0

Reputation

  1. I am just setting up PHP on a new server and I am trying to enable to ability to use <?=$variable?> instead of typing out <?php echo $variable;?> ... Google doesn't really give me any results when searching for the term <?=, so I was hoping someone here could help me out Thanks in advance!
  2. $re1='(Address)'; # Word 1 $re2='.*?'; # Non-greedy match on filler $re3='(Request)'; # Word 2 if ($c=preg_match_all ("/".$re1.$re2.$re3."/is", $txt, $matches)) { $word1=$matches[1][0]; $word2=$matches[2][0]; print "($word1) ($word2) \n"; } The above will output (Address) (Request). What do I do if I want to grab the filler in between those two words?
  3. Thanks for the tip.. got rid of the foreach loops there ;-) Still doesn't seem to work.. I am thinking it might be the way I am building the arrays? Here is the segment of code .. its from the Interspire Shopping Cart.. I am adding the ability to track individual sales and quantities of items ordered to be passed to Post Affilliate Pro. // Include the conversion tracking code for affiliates foreach ($this->pendingData['orders'] as $order) { if (strlen(GetConfig('AffiliateConversionTrackingCode')) > 0) { $converted_code = GetConfig('AffiliateConversionTrackingCode'); $converted_code = str_ireplace('%%ORDER_AMOUNT%%', $order['ordsubtotal'], $converted_code); $converted_code = str_ireplace('%%ORDER_ID%%', $order['orderid'], $converted_code); // Edit by Dustin to grab Product_ID //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $query_proid = "SELECT * FROM isc_order_products WHERE orderorderid='".$order['orderid']."'"; $result_proid = mysql_query($query_proid); $prod_id = ''; // Soon to be a string of product info $java_arr = array(); // Java string array $java = ''; // Soon to be string of javascript calls $img = ''; // Soon to be string of img src // Setup string to look like PRODUCTID:QUANTITY:PRICE, while ($row_proid = mysql_fetch_array($result_proid)) { if ($prod_id == '') { $prod_data = $row_proid['ordprodid'].':'.$row_proid['ordprodqty'].':'.$row_proid['ordprodcost']; } else { $prod_data .= $row_proid['ordprodid'].':'.$row_proid['ordprodqty'].':'.$row_proid['ordprodcost'].','; } } // Explode items seperated by, $prod_ids = explode(",", $prod_data); $prod_count = '1'; // Product Counter // Separate string by , foreach ($prod_ids as $value) { // Split apart string by : (PRODUCTID:QUANTITY:PRICE) $prod_info = explode(":", $value); //$converted_code = str_ireplace('%%PRODUCT_ID'.$prod_count.'%%',$prod_info[0], $converted_code); //$converted_code = str_ireplace('%%QUANTITY_ID'.$prod_count.'%%',$prod_info[1], $converted_code); // Calculate Total Price of each product ID if ($prod_info[1] > '1') { $price_total = $prod_info[1] * $prod_info[2]; // Price multiplied by quantity } else { $price_total = $prod_info[2]; } $converted_code = str_ireplace('%%PRICE_ID'.$prod_count.'%%', $price_total, $converted_code); // Build array of javascript commands $java_arr[] = " <script type=\"text/javascript\"> var sale".$prod_count." = PostAffTracker.createSale(); sale.setTotalCost('".$price_total."'); sale.setOrderID('".$order['orderid']."'); sale.setProductID('".$prod_info[0]."'); PostAffTracker.register(); </script>"; $prod_count++; // Increase Product Counter by 1 // Img array $img_arr[] = '<img src="https://www.example.com/affiliate/scripts/sale.php?TotalCost='.$price_total.'&OrderID='.$order['orderid'].'&ProductID='.$prod_info[0].'" width="1" height="1">'; } // Image Loop - Returns $img as all img src created in foreach loop $img = implode("", $img_arr); // Build string from array created in for each loop $java = implode("", $java_arr); $converted_code = str_ireplace('%%JAVA%%', $java, $converted_code); // Simply Insert %%JAVA%% into affiliate tracking section of interspire $converted_code = str_ireplace('%%IMG_CODE%%', $img, $converted_code); $GLOBALS['ConversionCode'] .= $converted_code; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // End Edit } Notice the part commented : // Build array of javascript commands What is happening is it is not creating multiple items, only the last item in the cart... what got me thinking its not looping correctly because it is simply replacing the previous information in the array with the next item it loops through... thanks in advance for any suggestions / help :-)
  4. I am building an array from a foreach loop and then using anything foreach loop to build a string to be outputted to HTML. The code I am posting below does this, but when using inside of another script it doesn't seem to work. I am thinking there is a better method I could use when building the final string to be outputted... any suggestions? <?php $prod_id = "1234"; // Sample Product number $img_arr = array(); // Array to place images into $prod_data = "0001:1:100,0002:2:200,0003:1:300,0004:2:400"; // Sample string $prod_ids = explode(",", $prod_data); // Seperate string so into PRODUCTID:QUANTITY:PRICE format foreach($prod_ids as $value){ // Loop through each set of PRODUCTID:QUANTITY:PRICE by , $prod_info = explode(":", $value); // Seperate string yet again by : $img_arr[] = '<img src="https://www.yourdomain.com/sale.php?TotalCost='.$prod_info[2].'&OrderID='.$prod_id.'&ProductID='.$prod_info[0].'" width="1" height="1">'; } // Now take all the img paths build from array, and put into a string to be outputted into HTML foreach($img_arr as $k){ $final = $k.$final; // Could this be done differently? Maybe more effective? } // Output of $final (Used a textbox so you can see the output as HTML) print '<textarea cols="120" rows="20>'; echo $final; echo '</textarea>'; ?>
  5. I am trying to get this to work. I would like to be able to log into my forum and then access the content withing the forums using cURL, then convert the data into something simple html dom can understand so that I can parse and scrape data. The script below will successfully login to a Invision Power Board I have installed on my testing machine. If I echo out any of the content it shows me the "logging in" page, then forwards me to the domain. So before I get any of the parsing and what have you worked out, I simply need to be able to tell the script how to login, then go to the correct forum so that it can begin collecting data so that the page can be parsed. I really am not sure where I am going wrong but it does log you in then forwards the page to the targeted domain from where ever its run. Any suggestions? I was thinking about possibly using stream_context_create, but I could use some advice. Thanks in advance! <?php /* * * The idea of this script is to scrape / parse data from a member protected forum run on Invision Power Board * This is not a hack, but rather an information gathering tool to a forum you already have access to. * The script uses simple_html_dom and cURL. First the user is logged into the site using cURL, * then directed to the correct forum ID, where data can then be scraped / parsed and organized. * */ ini_set('display_errors',1); // Turn error reporting on error_reporting(E_ALL|E_STRICT); // All errors displayed include_once('simple_html_dom.php'); // Simple_HTML_DOM *http://simplehtmldom.sourceforge.net/) // Config ////////////// $url = "http://****.com/ipb/"; // Target URL with a forward slash! $username = "testing"; // Your forum username $password = "testing"; // Your forum password $forum_id = "25"; // The ID of the target forum you want to be logged into ////////////// // End Config // Post Data ////////////// $curlPost = "index.php?act=Login&CODE=01&referer=".urlencode($url)."index.php%3F&UserName=".$username."&PassWord=".$password."&CookieDate=1&showforum=".$forum_id; echo "curlPost :".$curlPost."<br />"; // Start cURL ////////////// $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); // $url is target URL curl_setopt($ch, CURLOPT_HEADER, 1); // return headers curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // Use cookie.txt for STORING cookies curl_setopt($ch, CURLOPT_POST, true); // Tell curl that we are posting data curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); // send post data $html = curl_exec($ch); // Execute! $html contains curl data! curl_close($ch); // Free the memory ////////////// // End cURL // Convert $html into $content for use with simple_html_dom $content = str_get_html($html); // Convert String // Find all article blocks foreach($content->find('div.maintitle') as $content) { // so we are looking for anything in the content of a div with an id of maintitle $item['title'] = $article->find('div.maintitle', 0)->plaintext; // all this data is to be in plain text $content[] = $item; // place into array } // Testing Output //////////////////////////// // You guessed it.. if you each either of these out you get forwarded // to the index.php of the target url, however you get logged in // echo $item; // echo $content; // echo '<pre>'; // print_r($content); // echo '</pre>'; //////////////////////////// // End Testing Output // Loop through the array to get your data foreach($content as $item){ // ya ya ya foreach ($item as $key => $value){ // output contents of array echo $key.' : '.$value.'<br />'; // returns "title : %contents of div%" } echo '<br />'; // space em out } $content->clear(); // free up memory unset($content); // cause you got to ?> Run as is, the script outputs the following before redirecting to the next page curlPost :index.php?act=Login&CODE=01&referer=http%3A%2F%2Fwww.****.com%2Findex.php%3F&UserName=******&PassWord=******&CookieDate=1&showforum=25 nodetype : 5 tag : root attr : Array children : Array nodes : Array parent : _ : Array 0 : HTTP/1.1 200 OK Date: Thu, 04 Jun 2009 02:29:23 GMT Server: Apache Set-Cookie: ipbsession_id=3ea9501cb4aeb7c3aaa5f6044558ac71; path=/; domain=.*****.com; httponly Set-Cookie: ipbipb_stronghold=cdd5a86c4b0dd10032f8ddf41d7443c4; expires=Fri, 04-Jun-2010 02:29:23 GMT; path=/; domain=.*****.com; httponly Set-Cookie: ipbmember_id=******; expires=Fri, 04-Jun-2010 02:29:23 GMT; path=/; domain=******.com; httponly Set-Cookie: ipbpass_hash=92942a37*****257d721b86d6abf6d55; expires=Sat, 04-Jul-2009 02:29:23 GMT; path=/; domain=.*****.com; httponly Set-Cookie: ipbcoppa=0; path=/; domain=.*****.com Set-Cookie: ipbsession_id=2c7ce04ec93d904219a08c31526256d3; path=/; domain=.******.com; httponly Vary: Accept-Encoding Connection: close Transfer-Encoding: chunked Content-Type: text/html
  6. What I am doing is creating a simple page to use with Megashares.com .... if you have a valid account on Megashares and are logged in you can browse to http://d01.megashares.com/?d01=be86c04 for example and you are presented with a link that says Click Here to Download. Well, instead of going through all that, I wanted to create a script that parsed that page to grab the AVI link and paste it directly into the in browser DIVX Player because it starts streaming immediately. Neat huh? I think so... The below code works, but since cURL is run from the server side, its logging in and grabbing a link that can only be access by the server... I need to find an alternative method for allowing me, the client to log into Megashares.com and then grab the contents of the chosen URL to parse for the link directly pointing to the AVI file using the regex below... Suggestions? <?php //Requested URL $urlmega = $_REQUEST['urlmega']; // Not direct path to AVI $urlmega2 = $_REQUEST['urlmega2']; // Direct path to AVI //Login Info $email = "user@email.com"; $password = "yourpassword"; // If Megashares link submitted AND Direct Link to AVI NOT submitted... login to megashares and get direct AVI link if ($urlmega != '' && $urlmega2 == '') { // CURL METHOD $curlPost = "lc_email=".urlencode($email)."&lc_pin=".urlencode($password)."&lc_signin=Sign-In"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $urlmega); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10'); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // Use cookie.txt for STORING cookies curl_setopt($ch, CURLOPT_POST, true); // Tell curl that we are posting data curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $output = curl_exec($ch); // Execute! //echo $output; // Spit out what we found curl_close($ch); // Free the memory } // Load THIS page on first load, this means urlmega or urlmega2 has not been defined.... elseif ($urlmega == '' && $urlmega2 == '') { echo ' <h3>This form will parse, authenticate and play valid Megashares.com links...</h3> Example : http://d01.megashares.com/?d01=be86c04 <div class="box2"> <form name="form" action="megashares.php" method="post"> <input type="text" name="urlmega" size="65"/ value="http://d01.megashares.com/?d01=be86c04"> <br /> Or you can enter a direct link to any URL and attempt to play it with DIVX in browser player.<br /> <input type="text" name="urlmega2" size="65"/ value=""> <input type="submit" name="Submit" value="Roll the Dice" class="button"/> </form>'; } // End Megashares Login // PARSE MEGASHARES URL FOR DOWNLOAD LINK if cURL has ran and $output has contents if ($output != '') { // This REGEX will grab the direct link to the AVI through the pages source $regexp = "%http[^\" >]*?\\webprod(.*).avi%"; if (preg_match_all($regexp, $output, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $match = $match[0]; // $match is now a direct AVI link // echo $match."<br />"; } } } // END PARSE MEGASHARES URL FOR DOWNLOAD LINK if ($match != '') { // PLAYER EMBED echo "<object classid='clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616' width='512' height='384' codebase='http://go.divx.com/plugin/DivXBrowserPlugin.cab'>". "<param name='custommode' value='none' />". "<param name='src' value='".$match."' />". "<embed type='video/divx' src='".$match."' custommode='none' width='512' height='384' pluginspage='http://go.divx.com/plugin/download/'>". "</embed></object>". "<br>No video? Get the DivX Web Player for <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayerInstaller.exe'>Windows</a> or <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayer.dmg'>Mac</a>"; echo '<br />Attemping to play the following URL :<br />'; echo $match."<br />"; // END PLAYER EMBED } if ($urlmega2 != '') { // PLAYER EMBED FOR DIRECT AVI LINK echo "<object classid='clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616' width='512' height='384' codebase='http://go.divx.com/plugin/DivXBrowserPlugin.cab'>". "<param name='custommode' value='none' />". "<param name='src' value='".$urlmega2."' />". "<embed type='video/divx' src='".$urlmega2."' custommode='none' width='512' height='384' pluginspage='http://go.divx.com/plugin/download/'>". "</embed></object>". "<br>No video? Get the DivX Web Player for <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayerInstaller.exe'>Windows</a> or <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayer.dmg'>Mac</a>"; // END PLAYER EMBED } ?>
  7. Actually, went outside and smoked a cig and gave it some thought... here is what I have done and it worked ;-) <?php // Set paths to home and SVN $homedir = "/home"; $svndir = "/svn"; function returnDirectory($dirname) { $ignore= array('.', '..'); $files = array(); if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(!in_array($file, $ignore)){ $files[] = $file; } } closedir($handle); } return($files); // this will return an array of files } // Build array for home directory $homearr = returnDirectory($homedir); sort($homearr); // Build array for svn directory $svnarr = returnDirectory($svndir); sort($svnarr); // Output files that are IN the home directory and NOT in the SVN directory echo '<br /><b>Projects currently NOT in SVN</b><br />'; foreach($homearr as $file){ if(!in_array($file, $svnarr)){ $files[] = $file; echo $file."<br />"; } } // Output the names of directories that are in BOTH the HOME directory and SVN directory echo '<br /><b>Projects currently in SVN</b><br />'; foreach($homearr as $file){ if(in_array($file, $svnarr)){ $files[] = $file; echo $file."<br />"; } } ?>
  8. I have a function that is returning the directory names from a given path. These directory names are placed into an array. I would like to call the function twice and compare the contents of the array... (The below code works, just wanted to give an example of what I am trying to do) function returnDirectory($dirname) { $ignore= array('.', '..', '.cpan', '.cpcpan', 'MySQL-install'); $files = array(); if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(!in_array($file, $ignore)){ $files[] = $file; } } closedir($handle); } return($files); // this will return an array of files } // List files in home directory $filearr = returnDirectory('/home'); sort($filearr); foreach($filearr as $file){ echo $file."<br />"; } // End listing files for home directory // If I want to also scan another directory using the same function // List files in svn directory $filearr2 = returnDirectory('/svn'); sort($filearr2); foreach($filearr2 as $file){ echo $file."<br />"; } // End listing files for svn directory Basically, what I would like to do, is compare the two arrays. What I am trying to do is make two listings, one that outputs directories that "ARE IN BOTH" the /home directory and the /svn directory. The other listing would show the directories that are in the home directory, but "NOT" in the SVN directory. So all and all, I guess I just need to figure out the best way to compare the arrays. I have looked at the array_search function, which I would technically use but it seems rather inefficient. Any suggestions are greatly appreciated! Any suggestions on how to get this accomplished?
  9. I have been playing around with an ahref link that calls up download.php for instance.. download.php serves the file without redirecting the page to the actual file. What I would like to do is tell a link to download a file, then forward the page to a congratulations page. Any suggestions? I was thinking I might have to create a flash button, but I would rather just learn how its done in PHP. Thanks!
  10. So I have a script that is scanning a directory to grab the file names for use in a gallery. However, for some reason I can't get it to sort the files alphabetically. I have tried to comment the code to give you a good idea of what I am doing, and where I am thinking I am missing stuff. So, any suggestions would rock, but most importantly I can't figure out why not ordering the contents of the directory according to file names in alphabetical order. <?php function returnimages($dirname="images/gallery/images/refacing/") { $pattern="\.(jpg|jpeg|png|gif|bmp)$"; $files = array(); if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ echo $file.":"; // Ok so I don't want an echo here, I was attempting to pass all the file contents to the variable $files that is returned with each filename separated by a ":" so that I can explode them. } } closedir($handle); } return($files); // this will return something like this (refacing-08.jpg:refacing-18.jpg:refacing-01.jpg:refacing-14.jpg:refacing-13.jpg:refacing-04.jpg) // Notice how the array is out of order. The file names are named blah01, blah02, etc... yet it randomly orders them. } // Now I call the function to output the files... this is where I am all jacked up, but nevertheless will give you an idea of what I am trying to do. // Start Gallery $filearr = returnimages(); // I was trying to place the contents of the $files array into $filearr but all it does it echo the files $filename = explode(":", $filearr); // Then I was trying to explode the array of filenames as $filename sort($filename); // Put the array into alphabetical order?? foreach($filename as $i => $value){ // For everyfile found, I wanted to output the following echo '<li><h3></h3><span>images/gallery/images/refacing/'.$i.'</span><p></p><a href=""><img src="images/gallery/images/refacing/thumbs/'.$i.'"> </a></li>'; } echo '</ul><div id="txtContainer" class="float-left">'; // End Start Gallery ?> Now the above really doesn't work, so I will show you the original code I have that works, yet doesn't put the file names in order... <?php $pageURL = 'window-gallery'; include('includes/global.php'); include('includes/page-info.php'); $glbl = new specialIncludes(); $ctrl = new mainControls(); echo $glbl->globalHeader($title, $metaDesc, $metaKeys); function returnimages($dirname="images/gallery/images/windows/") { echo '<ul id="slideshow">'; $pattern="\.(jpg|jpeg|png|gif|bmp)$"; $files = array(); if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ echo ' <li><h3></h3><span>images/gallery/images/windows/'.$file.'</span><p></p><a href=""><img src="images/gallery/images/windows/thumbs/'.$file.'"></a></li> '; } } closedir($handle); } echo '</ul><div id="txtContainer" class="float-left">'; return($files); } // Start Gallery returnimages(); // End Start Gallery ?> I have been reading all morning and simply can't figure it out, so any suggestions would be helpful. Thanks again!
  11. I have tried var = $content_data[$row_name]; var = $content_data[$this->row_id]; Both don't return a value so I get the Catchable fatal error: Method fetchValue::__toString() must return a string value in C:\xampp\htdocs\Fluidcontent\main.php on line 91
  12. Thanks!!! That solved that part! Now, one last syntax issue.... $this->var = $content_data['page_name']; this line, I am manually typing the row name, what I would like to do is use the variable $this->row_id ... When I type it out, $var = $content_data['$this->row']; doesn't get a value because the syntax ['$this->row']; is incorrect... I have tried a few different ways but none have seemed to work. Is it possible to use a variable to determine which row should be assigned when using mysql_fetch_array? class fetchValue { public function __construct($table_name, $row_name) { $this->table_id = $table_name; $this->row_id = $row_name; $content_query = "SELECT $this->row_id FROM $this->table_id LIMIT 1"; $content_result = mysql_query($content_query) or die(mysql_error()); $content_data = mysql_fetch_array($content_result); $this->var = $content_data['page_name']; } public function __toString() { return $this->var; } } $var = new fetchValue(page_info, page_name); echo $var;
  13. Ok so here is where I am at now // Query database for value of requested row // Example : $requested_value = (new fetchValue(global_data, id)); // This returns the value of the row "id" in the table "global_data" class fetchValue { protected $table_name, $row_name; public function __construct($table_name, $row_name) { $this->table_id = $table_name; $this->row_id = $row_name; echo "The table name passed is named <b>".$this->table_id."</b><br />"; echo "The row name passed is named <b>".$this->row_id."</b><br />"; $content_query = "SELECT $this->row_id FROM $this->table_id LIMIT 1"; echo "The query executed was : <b>".$content_query."</b><br />"; $content_result = mysql_query($content_query) or die(mysql_error()); $content_data = mysql_fetch_array($content_result); echo "Manually printing the value of page_name from query: <b>".$content_data['page_name']."</b><br />"; // page_name is the variable passed, however, I shouldn't have to put in page_name, I would like to use $this->row_id! $var = $content_data['page_name']; echo "var has a value!!! The query is at least working! : ".$var; return $var; } } // Retrieve Page Info /////////////////////// $obj = new fetchValue(page_info, page_name); echo $obj->__toString(); The error generating from running this script... The table name passed is named page_info The row name passed is named page_name The query executed was : SELECT page_name FROM page_info LIMIT 1 Manually printing the value of page_name from query: aboutus var has a value!!! The query is at least working! : aboutus Fatal error: Call to undefined method fetchValue::__toString() in Using $var = $content_data['page_name'] then returning $var gives us the content from the table which is currently : "aboutus" What I am trying to do is place the variable passed ($row_name) into content_data['row_name'] so that it doesn't have to be manually defined like I did it above. The syntax $var = $content_data['$this->rowid'] is incorrect...?? I am slowly driving myself insane.. hehe.. thanks for the help so far guys!
×
×
  • 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.