
soma56
Members-
Posts
185 -
Joined
-
Last visited
Never
Everything posted by soma56
-
I'm familiar with sending and receiving cookies through cURL... <?php /* STEP 1. let’s create a cookie file */ $ckfile = tempnam ("/tmp", "CURLCOOKIE"); /* STEP 2. visit the homepage to set the cookie properly */ $ch = curl_init ("http://somedomain.com/"); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); /* STEP 3. visit cookiepage.php */ $ch = curl_init ("http://somedomain.com/cookiepage.php"); curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); /* here you can do whatever you want with $output */ ?> I would like to know if someone can point me to a tutorial and/or more information where this can be done through a proxy? I searched Google and couldn't find anything.
-
I have a very basic script. It's a cURL script used to grab the contents of a webpage. I'm attempting to connect through a proxy. The most frequent error message I'm receiving is related to a timeout... CURLE_OPERATION_TIMEDOUT (28) After a few hours of trying different things I decided to try a different server. I instantly noticed a huge difference. The script was working correctly through a proxy on SERVER 2. While I did have 'some success' on SERVER 1 I found the results to be slow and inconsistent. Here is a simplified version of the cURL script: <?PHP ignore_user_abort(true); set_time_limit(0); //Proxy Sources $proxypage = file('newproxies.php'); //Assign Page to Download $BIGG = "www.example.com"; //Proxy Sources $proxypage = file('newproxies.php'); $rand_goodproxy = array_rand($proxypage, 2); $goodproxy = $proxypage[$rand_goodproxy[0]] . "\n"; //Variable for User Agent $agent = "My Agent"; ?> <?PHP if(!function_exists('DownloadBIGG')){ function DownloadBIGG($BIGG){ //Globalize variables global $goodproxy, $proxypage, $BIGG, $agent; // is curl installed? if (!function_exists('curl_init')){ die('CURL is not installed!'); } //Start Output Buffer ob_start(); // create a new curl resource $ch = curl_init(); // set URL to download curl_setopt($ch, CURLOPT_URL, $URL); // set referer: curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/"); // user agent: curl_setopt($ch, CURLOPT_USERAGENT, "$agent"); curl_setopt($ch, CURLOPT_PROXY, "$goodproxy"); //Proxy Tunnel? curl_setopt($ch, curlopt_httpproxytunnel, 1); //curl_setopt ($ch, CURLOPT_HTTPGET, true); // remove header? 0 = yes, 1 = no curl_setopt($ch, CURLOPT_HEADER, false); // should curl return or print the data? true = return, false = print curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // sets how long CURL will run before it gives up curl_setopt($ch, CURLOPT_TIMEOUT, 30); // sets how long CURL will wait to even connect curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // download the given URL, and return output $DLBIGG = curl_exec($ch); //get information $info = curl_getinfo($ch); flush(); ob_flush(); // print output echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); echo "<br />cURL info:"; print_r($info); echo str_pad(" Loaded … ",; sleep(1); flush(); ob_end_flush(); echo $DLBIGG; usleep(100000); curl_close($ch); } }//end if !function does not exist global $info, $firstproxy; $DLBIGG = DownloadBIGG($BIGG); ?> Given that trying the script on another server (SERVER 2) led to success with respect to connecting to a proxy I have a strong suspicion that this has something to do with the server configuration. I should point out that the server that I'm having issues with (SERVER 1) is a VPS with over a gig of ram. SERVER 1 The server that is not responding quickly and otherwise timing out: PHP Version 5.2.9 SERVER 2 Responding quickly through the script and returning the page through a proxy: PHP Version 4.4.9 I'd be more then happy to post the "phpinfo();" information for both servers. I'm wondering if there is an obvious setting that I should be adjusting or looking at in terms of the PHP configuration for the server I'm having issues with. Any help would be greatly appreciated.
-
I have several fields in a database in which some could be blank. I'd like to echo out 'Not Assigned' if that's the case. Based on my limited experience with PHP this is the way I'm going about it: if ($tech == "") { $tech = "Not Assigned"; } if ($crew == "") { $crew = "Not Assigned"; } if ($number == "") { $number = "Not Assigned"; } I'm pretty certain there is a way to simply place all of the variables into an array to determine if they are empty or not - Followed by changing the variable to 'Not Assigned' one time rather then repeating code over and over again. The way I'm doing it will work, however, something tells me there is a much more efficient way.
-
Brilliant. Thanks guys/girls. I ended up simply placing them into a new array and then called the first 5 values for the DB. foreach($_POST['service'] as $service) { $services[] = $service; } And then for the php/mysql insert it was simply a matter of using $service[0], $service[1], etc. It doesn't matter if they're blank or not - however if all 5 are selected then this will place them in an array and subsequently into the database. Thanks Again!
-
I have a table that I must be populated based on a check box selection. The maximum selection is 5, however, there are more then 10 choices. For example: Here is a choice of 10 different (checkbox) options that the user can select from: 1. Coke 2. Root Beer 3. Pepsi 4. Dr. Pepper 5. Sprite 6. 7up 7. Cream Soda 8. Club Soda 9. Water 10. Milk I've already managed to limit the users selection to only 5. My issue is determining which of the checkboxese were actually selected so that I can correctly place them in my database. The first thing to do is create variables from all the checkboxes: $coke = $_POST['coke']; $rootbeer = $_POST['rootbeer']; $pepsi = $_POST['pepsi']; $drpepper = $_POST['drpepper']; etc. etc. Now that I have all 10 selections as variables from a submitted form how can I determine which ones are empty (or which ones have values) so that I can then save them to the database respectively?
-
I'm going through one of those moments where everything logically looks like it should work but it isn't. I have a textarea box that is posting text that contains quotes. The quotes are slipping through my filters. By all accounts should the following code grab any instance of a quotation mark in the manner that I have described? strpos($string,'"') || $string == '"' Note: the above code contains a " between two single quotes.
-
Does/can php reconize quotations beyond the simple example I have below: $quote = "\""; if(strstr($test, $quote)){ echo "quote found"; } I'd like to detect any instance of a quote. Should I be including html such as " and/or other html quote symbols? Or does the simple example I have above suffice?
-
Thanks guys. Ironically there is not hyphens - I just renamed everything to present a simply and logical example for everyone to see. In any event you got me thinking about trimming the whitespace which led to the discovery of a solution. Instead of exploding the array with '\n' I tried '\r' which magically solved the problem
-
I know this works and that's why I'm puzzled. I'm bringing in data from a textarea and trying to compare it. index.php <form name"fruit-farm" action="fruit-check.php" method="POST"> <textarea name="fruit-list"> Apples Bananas Oranges Pickles Hamburgers Grapes </textarea> <input type"submit" name="submit" value="Check The Fruit"> </form> fruit-check.php if (isset($_POST['submit'])) { //Bring in the data $fruit-list = explode("\n", $_POST['fruit-list']); //Search for Hamburgers $hamburgers = "Hamburgers"; if (in_array($hamburgers,$fruit-list)){ echo "That is not a fruit"; } } What's puzzling me is that it's not working. It must be something blantently obvious. It has something to do with the '$fruit-list' array and how it is being brought into the form. It posts fine. The reason I think this is the case is because if I simply create an array that is identical to the form coming in it works: if (isset($_POST['Submit'])) { //Bring in the data $fruit-list = explode("\n", $_POST['fruit-list']); //Search for Hamburgers $hamburders = "Hamburgers"; $fruit-list = array('Apples', 'Bananas', 'Oranges', 'Pickles', 'Hamburgers', 'Grapes); if (in_array($hamburders,$fruit-list)){ echo "That is not a fruit"; } } When I 'print_r' both arrays they both look identical. What is wrong and/or different with the way I'm bringing in the textarea that's causing this not to work?
-
Thank you. I'm sure that will work fine. I appreciate your time.
-
Yes, I suppose I could. I was trying to avoid it. Here's the traditional logic: > Browse and upload file to server > Grab contents from uploaded file This is what I want to do: > Browse and upload contents of file to textarea Is this possible?
-
I hope someone can help me out with this. What I would like to do is import a text file dircetly to a text area. I can't seem to find any examples on this (Yes I did search Google). I know how to upload but I'm not interested in storing files on the server - but rather just importing them directly to a textarea. Can anyone point me in the right direction? I can upload: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> I can read: $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') But I'm not interested in either of these as they are unnecessary steps (or are they?). Is there not a way to simply browse/import a text file directly to a textarea (or anywhere for that matter) without having to actually save the file to the server? Something like this: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> //uploader.php if (isset($_POST['submit'])) { $content = $_POST['"grab the contents of the file"']; echo "<textarea>"; echo $content; echo "</textarea>"; }
-
Thanks. I understand now. I suppose there is no easy way to do with $_POST? I have several dozen pages to revise now...
-
I'm trying to figure out a way to post data directly to a URL. For example: <?php if (isset($_POST["pass"]) && ($_POST["pass"]=="$password")) { echo "You did it"; ?> <?php } else { echo "<form method=\"post\"><p align=\"left\">"; echo "<input name=\"pass\" type=\"text\" size=\"25\" maxlength=\"40\"><input value=\"Enter Pass\" type=\"submit\"></form>"; exit; } ?> Let's assume $password is 'password'. Why can't I simply pass the information through the URL to access the page with something like this: http://mypage.com/the-same-page.php?pass=password
-
ARe there any PHP Keyword Suggestion Scripts out there?
soma56 replied to soma56's topic in Miscellaneous
For anyone curious on whether or not I solved this issue: I decided to explore the Google Adwords API. You have to jump through a few hoops to set up an account and an API token, however, the keyword tool that google offers simply can't be compared to any other (IMO). You can use PHP to connect to the API (which is where I'm at 'at' this point). -
Using cURL to get links on a page (not found in soure code)
soma56 replied to soma56's topic in PHP Coding Help
Thanks man. My head is spinning. I believe it's hard coded in Javascript. I'm going to try a few things and I'll post my 'success code', if I figure it out, here. In the mean time more suggestions are welcome. -
Using cURL to get links on a page (not found in soure code)
soma56 posted a topic in PHP Coding Help
Well this is a tricky one for me. The script I've created is able to upload images to a server. The server, which I have no control over, generates a random name. It uses Javascript and flash. As a result the links to these images are not within the source code. I suppose the question is, is there a way to still grab these links? I'm familiar with cURL and I was thinking about using something like (CURLOPT_FOLLOWLOCATION) but I'm wondering if that would just look at the source code for links as well? Has anyone had this problem before? -
After a few months of bumping into the same pages within Google's Adwords API I've given up trying to figure out how to use their keyword tool on my website. I simply can't figure out how to get a token as a means of using their Keyword Suggestion tool. Support is terrible and I'd have better chances smuggling diamonds throughout 30 major airports. I've also searched the web. While there seems to be plenty of scripts and ways to create keyword clouds based on existing text there isn't anything that offers 'suggestions'. I've created a script that is able to use the actual 'Google Suggests' function. When you type - it auto-types possibilities - but these results are too similar for my purposes. I've also created a meta tag scrape which, can be useful, but it's format-dependent. And if some websites don't have comma's between there keywords and/or decide to you semi-colons (for whatever reason) then things go funny. The results are also so-so. All that being said: In the world of PHP is there a script (or way) to generate 'NEW' keyword suggestions based on one keyword/keyword phrase?
-
Comparing values within two different arrays and pulling my teeth out
soma56 replied to soma56's topic in PHP Coding Help
Brilliant. Thank you akitchin! I was using the trim() function in the foreach statement previous to your post - everyone looked the same - the only logical conclusion was white space. As a result of reading your last post it occurred to me that maybe I should trim both of the values prior to placing them into an array. I decided to trim both the first and last name as I was receiving while the script was receiving the data from the CSV file. <?PHP $first_name = trim($data[2]); $last_name = trim($data[3]); $name = $first_name." ".$last_name; $first_array[] = $name; ?> Voila! The I can relax again... Thanks again, and for everyone's insight. -
Comparing values within two different arrays and pulling my teeth out
soma56 replied to soma56's topic in PHP Coding Help
I see one messed up looking array.... array(52) { [0]=> string(4) "TEST" [1]=> string(14) "Nick Boynton " [2]=> string(16) "Jason Garrison " [3]=> string(15) "Bruno Gervais " [4]=> string(17) "Barrett Jackman " [5]=> string(15) "Chris Pronger " [6]=> string(15) "Anton Babchuk " [7]=> string(13) "Johny Oduya " [8]=> string(15) "Kyle Brodziak " [9]=> string(13) "Ville Leino " [10]=> string(17) "Mike Santorelli " [11]=> string(14) "Ryan Shannon " [12]=> string(14) "Raffi Torres " [13]=> string(13) "Kyle Turris " [14]=> string(11) "Joel Ward " [15]=> string(15) "Casey Wellman " [16]=> string(18) "Erik Christensen " [17]=> string(15) "Patrick Sharp " [18]=> string(19) "Fabian Brunnstrom " [19]=> string(18) "Gregory Campbell " [20]=> string(18) "Sergei Kostitsyn " [21]=> string(14) "Brooks Laich " [22]=> string(14) "Rick Peverly " [23]=> string(14) "Evander Kane " [24]=> string(19) "Goalies-b Chicago " [25]=> string(24) "Goalies-a Ny islanders " [26]=> string(24) "Goalies-a Philadelphia " [27]=> string(13) "Wade Redden " [28]=> string(17) "Viktor Tikhonov " [29]=> string(16) "Johan Fransson " [30]=> string(15) "Cody Goloubef " [31]=> string(17) "Brandon Gormley " [32]=> string(12) "Alex Grant " [33]=> string(13) "Paul Postma " [34]=> string(19) "Kevin Shattenkirk " [35]=> string(14) "Beau Bennett " [36]=> string(19) "Francois Bouchard " [37]=> string(22) "Alexander Burmistrov " [38]=> string(14) "Bobby Butler " [39]=> string(14) "Aaron Gagnon " [40]=> string(16) "Quinton Howden " [41]=> string(16) "Calle Jarnkrok " [42]=> string(16) "Kiril Kabanov " [43]=> string(15) "Louis Leblanc " [44]=> string(15) "Brad Marchand " [45]=> string(14) "Tyler Seguin " [46]=> string(15) "Riley Sheahan " [47]=> string(12) "Ilya Zubov " [48]=> string(23) "Mats Zuccarello-aasen " [49]=> string(14) "T.j. Hensick " [50]=> string(20) "Branko Radivojevic " [51]=> string(13) "Asgsg Uiowern" } The array (first array) was created from two variables (first and last name) coming in from a csv file, however, looking at it now I can see that it's not coming back the way I expected it to. I was simply using 'print_r' to see the data - which looks correct. I suspect the problem lies with how the first array was created in the first place: ///CSV names coming in... $name = $data[2]." ".$data[3]; array_push($first_array, $name); No need to be rude. I'm just entertaining different ways to get what I want. -
Comparing values within two different arrays and pulling my teeth out
soma56 replied to soma56's topic in PHP Coding Help
mjdamato, thanks for the great reply. None of it works. Here's why - although the values 'LOOK' identical they are not. I tried a different approach which made me discover this. Assuming the first array is '$name' and the second is in a table... <?PHP foreach ($name as $v){ $query= "SELECT your_name FROM names WHERE your_name = '$v'"; $result = mysql_query($query); $row = mysql_fetch_row($result); $name = $row[0]; echo $name."<br />"; } ?> This doesn't work - but if change one thing - the $v variable to a name that is ALREADY in the array it does work, like so: <?PHP foreach ($name as $v){ $query= "SELECT your_name FROM names WHERE your_name = 'Charles'"; $result = mysql_query($query); $row = mysql_fetch_row($result); $name = $row[0]; echo $name."<br />"; } ?> My first conclusion was white space. So I added this prior to connecting to the table: $v = trim($v); So it's something to do with the first array that I have. What I'm finding as a total mindf#$@ is that, as with the example above, if I simply paste the first array value (any value) in the query it works. -
This has kept me busy for a couple of hours. I have two arrays that I would like to compare against each other to see matches and otherwise. Simple enough, right? foreach ($array1 as $value){ if (in_array($value, $array2)) { echo $value."-FOUND<br />"; } else { echo $value."-NOT!<br />"; } } Using print_r I can CLEARLY see matches: array1 = Array ( [0] => CHARLES [1] => TOM [2] => DICK [3] => HARRY) array2 = Array ( [0] => HARRY [1] => DICK [2] => TOM [3] => CHARLES) The only difference I can see is the keys - but why should that matter for what I'm trying to do? Both arrays were converted to uppercase. I have done variations of search_array, array_intersect and array_unique - but absolutely nothing is working. 3 hours later and I'm no further then I started off. WTF?
-
How would ANYONE append to every value within an array?
soma56 replied to soma56's topic in PHP Coding Help
I rushed through it - yes it worked. Thanks -
How would ANYONE append to every value within an array?
soma56 replied to soma56's topic in PHP Coding Help
Hey Thorpe, it's nice to see you're still hear helping people like me out. I thought of that but then how would I place all the $v back into the array? I hope that makes sense. The reason is because I have to combine it with another one... <?PHP foreach ($arr as $k => $v) { $arr[$k] = 'go' . $v; } $combine = array_merge((array)$arr, (array)$anotherarray); print_r($combine); ?> -
I can't seem to find an answer on this one. I've figured out how to add key/value pairs, add to the beginning and end - but the question here is how do you append to each value within an array? Let's say I wanted to add the word 'go'. From: Array ( [0] => Bruins [1] => Rangers [2] => Leafs ) To: Array ( [0] => GoBruins [1] => GoRangers [2] => GoLeafs ) Seems simple enough but Google isn't being friendly today.