|
DirtyDaub posted:I need some help. I thought asp was pretty much dying? Either way, if I was a company I wouldn't want to move there as there are a lot more PHP devs out there.
|
# ? Dec 10, 2009 19:38 |
|
|
# ? May 19, 2024 09:44 |
|
Is there a way to upload a picture from a remote url to my server using curl? Basically I had a firefox extension that allowed me to right click on a picture and upload it to my server, but now they turned "allow_url_fopen" off and doesn't work. (Just need to know if there's a way, not the actual way) Thanks.
|
# ? Dec 10, 2009 20:37 |
|
LastCaress posted:Is there a way to upload a picture from a remote url to my server using curl? Basically I had a firefox extension that allowed me to right click on a picture and upload it to my server, but now they turned "allow_url_fopen" off and doesn't work. You mean use CURL to fetch an image? Sure, that's what it's for, to fetch things from the Internet.
|
# ? Dec 10, 2009 20:50 |
|
LastCaress posted:Is there a way to upload a picture from a remote url to my server using curl? Basically I had a firefox extension that allowed me to right click on a picture and upload it to my server, but now they turned "allow_url_fopen" off and doesn't work. Here is a very basic example: Please read the curl documentation php:<? $url = "http://www.domain.com/image.jpg"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); $fileContents = curl_exec($ch); curl_close($ch); $newImg = imagecreatefromstring($fileContents); ?>
|
# ? Dec 10, 2009 23:02 |
|
Thanks, I'm a veterinarian and obviously know nothing about coding, so before I would spend a lot of time trying to figure that out I just wanted to know if it worked
|
# ? Dec 11, 2009 11:31 |
|
LastCaress posted:Thanks, I'm a veterinarian and obviously know nothing about coding, so before I would spend a lot of time trying to figure that out I just wanted to know if it worked It's okay, just make sure to tell us how to fix our animals when we need it.
|
# ? Dec 11, 2009 15:36 |
|
Another complete coding-newbie question here: How do you replace php's copy() with curl? I've got a wordpress script that uses the copy function to download a file to my website, and allow_url_fopen or something is recently been disabled by my host so it doesn't work anymore. This is the relevant piece of code (I think): code:
|
# ? Dec 15, 2009 02:02 |
|
Hey guys, I'm helping my GF write her honours thesis with a simple php scraper of a vBulletin board (not SA). I'm not particularly proficient with php and an just making the very first steps. What I need help with is how to get php to "log in" so it can view content available to members. Is there a way to load cookies into php before using file_get_contents($url)?
|
# ? Dec 15, 2009 02:34 |
|
Amethyst posted:Hey guys, I'm helping my GF write her honours thesis with a simple php scraper of a vBulletin board (not SA). http://php.net/manual/en/function.file-get-contents.php Crazy what they put in the documentation these days. Example 4.
|
# ? Dec 15, 2009 03:15 |
|
Amethyst posted:Hey guys, I'm helping my GF write her honours thesis with a simple php scraper of a vBulletin board (not SA). Use cURL - With cURL you can login and let it manage the cookies for you. I don't have a complete example, but this should give you enough idea and get you started: http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/ Ninja Edit: Is there any reason your using file_get_contents() vs cURL anyway? In 99% of instances I would recommend people use cURL as their first step as it isnt hamstrung by safe mode or url open stuff, and it is far more flexible then other options.
|
# ? Dec 15, 2009 03:26 |
|
Sterf posted:Another complete coding-newbie question here: This link has a decent example of what your trying to do: http://www.weberdev.com/get_example-4009.html
|
# ? Dec 15, 2009 03:34 |
|
Lumpy posted:http://php.net/manual/en/function.file-get-contents.php WildFoxMedia posted:Use cURL - With cURL you can login and let it manage the cookies for you. Thanks for the help, I know it was basic but I just needed a push in the right direction
|
# ? Dec 15, 2009 03:41 |
|
Yarp - No problem Sorry if my last comment seemed abrasive - Among the many things that "irk" me about PHP, things like file_get_contents and copy via remote URL open bother me most since they tend to have issues and are subject to safe mode and other oddball restrictions.
|
# ? Dec 15, 2009 05:03 |
|
haywire posted:I thought asp was pretty much dying? Either way, if I was a company I wouldn't want to move there as there are a lot more PHP devs out there. Probably, I dont really see it anywhere. The only reason I'm using it is cause the old site was built with it and its the only way i know how to use: <!-- include file --> I use this for the header and footer so I dont have to change them out on each page. Theres probably a better way to do this right?
|
# ? Dec 15, 2009 19:57 |
|
DirtyDaub posted:Probably, I dont really see it anywhere. The only reason I'm using it is cause the old site was built with it and its the only way i know how to use: Same thing: <?php include('filename'); ?>
|
# ? Dec 16, 2009 03:52 |
|
Cool, I'll start using that.
|
# ? Dec 16, 2009 14:19 |
|
WildFoxMedia posted:This link has a decent example of what your trying to do: http://www.weberdev.com/get_example-4009.html I tried applying that, but it gives an error. Fatal error: Call to undefined function get_file1() Is it something I did wrong or is something disabled on the server or something? (remember, complete newbie here) This is what I made of it. I probably butchered it, but yeah... code:
|
# ? Dec 16, 2009 19:56 |
|
Did you add the function get_file1 to your code, that was listed on the page?php:<?php function get_file1($file, $local_path, $newfilename) { $err_msg = ''; echo "<br>Attempting message download for $file<br>"; $out = fopen($newfilename, 'wb'); if ($out == FALSE){ print "File not opened<br>"; exit; } $ch = curl_init(); curl_setopt($ch, CURLOPT_FILE, $out); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $file); curl_exec($ch); echo "<br>Error is : ".curl_error ( $ch); curl_close($ch); //fclose($handle); }//end function ?>
|
# ? Dec 16, 2009 20:05 |
|
SuckerPunched posted:Did you add the function get_file1 to your code, that was listed on the page? He just copied and pasted in the interesting bits. Here: php:<? function curl_download($remoteURL, $toFilename){ if(($fh = fopen($toFilename, 'wb')) === false){ echo "Unable to open '$toFilename' in write mode!"; return false; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remoteURL); curl_setopt($ch, CURLOPT_FILE, $fh); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); if(curl_errno($ch)){ echo "Error downloading '$remoteURL': ", curl_error($ch); return false; } curl_close($ch) return true; } $filename = WP_PLUGIN_DIR."/mochi/mochigames/".$game[blog_id].".swf"; $filefolder_local = WP_PLUGIN_DIR."/mochi/mochigames/"; $filename_local = $game[blog_id].".swf"; //no idea where remoteURL is coming from (assuming filename is the local path)! if(curl_download($remoteURL, $filename)){//you get to figure that out $query = "update ".$wpdb->prefix."mochi set blog_url = \"$filename\" where id = $game[id]"; $wpdb->query($query); } ?> Munkeymon fucked around with this message at 20:44 on Dec 16, 2009 |
# ? Dec 16, 2009 20:38 |
|
SuckerPunched posted:Did you add the function get_file1 to your code, that was listed on the page? Oops, apparantly I didn't. And what I failed to mention is that the code I showed is already in one of those 'function' brackets. I'm guessing by the error it gives me you can't put one of those inside another? Here's the complete code thingie excerpt btw. The code I showed previously was just the one in the 'else': php:<? php function mochi_toggle_games($id){ global $wpdb; $id = intval($id); $query = "select id,swf_url,blog_url,blog_id from ".$wpdb->prefix."mochi where id = $id"; $game = $wpdb->get_row($query,ARRAY_A); if($game[blog_url]){ $unlink = unlink($game[blog_url]); if($unlink){ $query = "update ".$wpdb->prefix."mochi set blog_url = \"\" where id = $game[id]"; $wpdb->query($query); } } else{ $filename = WP_PLUGIN_DIR."/mochi/mochigames/".$game[blog_id].".swf"; $copy = copy($game[swf_url],$filename); if($copy){ $query = "update ".$wpdb->prefix."mochi set blog_url = \"$filename\" where id = $game[id]"; $wpdb->query($query); } } }?> Sorry for probably being an idiot, but this is all chinese for me (I'm not chinese). It's all a bit above my head, so I'll probably just have to give up for now and first try and learn basic php. Thanks for helping, though. edit: quote:He just copied and pasted in the interesting bits. I shall now flee in shame. Sterf fucked around with this message at 20:50 on Dec 16, 2009 |
# ? Dec 16, 2009 20:44 |
|
I have a class with a bunch of methods, and comments in front of each method. Is there a way to grab all those comments in a array or something so I can echo them in an API page? <edit> Just had a friend tell me, use ReflectionClass which is working great. nevermind. hallik fucked around with this message at 04:38 on Dec 17, 2009 |
# ? Dec 17, 2009 04:17 |
|
How would I go about making sure something happens 75% or n% of the time? If that didn't make sense, how can I make a random event happen n% of the time whenever a page is loaded. I tried this but this doesn't seem right. php:<? $r = rand(1,100); if($r <= 75) echo "hit"; else echo "miss";?>
|
# ? Dec 17, 2009 05:26 |
|
hallik posted:I have a class with a bunch of methods, and comments in front of each method. Is there a way to grab all those comments in a array or something so I can echo them in an API page? Are you writing actual PHPdoc? If not, it's easy to do and you should start doing it.
|
# ? Dec 17, 2009 06:16 |
|
drcru posted:How would I go about making sure something happens 75% or n% of the time? Did you initialize the random number generator at some point? [EDIT] looks like you don't need to do this since 4.2, but I dunno what version you are on.... php:<? srand( time() ); $num = rand(1,100); printf("I generated %d", $num); if( $num <= 75 ) { // yippie! }else { // boo } ?> Lumpy fucked around with this message at 07:51 on Dec 17, 2009 |
# ? Dec 17, 2009 07:48 |
|
drcru posted:How would I go about making sure something happens 75% or n% of the time? What do you mean by "doesn't seem right"? It looks like it should work. You could check whether it really is generating numbers like you want by temporarily changing it to the following php:<? $hits = 0; $misses = 0; for ($i=0;$i<10000;$i++) { $r = rand(1,100); if ($r <= 75) { $hits++; } else { $misses++; } } echo $hits.' hits and '.$misses.' misses.'; ?>
|
# ? Dec 17, 2009 17:32 |
|
rt4 posted:Are you writing actual PHPdoc? If not, it's easy to do and you should start doing it. I am trying to make it easy for a non php person at work to know what classes/methods are available to him, and how to call them from his application. I will google PHPDoc and see what it's all about.
|
# ? Dec 17, 2009 20:02 |
|
hallik posted:I am trying to make it easy for a non php person at work to know what classes/methods are available to him, and how to call them from his application. I will google PHPDoc and see what it's all about. PHPDoc is perfect for that - not only is it useful when reading the source itself, but it generates an HTML (or whatever else) "help file" that sort of documents your code as per what it can find itself and what you've written.
|
# ? Dec 18, 2009 08:55 |
|
It's been a long time since I last wrote session scripts and user authorization, so I want to check what I'm doing isn't pointless. I've used the PHP Security Consortium example of sessions to write a three-tiered validation (session active > session user agent (hashed) > url user agent (hashed)). If I set a boolean to true if the validation passes, can I stick an if outside of the session code to call user functions? I.e. if($uservalid == true) { echo userInput(); } Does that destroy the point of checking the session in the first place? My second question (if the answer to the first is positive), can I abstract the session validation to a separate file and just call it like I would any other function? php:<?php session_start(); validate_session(); ?>
|
# ? Dec 19, 2009 19:23 |
|
Surely if your session is invalid you should most likely kill the script and tell the client to gently caress off, whilst deleting the session? Or just do the latter.
|
# ? Dec 19, 2009 21:25 |
|
I was thinking of having update forms on certain pages which were only visible to users that are logged in. That way they all existing content is visible. If the session is invalid, the page will still load, but without the form. Is this bad practice?
|
# ? Dec 19, 2009 21:38 |
|
haywire posted:Surely if your session is invalid you should most likely kill the script and tell the client to gently caress off, whilst deleting the session? Or just do the latter. Just re-initialize the session and redirect to the homepage.
|
# ? Dec 20, 2009 07:36 |
|
MrMoo posted:Just re-initialize the session and redirect to the homepage. Essentially ending the script.
|
# ? Dec 21, 2009 02:30 |
|
gwar3k1 posted:I was thinking of having update forms on certain pages which were only visible to users that are logged in. That way they all existing content is visible. If the session is invalid, the page will still load, but without the form. Make sure you also protect the script that processes the form with the same checks. Otherwise, users who had access to the form structure at some point (or just guessed it) would be able to submit forms without logging in.
|
# ? Dec 21, 2009 02:36 |
|
Is there some sort of way to send multiple mail() queries at once? I set up an "Email All Users" thing for my site, and it takes 2 seconds a mail(), and there are 1500 users. You can see how this is a problem. What can I do to speed the process up?
|
# ? Dec 21, 2009 08:52 |
|
Mr Viper posted:Is there some sort of way to send multiple mail() queries at once? I set up an "Email All Users" thing for my site, and it takes 2 seconds a mail(), and there are 1500 users. You can see how this is a problem. What can I do to speed the process up? Are the mail subjects/bodies identical? mail() accepts virtually any number of receivers per call (Example 4, delimit with commas). If each mail has to be tailored to its recipient, you probably have to send them one at a time. The documentation also points to PEAR for bulk sending: http://pear.php.net/package/Mail and http://pear.php.net/package/Mail_Queue.
|
# ? Dec 21, 2009 09:15 |
|
Supervillin posted:Are the mail subjects/bodies identical? mail() accepts virtually any number of receivers per call (Example 4, delimit with commas). If each mail has to be tailored to its recipient, you probably have to send them one at a time. I gave the multiple "to"s method a shot, and it seems to still take the standard 2 seconds per email... And I don't feel like dealing with PEAR.
|
# ? Dec 21, 2009 09:37 |
|
Mr Viper posted:it takes 2 seconds a mail() Sounds like you are not queuing mail in the MTA, or the MTA is remote to the script host. You need to configure a local MTA to spool out for later delivery.
|
# ? Dec 21, 2009 10:54 |
|
CoderCat posted:Make sure you also protect the script that processes the form with the same checks. Otherwise, users who had access to the form structure at some point (or just guessed it) would be able to submit forms without logging in. Surely this is security by obscurity? The user could make anything they like with an HTTP request, it is up to your script to ignore the submitted form if there's no way to authenticate it. So, in theory, you could give them every piece of information about the drat form, but no matter how they submit it, unless they are logged in it wont work.
|
# ? Dec 21, 2009 22:03 |
|
haywire posted:Surely this is security by obscurity? The user could make anything they like with an HTTP request, it is up to your script to ignore the submitted form if there's no way to authenticate it. So, in theory, you could give them every piece of information about the drat form, but no matter how they submit it, unless they are logged in it wont work. Exactly, this is what I'm trying to say. The script that processes the form should also be protected. I've seen many pieces of code in which the form is protected but the processing code has no protection.
|
# ? Dec 21, 2009 22:32 |
|
|
# ? May 19, 2024 09:44 |
|
So I should be encapsulating my "action" scripts with the session authorization and not just setting a variable that says the user is logged in and the session is valid? That makes sense. So this... code:
code:
|
# ? Dec 21, 2009 22:45 |