[PHP] moving file from one server to another
hi, i have thttpd (a very light weight http server) running as an image server on one box, and users uploading images to another php/apache powered box. I need to let users upload to the regular LAMP box, but then copy the image over to the custom image server (which does not have php or any kind of cgi capability). I was considering using exec() and scp to do this, but thought i'd ask and see if anyone had any better suggestions? many thanks -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] moving file from one server to another
* and then Google Kreme declared On 30 Sep 2006, at 03:29 , Nick Wilson wrote: I need to let users upload to the regular LAMP box, but then copy the image over to the custom image server (which does not have php or any kind of cgi capability). I was considering using exec() and scp to do this, but thought i'd ask and see if anyone had any better suggestions? Ah... well, does the copy need to be interactive, or does it need to be automatic? I'd probably use rsync to copy the upload tree to the image server myself, without involving php at all. yes. i'd considered rsync but the file needs to be available on the image server immediately. scp'ing it should work, but of course imnow having fun with the apache user and try9ing to work out how to give it an ssh profile :) -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] exec returns no output?
hi all, i've searched and racked my brains, checked config files and all sorts but cannot work out why the following command would give me an empty array (and certainly not actually perform the requested command...) exec('scp -v -i /id_dsa file.txt [EMAIL PROTECTED]:/target/dir/', $argh); print_r($argh); I can only surmise there is some setting todo with ssh/scp that im unaware of? any ideas welcomed, thanks! -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] moving file from one server to another
* and then Tony Di Croce declared How about nfs mounting a directory from the image server to a directory on the lamp server. This way, the files are never really on the LAMP server... yeh, that had ocurred to me, and may be a good solution Tony. The only thing that worried me was not knowing (ie having to research..) whether that would cause any significant overhead on the image server. It's not like it's an under spec'd machine, but the point of course is to have as small a server load as possible -- so we dont need to start dropping aditioonal boxes in too soon. I run nfs at home and we make good use of it on the local network where the actual application is for shared files under the laod balancer, but this would be another data center entirely. It may be that it's a trivial thing, the reason ive not done it is Im just not 100% sure on it is all, whereas simply scp/sftp'ing files into the image server dir is about as simple as it gets right? -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] exec returns no output?
* and then Ray Hauge declared On Saturday 30 September 2006 7:22 am, Nick Wilson wrote: hi all, i've searched and racked my brains, checked config files and all sorts but cannot work out why the following command would give me an empty array (and certainly not actually perform the requested command...) exec('scp -v -i /id_dsa file.txt [EMAIL PROTECTED]:/target/dir/', $argh); print_r($argh); I can only surmise there is some setting todo with ssh/scp that im unaware of? any ideas welcomed, thanks! -- Nick Wilson http://performancing.com/user/1 Do you use generated keys without a password for logging in? Otherwise exec() is just going to sit there while the scp command waits for a password. Tha'ts exactly what i think it's doing. The -i specifies an identity file according to the man page for scp so i would have hoped that would take care of it (as i cant work out how to generate an identity for the apache user itself) but i guess it is doing exactly as you say.. -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: exec returns no output?
* and then Colin Guthrie declared Nick Wilson wrote: Do you use generated keys without a password for logging in? Otherwise exec() is just going to sit there while the scp command waits for a password. Tha'ts exactly what i think it's doing. The -i specifies an identity file according to the man page for scp so i would have hoped that would take care of it (as i cant work out how to generate an identity for the apache user itself) but i guess it is doing exactly as you say.. Nick I think you are misunderstanding what Ray is asking. scp (without the -i keyfile arg) will ask you for your SSH password. BUT, the keyfile itself can be generated to have a password also! Right, im with you. The keyfile is mine though, and i know i can ssh from this box to that without any problem. I've made a test script for htis and it's returning some very weird stuff now. The actual file it outputs (stdout and stderr) is the actual image im trying to send! ?php $file = '/stat/data/drupal/image.png'; exec(/usr/bin/scp -v -i /home/troot/.ssh/id_dsa $file [EMAIL PROTECTED]:/var/www/images/ 12 /var/www/html/test/out, $ack); print_r($ack); ? -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: exec returns no output?
* and then Colin Guthrie declared Nick Wilson wrote: Right, im with you. The keyfile is mine though, and i know i can ssh from this box to that without any problem. I've made a test script for htis and it's returning some very weird stuff now. The actual file it outputs (stdout and stderr) is the actual image im trying to send! ?php $file = '/stat/data/drupal/image.png'; exec(/usr/bin/scp -v -i /home/troot/.ssh/id_dsa $file [EMAIL PROTECTED]:/var/www/images/ 12 /var/www/html/test/out, $ack); print_r($ack); ? Could it be a permissions problem? your ~/.ssh folder should has to be nailed now permissions wise otherwise SSH will complain. Also the id_dsa file is usually only readable by the user and nothing else (e.g. mode 0600) I'd suggest you check permissions. Also I'd add a new key for this rather than user your own. If the apache process can read your private key this is quite a security risk I think you're on the right track Col. I did a whole bunch more searching and the one thing I kept hearing was that no matter what you try, you just cant get the webserver to exec the script as another user -- so even if im saying '[EMAIL PROTECTED]' in both parts of the scp command, it's still being exec'd as apache, and apache has no home, and no .ssh dir. i've tried putting the perms on that dsa file directly as the apache user and even putting it eleshwere in teh filesystem but nothing seems to work As i dont have the ssh2 ext on this setup, and have no desire to go messin with new extensions it looks like im going to have to go gthe nfs route on this problem unless anyone has done this before and knows an answer? thanks for the help! -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: exec returns no output?
* and then Colin Guthrie declared Nick Wilson wrote: I think you're on the right track Col. I did a whole bunch more searching and the one thing I kept hearing was that no matter what you try, you just cant get the webserver to exec the script as another user -- so even if im saying '[EMAIL PROTECTED]' in both parts of the scp command, it's still being exec'd as apache, and apache has no home, and no .ssh dir. The program on the webserver will always be executed as the user that runs the webserver. The nick@ bit is purely the syntax used by the program in question, in this case scp. I'm sure it will be possible to get the apache user to run SCP, even if the user does not have a home directory specified. i've tried putting the perms on that dsa file directly as the apache user and even putting it eleshwere in teh filesystem but nothing seems to work As i dont have the ssh2 ext on this setup, and have no desire to go messin with new extensions it looks like im going to have to go gthe nfs route on this problem unless anyone has done this before and knows an answer? Assuming you have root on the box in question, you could write a shell script that does what you need then run it from apache via the sudo command. Provided you configure /etc/sudoers to allow the apache user to run your script without a password, it should work. As it's only allowed to run that one script, it is also fairly secure. E.g. /usr/bin/transfer_image.sh: #!/bin/bash if [ -z $1 ]; then echo No input file. exit 1 fi scp $1 [EMAIL PROTECTED]:/var/www/images/ And then in apache: exec(sudo -u nick /usr/bin/transfer_image.sh $file); (obviously escape $file with the escape_shell_cmd() func.) /etc/sudoers should contain something like: apache ALL = (/usr/bin/transfer_image.sh) NOPASSWD: ALL That makes a lot of sense. I wasnt aware sudoers could be used for individual tasks. im not having much luck with it, I suspect it's cos what apache really needs permission to do is to 'sudo -u nick' right? -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: exec returns no output?
* and then Colin Guthrie declared /usr/bin/transfer_image.sh: #!/bin/bash if [ -z $1 ]; then echo No input file. exit 1 fi scp $1 [EMAIL PROTECTED]:/var/www/images/ And then in apache: exec(sudo -u nick /usr/bin/transfer_image.sh $file); (obviously escape $file with the escape_shell_cmd() func.) /etc/sudoers should contain something like: apache ALL = (/usr/bin/transfer_image.sh) NOPASSWD: ALL Success! After lots of messing around with visudo, i got this line working right: apache ALL=(user2runAs) NOPASSWD: /usr/bin/scp-image.sh Thanks for the help Col, seems it all turned out good -- shame to spend the whole damn day on something so small though heh.. -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: exec returns no output?
* and then Stut declared Nick Wilson wrote: That makes a lot of sense. I wasnt aware sudoers could be used for individual tasks. im not having much luck with it, I suspect it's cos what apache really needs permission to do is to 'sudo -u nick' right? Is it important that the transfer happens immediately? If not then a better solution is to drop the images in a folder that is then transferred by a script cron'd by the user that has everything required to do the scp. To be frank, anything is better than giving the user that Apache runs as any more permissions than you have to. yes, im afraid it does need to be immediate. I've fixed it now though with the sudoers help above in the thread. thanks -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] When is a global not a global?
* and then Robert Cummings declared On Wed, 2006-07-12 at 18:52, Nick Wilson wrote: hi all, After upgrading a CMS, im having a problem with global variables not showing up anymore -- configs and things could have changed, but search as i have, i cannot find anything to help me work out what the problem is. This should work of course: $foo = 'bar'; function foobar() { global $foo; print( -- . $foo); exit; } foobar(); It prints *nothing*. Does anyone have an idea as to what might stop this from functioning as expected? The above code is probably being included, and probably being included by a function and so $foo does not have global scope. To ensure global scope: ?php $GLOBALS['foo'] = 'bar'; function foobar() { global $foo; print( -- . $foo ); exit; } foobar(); ? Try that and let us know what happend. No, it didn't work. It's odd, becuase it worked just fine in the previous version, and this is a module, so that module is exactly the same as the previous one -- ie i've not made any changes to do with includes to it (just a few upgrades to form functions and stuff). I have fixed the issue, but the mystery will probably have to remain as there is a lot more to do in the upgrade :( In the end i just manually set $GLOBALS as you suggested and did a search and replace on the var to do $GLOBALS[var] instead of global var; do_stuff($var); crap i know, but thanks for the response! -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] When is a global not a global?
hi all, After upgrading a CMS, im having a problem with global variables not showing up anymore -- configs and things could have changed, but search as i have, i cannot find anything to help me work out what the problem is. This should work of course: $foo = 'bar'; function foobar() { global $foo; print( -- . $foo); exit; } foobar(); It prints *nothing*. Does anyone have an idea as to what might stop this from functioning as expected? -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mhash() without mhash library?
hi all, can anyone tell me if it might be possible to do an mhash() without actually having the mhash library installed? for various reasons it's very impracticle to have a compiled version of php running on our production servers and i'd really like to be able to use the alexa web services. here's the php snippet that wont work, just so you know what the aim is.. function make_sig ( $secret_access_key, $service, $operation, $timestamp) { $sig = $service . $operation . $timestamp; $hmac = mhash ( MHASH_SHA1, $sig, $secret_access_key ); $encoded_hmac = base64_encode ( $hmac ); return urlencode ( $encoded_hmac ); } any thoughts? -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mhash() without mhash library?
* and then Jochem Maas declared Nick Wilson wrote: hi all, can anyone tell me if it might be possible to do an mhash() without actually having the mhash library installed? for various reasons it's very impracticle to have a compiled version of php running on our production servers and i'd really like to be able to use the alexa web services. here's the php snippet that wont work, just so you know what the aim is.. function make_sig ( $secret_access_key, $service, $operation, $timestamp) { $sig = $service . $operation . $timestamp; $hmac = mhash ( MHASH_SHA1, $sig, $secret_access_key ); $encoded_hmac = base64_encode ( $hmac ); return urlencode ( $encoded_hmac ); } any thoughts? read this page: http://php.net/sha1 (and search for 'hmac') no idea if the solution offered there actually works but hope it does the trick. Wonderful, thanks. I'd seen the page, but neglected to look through the comments. Im sure i can work it out from there. thanks again. -- Nick Wilson http://performancing.com/user/1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security Concerns with Uploaded Images:
* and then chris smith declared Check the file extension and the mimetype, make sure they are both valid.. or as someone else suggested, use getimagesize on it - if that returns false or empty then it's not an image. Ok thanks guys. I'll do extension and mime and getimagesize() before saving/using them. Much thanks! -- Nick Wilson Tel:+45 3311 2250 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Security Concerns with Uploaded Images:
Hi all, are there any security concerns with uploaded images? My thought is that it wouldnt be too hard to have some kind of script masquerade as a gif file, and perhaps cause damage. I cant find anyway to check a file really is a gif/png/jpg (i assume the mimetype available in $_FILES could be spoofed). I'd welcome any thoughts in general on this, but specifically if anyone has experience/knowledge in this area and can point me in the right direction. Many thanks! -- Nick Wilson Tel:+45 3311 2250 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Cannot suppress fsockopen errors
Hi, Im having a hard time surpressing fsckopen() errors. I've looked at the manual and searched around, but what i am doing /appears/ to be correct, yet im still geting warnings... here's the code: // open a socket to the server if($handle = @fsockopen($bits['host'], 80, $errno, $errstr, 10) or die(die)) { return true; } and here are the warnings: warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/localhost/vhosts/payment.communicontent.com/modules/partners/inc/includes/validateBlog.inc on line 53. warning: fsockopen(): unable to connect to www.ivana.dk:80 in /var/www/localhost/vhosts/payment.communicontent.com/modules/partners/inc/includes/validateBlog.inc on line 53. I've even tried looking though php.ini for any clues and i dont see anything useful. Does anyone have an idea of what im missing here? Many thanks! -- Nick Wilson Tel:+45 3311 2250 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Includes and paths confusion
Hello all, Im having some problems understanding why some requires() are failing. Let me see if i can describe what's going on clearly... I have this: [EMAIL PROTECTED] ls ads/ config.inc db.inc funcs.inc init.inc where ads/ is a whole huge set of scripts from an existing setup. ads/ was originally placed on its own domain as it's a version of phpadsnew and runs as a server all by itself. I moved ads/ to this directory to try to troubleshoot and make things clearer. db.inc has these lines: require_once(ads/admin/config.php); require_once(lib-statistics.inc.php); require_once(lib-zones.inc.php); require_once(config.inc.php); require_once(lib-db.inc.php); require_once(lib-dbconfig.inc.php); warning: main(../config.inc.php): failed to open stream: No such file or directory in /var/www/localhost/vhosts/payment.communicontent.com/modules/partners/inc/ads/admin/config.php on line 33. Fatal error: main(): Failed opening required '../config.inc.php' (include_path='.:/usr/lib/php') in /var/www/localhost/vhosts/payment.communicontent.com/modules/partners/inc/ads/admin/config.php on line 33 So, why does this not happen when ads/ is on its own domain? I can see it has something to do with relative paths, but even when i try to work with chdir() i still get no joy. I just can't figure out what the issue may be, so any pointers in the right direction would be hugely appreciated. thankyou! -- Nick Wilson Tel:+45 3311 2250 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Includes and paths confusion
* and then Jochem Maas declared Nick Wilson wrote: Hello all, Im having some problems understanding why some requires() are failing. Let me see if i can describe what's going on clearly... I have this: [EMAIL PROTECTED] ls ads/ config.inc db.inc funcs.inc init.inc where ads/ is a whole huge set of scripts from an existing setup. ads/ was originally placed on its own domain as it's a version of phpadsnew and runs as a server all by itself. I moved ads/ to this directory to try to troubleshoot and make things clearer. db.inc has these lines: use something *like* the following: $oldincpath = ini_get('include_path'); ini_set('include_path', 'path/to/ads/stuff:etc'); // do your 'ads' requires ini_set('include_path', $oldincpath); Unfortunately that's pretty much the same thing we tried first on this. Even with the include path set to include every directory that contains a script we need to access, the same error happens. also look into the magic constant __FILE__ and the functions dirname() and realpath(). read the manual regard how to use 'include_path' No, the ideal is to not touch the config.php file or any of the other required files (otherwise we may just aswell write our own) so those functions and the __FILE__ constant are not usable. Unless i miss your point? thanks -- Nick Wilson Tel:+45 3311 2250 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Includes and paths confusion
* and then Jochem Maas declared check directory permission, check the include_path is being set, check the include path is actually correct (I take it you have a good understanding how include_path works). Good call on dir perms, but yes, they appear to be fine. I *think* i have a good understanding of include_path but here's the error which quotes the include path so you/others can tell me for sure: Fatal error: main(): Failed opening required '../config.inc.php' (include_path='/var/www/localhost/vhosts/ads.communicontent.com/:/var/www/localhost/vhosts/ads.communicontent.com/admin:/var/www/localhost/vhosts/ads.communicontent.com/libraries:/var/www/localhost/vhosts/ads.communicontent.com/libraries/resources') in /var/www/localhost/vhosts/ads.communicontent.com/admin/config.php on line 34 and here's the line that sets it: ini_set('include_path', PARTNERS_MAX_PATH.':'.PARTNERS_MAX_PATH.'admin'.':'.PARTNERS_MAX_PATH.'libraries'.':'.PARTNERS_MAX_PATH.'libraries/resources'); and the definition of the constant in there: // where max is installed (include / ) define(PARTNERS_MAX_PATH,/var/www/localhost/vhosts/ads.communicontent.com/); also look into the magic constant __FILE__ and the functions dirname() and realpath(). read the manual regard how to use 'include_path' No, the ideal is to not touch the config.php file or any of the other I would say fix the config file so that it can figure out where everything is regardless of whether your using a vhost or stuck in subdir of some other vhost. but thats just me :-) Ordinarily i'd agree. We want to be able to update this set of third party maintained scripts easily though, hence writing a layer to interact with it rather than hack the core code. Hope that all makes sense! thanks -- Nick Wilson Tel:+45 3311 2250 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions and subdomains issues
Goodmorning all, My application (a third party customized cms) shares sessions across the main site and the two subdomains - or at least it should I have 'php_value session.cookie_domain .mysite.com and'php_value session.cookie_path / all set in htaccess The sesions are stored in a db and are not functioning correctly across the subdomains - example: if i log in at the main www domain then go the subdom1.mysite.com i am not logged in there. The subdomains have their own db's but share tables for sessions and some other stuff with the main site. As it's a third party app i can be no more specific unless someone would be kind enough to tell me what to look for or what info to provide. So, here is my question: * Are there any common pitfalls you can think of that i should look at? * Have I set the domain and path correctly for this to work? any help in regard to what direction to take to track down the problem would be really appreciated, much thanks for you time... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Atom 2 RSS Script? Anyone got one?
hi all, im all tired out of searching, just cant seem to find a script that will convert atom 0.3 to any rss format. Does anyone have one or know where i can get hold of one? I know about 2rss.com but they insert ads as i understand it so that just wont do :) thanks for any links or help.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Matching *exact* string?
hello all I am foreach()ing through an array of ip addresses in a 'ban script' and have the following php code: foreach($ips as $ip) { preg_match(/$ip/, $_SERVER[REMOTE_ADDR]); $ban = TRUE; } This is great, but if 127.0.0 were in the ban list (for example) it would still produce a ban as it partially matches. How can I alter the above so that only *exact* matches are banned? Much thanks! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Matching *exact* string?
* and then Aidan Lister declared I cannot fathom why you would use preg_match for this. This will get an exact match... if ($ip == $_SERVER[REMOTE_ADDR]) { $ban = true; } Ahh.. an oversight. The script has been cobbled together from a previous version that supported partial matches. I'd just missed the obvious, thankyou ;-) Despite this being the worst idea I've ever seen, combined with a true lack of understanding, I wish you well. There is no need to be insulting. I doubt very much anyone thinks your a clever guy for acting like a twat on a mailing list. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Matching *exact* string?
* and then Per Jessen declared foreach($ips as $ip) { preg_match(/^$ip$/, $_SERVER[REMOTE_ADDR]); $ban = TRUE; } Great! - found a more sutable way but that's appreciated. Cheers! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Matching *exact* string?
* and then Daniel Schierbeck declared I'd rather go with something like this: $banned_ips = array('123.123.123.123', '321.321.321.321'); // Banned IPs if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) { die('Dude, you\'re banned!'); } But if I were you I'd choose something more advanced. I think in_array() sounds like a great solution, wonder if it's faster than comparing each ooe with == ? thanks! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Matching *exact* string?
* and then Greg Donald declared On Sun, 31 Oct 2004 12:58:04 +0100, Nick Wilson [EMAIL PROTECTED] wrote: I think in_array() sounds like a great solution, wonder if it's faster than comparing each ooe with == ? thanks! Benchmark it both ways and find out. Then post back and tell us. :) Started to, but found I cant ;( I need to get the key from the array also (for use in a corresponding array) and with in_array() I couldnt find a way to do it. So, im just using == which is lightning fast anyway so no worries :) thanks again.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] About File Paths [unresolved]
* and then Matthew Sims declared If a script is to be called with cron *outside* of the http directory, how should file system paths be handled? Should I use fopen('a_path/relative_to/thescript.php'); or fopen('/usr/var/www/absolute_file_path/thescript.php'); Im not only using this for fopen. So does php work relative to the script being called or not? Much thanks... -- Nick W When in doubt, use absolute. Fair enough, thanks Matthew.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] About File Paths
Hi all, If a script is to be called with cron *outside* of the http directory, how should file system paths be handled? Should I use fopen('a_path/relative_to/thescript.php'); or fopen('/usr/var/www/absolute_file_path/thescript.php'); Im not only using this for fopen. So does php work relative to the script being called or not? Much thanks... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] About File Paths
* and then Greg Donald declared On Thu, 28 Oct 2004 18:27:34 +0200, Nick Wilson [EMAIL PROTECTED] wrote: If a script is to be called with cron *outside* of the http directory, how should file system paths be handled? I always assume cron is dumb and provide it with full paths. Absolutely, but I dont mean cron, i mean the php code in the script. When referencing (including/requireing/fopen/etc) files.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] About File Paths [unresolved]
* and then Nick Wilson declared ***bumpety bump*** ;-) If a script is to be called with cron *outside* of the http directory, how should file system paths be handled? Should I use fopen('a_path/relative_to/thescript.php'); or fopen('/usr/var/www/absolute_file_path/thescript.php'); Im not only using this for fopen. So does php work relative to the script being called or not? Much thanks... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Protecting Commercial PHP Scripts
Hello all, I was wondering if anyone might have suggestions or useful links on protecting commercial php scripts. I am about to design a system that would be pretty valuable in a very niche market and would not wish the script to be passed on to others once downloaded. Suggestions, discussion and links would be much appreciated ;-) -- Nick W http://www.threadwatch.org less noise, more signal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Protecting Commercial PHP Scripts
* and then Francisco M. Marzoa Alonso declared I was wondering if anyone might have suggestions or useful links on protecting commercial php scripts. I am about to design a system that would be pretty valuable in a very niche market and would not wish the script to be passed on to others once downloaded. There's no way to protect the code from copying. The only way to do that is not to give no one the code, provide the service based on the code instead of the code itself. Dont waste your time looking for a solution for a lost battle. It's just an advice, of course. I've had about 5 off list (why so many today?) telling me about zend encoder so that would seem not to be true. Thankyou all, i will check out the links, and especially the zend encoder page ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best Functions for Checking Remote File last modified?
Hello, I need to connect to a remote http server and pick up a file *only* if it has been modified since i last did this. The file is in csv format (not tht i think that matters?) and is http password protected. Which functions should I look at for acheiving this please? Thanks very much! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] urlencode() and newlines?
hello all, For reasons beyond my immediate control i have to keep some strings of text in a text *new line delimited* text file. I also have to urlencode those strings for use in my script. Like this: ## text file This is a line\nThis is another line This is another string\nwith some more\nnew lines Problem is, that urlencoding those lines doesnt seem to work well the the \n's - when they get to where they are going (another server, not in my control) the new lines are no longer there... Can anyone tell me how to get round this issue without storing the strings in another way? - many thanks! ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urlencode() and newlines?
* and then Marek Kilimajer declared Nick Wilson wrote: hello all, For reasons beyond my immediate control i have to keep some strings of text in a text *new line delimited* text file. I also have to urlencode those strings for use in my script. Like this: ## text file This is a line\nThis is another line This is another string\nwith some more\nnew lines Problem is, that urlencoding those lines doesnt seem to work well the the \n's - when they get to where they are going (another server, not in my control) the new lines are no longer there... Can anyone tell me how to get round this issue without storing the strings in another way? - many thanks! ;-) Because what you are doing is not urlencoding. Try echo urlencode(This is a line\nThis is another line); Yep, i can see that it's encoded but when the data is POSTed to a form, it does not come out as a newline... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urlencode() and newlines?
* and then Marek Kilimajer declared echo urlencode(This is a line\nThis is another line); Yep, i can see that it's encoded but when the data is POSTed to a form, it does not come out as a newline... Are you sure the other side accepts, does not remove newlines? Create a form with textarea that posts to the server yeah, i guess i'll have to, thanks Marek.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Encoding Question [NOT RESOVED]
* and then Nick Wilson declared that one is using rawurlencode() but it's just as bad with urlencode - How *should* I be doing this? is this how you tried to do it? $userAgent = Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); Yep, but like this: $userAgent = urlencode(Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); just a *bump* if anyone thought the thread was resloved ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Finding one line in a Variable?
Hello all, I have to find and put one line of an html file in a variable. I already have the entire html file stored in a variable like this: $myHTML=htmlheadblah blah blah; - Grabbed using cURL The particular line I want will *always* contain the string the_identifying_string So the line itself (the line i want to get into a var) would look like this: form method=post action=blah.php name=the_identifying_string blah.. How can I get that entire line? many thanks, im sure your all bored of my regex woes heh.. but thanks, it's appreciated.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Finding one line in a Variable?
* and then Minuk Choi declared If you don't mind NOT using regex or regular expression searching commands, you can try it this way. Assuming that there is a carriage break(e.g. \r\n if windows, and I'm assuming the HTML file was written in windows, otherwise, just \n for snip.. thanks so much! - that looks just great, im sure if it's not perfect I can make it work! thankyou again... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Encoding Question for getting pages
Hello, If im using cURL to grab pages, i like to set a $referer and $userAgent string. Easy enough right? If I do not encode the referer and ua strings my cURL functions do not seem to work, BUT, if I *do* encode them, they come out looking like this in the server logs.. Mozilla%2F4.0%20%28compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%0A that one is using rawurlencode() but it's just as bad with urlencode - How *should* I be doing this? thx! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Encoding Question for getting pages
* and then Matt M. declared Mozilla%2F4.0%20%28compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%0A that one is using rawurlencode() but it's just as bad with urlencode - How *should* I be doing this? is this how you tried to do it? $userAgent = Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); Yep, but like this: $userAgent = urlencode(Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] http 411 error with cURL
hi all, Im getting an http 411 error when trying to post data with php's cURL functions. The spec says ***The message for this error code is Length Required. The server refuses to accept the request without a defined Content- Length.*** Im confused on 2 points: * Is it the server i am posting *from* causing the error or is it the server im posting *to*? * How to resolve this? Much thx for any guidance here, this was not happening yesterday doing the same job.. weird! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http 411 error with cURL
* and then Marek Kilimajer declared * How to resolve this? header('Content-Length: ' . strlen($data_you_are_posting)); Ok, im with you Marek but how/where do i put it in my curl function? Not with CURL_POSTFIELDS for sure.. i've been looking through the options in the manual and dont see anything obivious...? thanks mate.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http 411 error with cURL
* and then Nick Wilson declared * and then Marek Kilimajer declared * How to resolve this? header('Content-Length: ' . strlen($data_you_are_posting)); Ok, im with you Marek but how/where do i put it in my curl function? Not with CURL_POSTFIELDS for sure.. i've been looking through the options in the manual and dont see anything obivious...? Opps! CURLOPT_HTTPHEADER I go play with it now ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http 411 error with cURL
* and then Marek Kilimajer declared Opps! CURLOPT_HTTPHEADER I go play with it now ;-) Sorry, I got it mixed :) But you figured it out. do you know if the lenght includes the args? like this strlen(val=$varval2=$var2); or strlen($var . $var2=; ? cheers marek -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http 411 error with cURL
* and then Marek Kilimajer declared Nick Wilson wrote: * and then Marek Kilimajer declared Opps! CURLOPT_HTTPHEADER I go play with it now ;-) Sorry, I got it mixed :) But you figured it out. do you know if the lenght includes the args? like this strlen(val=$varval2=$var2); This one. Don't forget to urlencode where necessary hmmm.. well, this is giving me the same curl_errno(22) http 411 $postF=s=$se=$ea= . urlencode($a) . em= . urlencode($em) .x= . $x . b=$bt= . urlencode($t) . p=$p; $postL=strlen($postF); curl_setopt($ch, CURLOPT_POSTFIELDS,$postF); curl_setopt($ch, CURLOPT_HTTPHEADERS, Content-Length: $postL); $result=curl_exec($ch); -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http 411 error with cURL
* and then Marek Kilimajer declared CURLOPT_HTTPHEADER - An array of HTTP header fields to set. Marek, im sure you dont need to know this, but i think it's funny so maybe you will, i just went to bed, im now sitting here er.. without much on at the PC cos i just realized the same thing! - sorry, im tired thanks so much! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http 411 error with cURL
* and then Nick Wilson declared * and then Marek Kilimajer declared CURLOPT_HTTPHEADER - An array of HTTP header fields to set. ahhh [EMAIL PROTECTED] it! that dont work and niether does this: curl_setopt($ch, CURLOPT_HTTPHEADERS, array(Content-Length: $postL)); im off to bed.. back in the am. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Creating a Sequence from Array
hello all, I have an array like this: array ( 1 = array(123, 345, 454), 2 = array(8854, 393, 4947, 77, 3343), 3 = array(393, 33) ); I need to create an array sequence from that that would look like this: array ( '1:123', '2:8854', '3:393', '1:345', '2:393', '3:33', '1:454', '2:4947', '3:393',// notice this has started from the start again... '1:123',// as has this.. '2:77', etc etc ); untill the last number of the largest array (number 2 in the original array) have been used. I do have some code to show you but im afraid ive been going at it all the wrong way so im not sure it's of any use. (posted below) - Could someone please help me out? im just not good enough to do this i think... thanks very much indeed.. Nicks messed up code so far: function rubbish_function($machines) { while(count($machines) 1) { for($i=0; $icount($machines); $i++) { sequence[] = ($i+1) . ':' . rtrim($machines[$i][0]); array_shift($machines[$i]); } if(empty($machines[$i])) { array_shift($machines); } else rubbish_function($machines); } return $sequence; } -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Array Sorting Please
* and then Ford, Mike declared php 543 = 2 432 = 2 // like here, more 2's than 1's see? 566 = 2 568 = 2 999 = 3 878 = 3 444 = 3 That's not terribly good, as you are using the unknowns (ip addresses) as keys to the knowns (machine IDs). It would be better keying off the machine IDs, although this does lead to a 2-level array; something like: array( 1 = array(123), 2 = array(543, 432, 566, 568), 3 = array(999, 878, 444) ) That's exactly what i have Mike, the above was what i had generated in an attempt to get the ips in sequential machineId order ;-) So, now im back to square one, do you have a suggestion as to how to acheive the goal? - many, many thanks.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Array Sorting Please
* and then Ford, Mike declared 543 = 2 432 = 2 // like here, more 2's than 1's see? 566 = 2 568 = 2 999 = 3 878 = 3 444 = 3 That's not terribly good, as you are using the unknowns (ip addresses) as keys to the knowns (machine IDs). It would be better keying off the machine IDs, although this does lead to a 2-level array; something like: array( 1 = array(123), 2 = array(543, 432, 566, 568), 3 = array(999, 878, 444) ) That's exactly what i have Mike, the above was what i had generated in an attempt to get the ips in sequential machineId order ;-) So, now im back to square one, do you have a suggestion as to how to acheive the goal? - many, many thanks.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Array Sorting Please
* and then Nick Wilson declared * and then Ford, Mike declared php sorry about the dupes everyone, i changed router today and resent a whole bunch of stuff b4 i realized it wasnt goint out... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Creating a Sequence from Array
* and then Tim Van Wassenhove declared I do have some code to show you but im afraid ive been going at it all the wrong way so im not sure it's of any use. Do you have a clue what your code is doing? Or did you just come up with it? What is the use of writing code that you don't understand? Not going to do your homework, but will give you some hints: Please dont. Thanks. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Array Sorting Please
* and then M Saleh EG declared i'd recommand u to use trees if u got complicated data arrays. use tree datascturcutres... u could sort n do watever then or jus queues or stacks depending on what u wanna do Try PEAR Tree class it might help Hope that was usefull. *very* useful, thankyou so much! ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Muti-Dimensional Array Help Please
hello all, I have some text files in a directory that contain newline delimited IP addresses. Here is what i would like to do with them, and what i have achieved so far: I read the files into a multi-dimensional array like: (pseudo code) array(IP_blocks) = ( File_number[1] = array('ip1', 'ip2', 'ip3') File_number[2] = array('ip1', 'ip2', 'ip3') File_number[3] = array('ip1', 'ip2', 'ip3') ) the ip files have variable numbers of ips, some have 5 ips, some 40 etc.. What i want to do is to run a loop through the whole thing doing a task on each IP address. Easy so far right? - Well, where im stuck is that i want to operate on them like this: do_stuff(File_number[1][ip1]) do_stuff(File_number[2][ip1]) do_stuff(File_number[3][ip1]) do_stuff(File_number[1][ip2]) do_stuff(File_number[2][ip2]) do_stuff(File_number[3][ip2]) I cant even get that far LoL! but then there is the problem of what happens when there is no IP left in an array? (its a short file of ips..)? - I need to start that particular array back at the beggining but continue the cycle (it doesnt matter that an ip is worked on more than once..) Here is the *actual* code I have so far: ##CODE ?php /* * Open the proxies dir and read all of the * ips contained within each file into a mutidimensional * array ($machines) */ $dir = dir('proxies'); while(FALSE !== ($file = $dir-read())) { if($file != '.' $file != '..') { $machines[$file] = file($dir-path . '/' .$file); } } $dir-close(); foreach($machines as $machineId = $ips) { // do stuff here } ###END CODE Im not really expecting anyone to be able to do my work for me but some *guidance* regardig how to tackle this problem would be magnificent... Thankyou.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Muti-Dimensional Array Help Please
* and then M. Sokolewicz declared However, if it does matter, then I suggest a different way. This would Yes, it does matter, a *lot* ;-) I have to hit each machine in order, choosing an IP from that machine and using it do 'do_stuff()' order them by their 2nd index, not the first (meaning by $machines[1][1], $machines[2][1], etc); ?php $max = 0; foreach($machines as $machineId = $ips) { $max = ($max = count($ips) ? $max : count($ips)); } for($i=0;$i$max;$i++) { foreach($machines as $machineId = $ips) { if(isset($ips[$i])) { do_stuff($ips[$i]); } else { continue; } } } ? Would that work with what i said above? im afraid i've never got the hang of the ? operator and dont really understand your code, sorry... thanks very much.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Muti-Dimensional Array Help Please
* and then Ed Lazor declared It looks like you're hading in the right direction. You've grabbed an array of each file. Then cycle through that array and read data from each file. The fread function will allow you to pull data from each file line by line, so you can store each line in an array. Using your idea of pseudo-code: $data = array(); $i = 1; foreach ( file ) { $n = 1; fp = fopen while ($line = fread() ){ $data[$i][$n] = $line; } } foreach ($data as $key = $line ) { foreach ($line as $line_number = $ip) { // do stuff } } hehe, not sure i get it but im playing with it ;-) i need to see code in action for my head to understand it. I did have one rather good though though (i think): If i can create an array with all of the ips in order like this 123.123.123.1 // 1st IP from machine 1 123.123.123.2 // 1st IP from machine 2 123.123.123.3 // 1st IP from machine 3 123.123.123.4 // 2nd IP from machine 1 123.123.123.5 // 2nd IP from machine 2 123.123.123.4 // 2nd IP from machine 3 etc... then i would have *exactly* what the application needs. Does that make the problem any easier? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with Array Sorting Please
Hi, If you scroll up the list you'll see another thread of mine, this is related. The reason for a new thread is that i've made a lot of progress but the old was getting really confusing.. Here's the scoop: I have an array like this: 123 = 1 // each value may have few or many duplicate values 321 = 1 543 = 2 432 = 2 // like here, more 2's than 1's see? 566 = 2 568 = 2 999 = 3 878 = 3 444 = 3 Now, the keys are not the issue. What i would really like, is for that array, to end up like this: 123 = 1 543 = 2 999 = 3 321 = 1 432 = 2 878 = 3 123 = 1 566 = 2 and so on... The important point here is that it does not matter if a key is repeated in the resultant array, in fact, that's *good* as long as it starts from the beggining again when there are no more values = (for example) '1' With me? If it helps to understand, each key is an IP address, each value a Machine number - my job is to never hit the same machine 2x in a row or the same IP 2x in a row, but to cycle through all the IP's on each Machine like the example resultant array. Phew... that was tough to explain, hope it's not a brain twister to understand ;-) Many, many thanks.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php script run by cron job
* and then Merlin declared Hi there, I already managed it to run a php script by cron, but now I cant remember the exact syntax. Somehow it does not work. /var/log/messages tells me that cron has called the line, but it never runs. I did try to run the line without cron and it works. Here is the how I did it: 14 8 * * * root /usr/local/bin/php /home/www/cron/statistics.php No, but then im no cron expert either ;-) Whenever i need to do a cron job i refer to this: http://www.tech-geeks.org/contrib/mdrone/croncrontab-howto.htm If the crontab line is executing but the script aint running try this: 14 8 * * * root php -q /home/www/cron/statistics.php -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] cURL and Proxy Servers
Hello everyone, I'm using cURL and have a question about this line (part of a function) curl_setopt($ch, CURLOPT_PROXY, $proxy2use); I know that *after* I curl_exec() i can find out if the proxy resolved or not with curl_errno() (it would return 5) but it seems that if it does fail to resolve, it will default to the users IP This is not acceptable ;-) I already check that the proxy is up and i can connect to it prior to running my curl function, but if the proxy still doesnt resolve, how might i prevent the curl function form executing? Much thanks for any insight on this... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: cURL and Proxy Servers
* and then Manuel Lemos declared You may want to try this HTTP client class instead. It supports requests via proxies and does not use Curl. http://www.phpclasses.org/httpclient Hmmm.. good point Manuel, i have seen the class, in fact it was the original way i /was/ going to build the script. Wouldnt be hard to rip out the cURL function and replace it with an http method, thanks... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Escaping Regex Chars with addcslashes()
Hi all, If i want to find a url on a page, there are some chars i need to escape right? like '/' and '?' do i also need to escape '.'? Are there any other things that might pop up in a url that I can escape with addcslashes()? Much thanks -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Data cache ideas/solutions
* and then Niklas Ojala declared I am looking for a class or some samples that would read a table from mysql and store it in an array variable, so that it will be avilable to other parts of the page without having to get it from the database again. So I would like to only get the table once per page load but I must be able to filter the table to get the data that I want. I am looking for some similar code to get me started or other ideas on how to make less queries to the database. It may be a little 'overkill' for this particular example but it'll work, and it'll help you keep code and presentation separte (which is a VERY good thing) - Take an hour or two to get to grips with the Smarty template engine: http://smarty.php.net Does exactly what you want and a whole bunch more ;-) i wouldnt build a site without it... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Escaping Regex Chars with addcslashes()
* and then Marek Kilimajer declared If i want to find a url on a page, there are some chars i need to escape right? like '/' and '?' do i also need to escape '.'? Are there any other things that might pop up in a url that I can escape with addcslashes()? Don't use posix regexp, but use perl compatible instead. It has preg_quote() function that is intended for this purpose. I'll go look it up, thanks Marek ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing Response of A Proxy with PHP?
* and then Marek Kilimajer declared oookay... i think i understand the page, but how would i imlement that $fp = fsockopen (proxy.server.net, 8080, $errno, $errstr, 30); if (!$fp) { echo $errstr ($errno)br\n; } else { fputs ($fp, OPTIONS * HTTP/1.0\r\nMax-Forwards: 0\r\n\r\n); while (!feof($fp)) { echo fgets ($fp,128); } fclose ($fp); } You should get something like: HTTP/1.0 200 Ok Date: Sun, 26 Sep 2004 20:48:46 GMT Via: HTTP/1.1 proxy.server.net (Traffic-Server/4.0.18 [c s f ]) Allow: CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PURGE, PUT, PUSH, TRACE Content-Length: 0 Well, it connects great! However, i get errors back about * being a bad url...? -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Loop within Loop help please
hi everyone, I have a simplified bit of code below: ?php foreach($someArray as $someVal) { //do some stuff } ? What i'd like to do is have a count inside that loop that will trigger some action every 20 iterations of the foreach. Like this: ?php $count=0; foreach($someArray as $someVal) { if($count is divisible by 20 exactly) { // do some stuff } //do some stuff } ? How might i do that? Much thanks... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop within Loop help please
* and then Pablo Gosse declared if ($count%20 == 0) http://ca3.php.net/manual/en/language.operators.arithmetic.php in the manual (look for Modulus). Yes, thankyou very much, got a bunch of similar replys in my personal inbox to ;-) And there was me sifting through the math functions! hehe... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop within Loop help please
* and then Marek Kilimajer declared % operator: http://www.php.net/operators Thanks EVERYONE, i feel like i should have known that, but i didnt, my thanks! - and the guy that suggested the other way? that was how i was trying to do it ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop within Loop help please
* and then Jesse Castro declared [snip] ?php $count=0; foreach($someArray as $someVal) { if($count is divisible by 20 exactly) { // do some stuff } //do some stuff } ? [/snip] if($count is divisible by 20 exactly) Can be written as If ($count %20 == 0) % is the modulus operator and works like the division operator, only it returns the remainder instead of the quotient. Ahhh.. thankyou very much jesse, that's great! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop within Loop help please
* and then Jason Davidson declared I see lots of references to modulus, which works fantastic.. but how abut just testing if its equal to 20, then there isnt that extra arthmitc call.. this is just another way to do the same thing.. take your pick.. unless someone can see a bad reason for this method. $count = 0; foreach . { if($count == 20) { . $count = 0; } else { $count++; } } That would be fine, but im afraid in my effort to make the example simple i forgot to ad a line: $count++; ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Getting Header info with PHP?
Hi everyone, Can anyone tell me which functions/areas i need to look at to do the following? * I need to check a proxy server. * I want to have the proxy fetch a php page at my site * my php page should show me *every* header the proxy server sends Is that possible? much thanks, and have a nice sunday morning ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Post vars without using html form
* and then Pahlevanzadeh Mohsen declared You must use Socket Programming. PHP have been supported socket programming. You can choose port 80 then use its functions. There is an easier way. Use the cURL functions: very simple and doing a search for curl php tutorial or similar will help you out :-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Counter?
Hi all, I have a script that at the present just outputs '$count .'br /'' after each iteration of a foreach() loop. I have set implicit_flush so that this works. That's clearly monkey poo though eh? :-) Do I have to get into unkown waters and try and make PHP talk to JS to achieve a kind of 'hit counter' like effect or is there some easier way? ::explanation It should print the $count var after each iteration *replacing* the last $count Im stumped. A little guidance would be much appreciated... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Testing Response of A Proxy with PHP?
hi again all, I cant find any functions that might help me test the response of a proxy server b4 attempting to use it. Do i need to use exec() with ping? Anyone know how to do that? (if that's the case...) mucho grassy arse.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing Response of A Proxy with PHP?
* and then Marek Kilimajer declared I cant find any functions that might help me test the response of a proxy server b4 attempting to use it. Do i need to use exec() with ping? Anyone know how to do that? (if that's the case...) What kind of response? If the server is alive, if the proxy is alive? If an url exists? hehe, good point! Just if the server is alive i guess. I want to use the proxy and want to test if it's responsive b4 i attempt to use it... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing Response of A Proxy with PHP?
* and then Marek Kilimajer declared OPTIONS * HTTP/1.0 More at http://www.freesoft.org/CIE/RFC/2068/63.htm oookay... i think i understand the page, but how would i imlement that and what would be the difference in that and just pinging the server to see if it's responding? Thanks for the help.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing Response of A Proxy with PHP?
* and then Marek Kilimajer declared oookay... i think i understand the page, but how would i imlement that $fp = fsockopen (proxy.server.net, 8080, $errno, $errstr, 30); if (!$fp) { echo $errstr ($errno)br\n; } else { fputs ($fp, OPTIONS * HTTP/1.0\r\nMax-Forwards: 0\r\n\r\n); while (!feof($fp)) { echo fgets ($fp,128); } fclose ($fp); } Okay, thanks marek, i can take it from there ;-) Im tired, its past my bedtime, i'll check the manual in the morning and work on your code. Thanks very, very much! Even if the server is up that does not mean proxy is working. Yep, i get it. THanks.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with fwrite()
Hi all, Im trying to delete a line from a file after having first read the line. The file contains a list or urls, one per new line: like this: urls.txt http://example.com/somedir/ http://www.example.com/page.php?name=Nick+W Here's what I have so far: ?php $file = 'urls.txt'; $f = fopen($file, 'r+'); $url2use = fgets($f); fseek($f, 0); fwrite($f, '', strlen($url2use)); // Where is the gotha? print($url2use); fclose($f); ? Clearly im using fwrite incorrectly (at least i think that's clear ;-) but i cant seem to figure out what im doing wrong? (well, i kinda can but i cant get any further with it without a little help..) Much thanks for your time... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with fwrite()
* and then Nick Wilson declared Hi all, Im trying to delete a line from a file after having first read the line. The file contains a list or urls, one per new line: like this: BTW, reading the file into an array, shifting off the first element and rewriting isnt a good option for me as the urls.txt file can be *very* big... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with fwrite()
* and then John Nichel declared John Holmes wrote: You can't just remove part of a file like you remove part of a string. You'll need to read (eventually) the entire file and only write back what you want to keep. Now, you said this could be a very large file, so you don't want to read the whole thing into memory. That's smart, so maybe using a swap file would be handy? Read from file1, if it's a URL you want to keep, then write it to file2. rinse, lather, repeat and at the end rename file2 to file1. This way you're only reading one line at a time into memory. Is keeping this info in a db an option? Not a good one, no. I've tried to figure a schema for it but it's been a long time since i did db work ;-) Speed is key here, it's an app that uses the Google API to fetch relevant urls, then uses cURL to fetch the pages, and if the user wants, to POST to that page. A DB would be okay i think but filesystem calls are just faster aren't they? Where I fail on the DB schema is getting my head around the relationship between the data, here's roughly what i need to do if anyone is curious or might prod me in the right direction... Each user (must have an id,name clearly) can fetch as many urls as they wish, those urls get written to the db, then as each url is fetched from the db it is dealt with with php and deleted from the db. What if a user gets cut off from the script and a whole bunch of unwanted urls are in the db though? Should the db go like this? db_urls url_id | user_id | project_id | url db_user user_id | name | whatever db_project project_id | user_id Wow, now i've written it down it seems clearer ;) you guys reckon that's the right kind of schema (based on what you know from the above..)? Thanks John Holmes, that's seems pretty neat but i may have been mistaken, i did a test with 5000 urls (shouldnt get much more than that at any one time) and the memory usage wasnt so bad at all... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with fwrite()
* and then John Holmes declared Should the db go like this? db_urls url_id | user_id | project_id | url db_user user_id | name | whatever db_project project_id | user_id Wow, now i've written it down it seems clearer ;) you guys reckon that's the right kind of schema (based on what you know from the above..)? That structure looks good, but it really depends upon what dealt with by PHP means. Well, the url is fetched into a variable by cURL, i then do a whole bunch of stuff with that variable with regex and wotnot, then the user decides if they want to post to that url, or discard it. Either way, the result is the url is deleted from the db_url (and now i think more about it, written to db_url_done - or a flag put on db_url (that's better i think)) As for the user getting cut off with urls still in the DB... it shouldn't Yeah, i realized that the moment i sent the mail ;-) they should be able to pick up with a project right where they left off my thanks, always good to get your schema cheked out by more knowledgable folk -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] iguanahost - anyone else being plagued?
Anyone else getting these infuriating italian messages about some muppet that doesnt exist? 'desintione non existente'? I've written to [EMAIL PROTECTED] but no joy, everytime i post on the php list i get half a dozen of the damn things... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] iguanahost - anyone else being plagued?
* and then Gryffyn, Trevor declared It appears to be a user not found type error..'desintione non I must say, im glad it's not just me hehe! I was beginning to think it was just me. I've been away from the list (never a big participant...) for a while but stuff like that used got sorted faster...? -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Delete Line from File?
Whats the easiest/best way to do that with php? just replace the line with ''? -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Delete Line from File?
* and then John Holmes declared Whats the easiest/best way to do that with php? just replace the line with ''? Yes, basically. You have to read the file, replace the part you don't want with an empty string and then re-write the file. If the file is small and you're using file() to read it, you can just unset() the element you don't want, then join the array back together and write it. Great, it just seems a bit clumsy which was why i thought maybe i was looking at it the wrong way.. my thanks! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Outputting HTML with PHP - Buffer Problem?
Hi all, Say i have a php script like this: ?php print(html_head()); // do loads of time taking stuff print(html_footer()); ? How come I dont see the html header (it's just a function that returns a string with the html up till body) before the entire script has run? This goes against my understanding, why might this be and what might i use to get some output before the script has finished executing? Much thanks... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Outputting HTML with PHP - Buffer Problem?
* and then Jason Davidson declared i prefer to escape from php inside my header fucntion, and just not print it.. eg. function header() { ? html head title ? } Yes, i remember now, thanks ;-) I've been using Smarty (smarty.php.net) for so long now that i've forgotten how this stuff works without it hehe... This is a script for a few mates that dont have php knowledge, just raw html output Thanks.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Outputting HTML with PHP - Buffer Problem?
* and then John Holmes declared How come I dont see the html header (it's just a function that returns a string with the html up till body) before the entire script has run? This goes against my understanding, why might this be and what might i use to get some output before the script has finished executing? Could be your web server buffering the output until the script finishes or something else on your connection doing the same. Some web browsers will not show content until everything is received. You could try using flush() to see if that helps. Ok, that makes sense, i was fairly certain that i wasnt mistaken in thinking it should woek the way i expected... Cheers John,.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Outputting HTML with PHP - Buffer Problem?
* and then M. Sokolewicz declared How come I dont see the html header (it's just a function that returns a string with the html up till body) before the entire script has run? This goes against my understanding, why might this be and what might i use to get some output before the script has finished executing? Much thanks... that's because it's all sent as 1 single big chunk of data. To get around this, you should set implicit_flush to 1 (it's in php.ini). Otherwise, you can also use the PHP ob_implicit_flush() to do this. Setting it to 1 will flush the output buffer everytime it's written to, if set to 0 it will do as normal, and buffer it all to send it together. ah... now that makes a lot of sense, ill check that out, much thx... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] cURL Help - Posting a Form
hi all, Im trying to get the following php code to output the 'success'/'failure' page from posting a form to a site. The problem is that there is no output at all, so i must be doing somthing silly, but cant work out what! ;-) ## Code $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, http://example.com/form.html;); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_REFERER, http://nowhere.com;); curl_setopt($ch, CURLOPT_USERAGENT, CommentMaker 0.8); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POSTFIELDS, static=$staticentry_id=$entry_idauthor= . urlencode($author) . email= . urlencode($email) .url=$myurlbakecookie=Forget+Infotext= . urlencode($text) . post=+Post+); $result=curl_exec($ch); curl_close($ch); print($result); ## End Code Anyone see the problem/mistake? Much thx... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cURL Help - Posting a Form
* and then Nick Wilson declared hi all, Im trying to get the following php code to output the 'success'/'failure' page from posting a form to a site. The problem is H... it helps if you are submitting to the 'action' url of course sigh -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Parsing HTML files
Hi all, I was wondering if any classes/functions could help me with this little challenge, (im hopeless at regex ;-) input type=hidden name=id value=593 / I want to extract the value of 'id' from a webpage. Any simple way to do this or am I down to sweating of the regex functions? Much thanks -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parsing HTML files
* and then Abdul-Wahid Paterson declared No easy way of doing it, regex somthing like: $id = preg_replace(/.*input.*name=\id\ value=\[0-9]+\ \//, $1, $string); where $string is a line from your input'd HTML page OK, thanks abdul, much appreciated.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] !!Urgent .. Session Problem
* and then Dre declared I'm sorry about the capital letters and nop I'm not prepending any files at all Can I get a look at the file? -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] !!Urgent .. Session Problem
* and then Dre declared Warning: session_start(): open(/tmp\sess_2984f6d378560d0882f37728dbe1defc, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\ELBA\logme_in.php on line 3 Check your php.ini for session.save_path= Im not sure where the temp dir is on a windows box, but point it to there and that should do it I think. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\ELBA\logme_in.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\ELBA\logme_in.php on line 3 Check the file for white space, this always gets me too ;-) Like this start of file ?php - See the new line above the php? that would cause that error. Check your file for somthing similar... the session.save_path parameter in my php.ini file is as follows ** session.save_path = C:/WINDOWS/Temp ** Damn! should have read the whole thing b4 replying! hehe you might have several php.ini's find the right one! on my gentoo box it's in /etc/apache2/conf/php.ini but there's also one in /etc/php.ini -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] !!Urgent .. Session Problem
* and then Dre declared first of all thanks for ur reply you're most welcome there are no white spaces before the ?php in my .php file and I do have ONLY one php.ini file in the whole system drive (I'm sure of this) See the other reply, that sounds like it.. i was unaware of this... is there a special format for writing paths in the php.ini file .. as I do believe that I pointed correctly to the temp folder ??? Dont know. Try this though ?php ini_set'session.save_path', 'path/to/tmp'); at the top of your script. It's an inelegant solution, you really need to get it right in the ini file but it might help you debug it for now... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] !!Urgent .. Session Problem
* and then M. Sokolewicz declared also, please remember you need to restart your webserver to actually have PHP re-read the php.ini file. If you don't, then nothing will change in run-time, even though the php.ini file might have changed *a lot* heheheh! that's most probably it! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex for Validating URL
* and then Jim Grill declared Guys, while we may be able to debate what is rude, what is blunt, what should have been said, what was said, the facts are clear. He apologized, and I think its time to lest this debate rest for now. While I would admit that harshness runs rampid on this list, there are times that maybe it is in order. If that time is now or not is a moot point at the moment. Let's get back to peaceful exchange of PHP pleasantries. -Dan Joseph Very nicely said, Dan. I'm with you. :-) PHP is pleasant. I can abide by that ;-) -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: File Transfer
* and then Nadim Attari declared This gonna help: http://www.php.net/ftp I think you could also use the cURL functions. But ftp seems the way to go... -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php