Re: [PHP] framework or not
On 25 Oct 2013, at 15:40, Robert Cummings wrote: > On 13-10-25 10:17 AM, Stuart Dallas wrote: >> On 25 Oct 2013, at 15:01, Robert Cummings wrote: >> >>> On 13-10-24 09:41 PM, Larry Garfield wrote: >>>> On 10/23/2013 08:51 AM, Jay Blanchard wrote: >>>>> [snip] a bitter rant[/snip] >>>>> >>>>> Dang Larry - bad night? >>>> >>>> That wasn't a bitter rant. You haven't seen me bitter. :-) That was >>>> "tough love" to the OP. I don't see a reason to pussyfoot around the >>>> original question, which is one that comes up about once a month. The >>>> answer is always the same: How much is your time worth? >>> >>> Basic math... >>> >>>Life: finite >>>Time: infinite >>> >>>finite / infinite = 0 >>> >>> *sniffle* >> >> Who's valuation of your time actually matters? Yours, and yours alone. >> >> Therefore: >> >> Life: n years >> Time I can benefit from my life: n years >> >> n years / n years = 1 >> >> *hoorah* >> >> Your time is the most precious commodity you have. >> >> Whether you use a framework or not you will (hopefully) reuse code between >> projects. If you choose to make part of that reused code one of the many >> frameworks that exist, you need only do one thing to ensure it continues to >> be worth using: how much of your time do you spend battling against the >> restrictions of the framework? If that's sufficiently low then using that >> framework is probably a good thing. If a significant portion of your time is >> spent battling the framework it's time to make a change. >> >> Also remember that the only person who can truthfully judge whether you're >> "wasting time" is you, unless you earn money by selling your time to someone >> else in which case they have some right to decide what constitutes a waste >> of the time for which they're paying. I found the experience of writing my >> own framework to be hugely beneficial to my future productivity, but I might >> have struggled to justify spending the extra time it took to my employer at >> the time. > > You stripped away the context of my response. By removing the evil grin you > made it look like I was serious. You should be a reporter ;) Who says I'm not! :) -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Persistent connections
On 25 Oct 2013, at 12:51, Nibin V M wrote: > Thank you for the quick response Stuart...one more doubt..at > http://php.net/manual/en/features.persistent-connections.php they states > > = > This means that when the same client makes a second request to the server, it > may be served by a different child process than the first time. When opening > a persistent connection, every following page requesting SQL services can > reuse the same established connection to the SQL server > = > > Is the persistent connection pool is re-used between apache child processes ? No, connections are not shared between PHP processes. Nothing is shared between PHP processes. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Fri, Oct 25, 2013 at 3:54 PM, Stuart Dallas wrote: > On 25 Oct 2013, at 11:10, Nibin V M wrote: > > > I have been reading docs and many are telling that persistent connections > > are kept open indefinitely. But I found in PHP docs that it will not close > > after script execution like requesting a page; so should it close after > > the request is over? > > > > So when exactly a persistent connection should close? > > > > Please advice. > > A persistent connection is closed when the PHP process ends, or it gets > disconnected by the server-side or due to a network error. Attempting to > explicitly close a persistent connection will do nothing without complaining. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > > > > -- > Regards > > Nibin. > > http://TechsWare.in -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] framework or not
On 25 Oct 2013, at 15:01, Robert Cummings wrote: > On 13-10-24 09:41 PM, Larry Garfield wrote: >> On 10/23/2013 08:51 AM, Jay Blanchard wrote: >>> [snip] a bitter rant[/snip] >>> >>> Dang Larry - bad night? >> >> That wasn't a bitter rant. You haven't seen me bitter. :-) That was >> "tough love" to the OP. I don't see a reason to pussyfoot around the >> original question, which is one that comes up about once a month. The >> answer is always the same: How much is your time worth? > > Basic math... > >Life: finite >Time: infinite > >finite / infinite = 0 > > *sniffle* Who's valuation of your time actually matters? Yours, and yours alone. Therefore: Life: n years Time I can benefit from my life: n years n years / n years = 1 *hoorah* Your time is the most precious commodity you have. Whether you use a framework or not you will (hopefully) reuse code between projects. If you choose to make part of that reused code one of the many frameworks that exist, you need only do one thing to ensure it continues to be worth using: how much of your time do you spend battling against the restrictions of the framework? If that's sufficiently low then using that framework is probably a good thing. If a significant portion of your time is spent battling the framework it's time to make a change. Also remember that the only person who can truthfully judge whether you're "wasting time" is you, unless you earn money by selling your time to someone else in which case they have some right to decide what constitutes a waste of the time for which they're paying. I found the experience of writing my own framework to be hugely beneficial to my future productivity, but I might have struggled to justify spending the extra time it took to my employer at the time. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Persistent connections
On 25 Oct 2013, at 11:10, Nibin V M wrote: > I have been reading docs and many are telling that persistent connections > are kept open indefinitely. But I found in PHP docs that it will not close > after script execution like requesting a page; so should it close after > the request is over? > > So when exactly a persistent connection should close? > > Please advice. A persistent connection is closed when the PHP process ends, or it gets disconnected by the server-side or due to a network error. Attempting to explicitly close a persistent connection will do nothing without complaining. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Trying to understand what is happening in this code
On 11 Oct 2013, at 16:20, Nathan Grey wrote: > Stuart, Jose - Thanks for your quick response. Are you saying that the > processor echos all the html tags it sees. Is it doing something like this to > the script: > > echo > echo The first twenty Fibonacci numbers: > echo > $first = 0; >$second = 1; >for ($i = 0; $i < 20; $i++) { > ?> > echo >$temp = $first + $second; > $first = $second; > $second = $temp; > > } ?> > echo > echo > > Or is it just the line in question that is being echoed? I'm not sure exactly what it gets compiled to, but I also don't see why it matters. All that matters is that content outside of PHP tags will simply get echo'd. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Fatal error: Call to undefined function ()
On 7 Oct 2013, at 14:34, Michael Alaimo wrote: > On Mon, Oct 7, 2013 at 9:29 AM, Stuart Dallas wrote: >> On 7 Oct 2013, at 14:24, Michael Alaimo wrote: >> >> > We have a server that gets a large number of requests each month. >> > >> > After a period of time I began to see this error in our error logs this >> > weekend. >> > >> > PHP Fatal error: Call to undefined function () >> > >> > It does not reference a function, so I found it odd. It did give a line to >> > a function with array_merge on it. >> > >> > Has anyone seen this in the apache error logs? We are using PHP 5.3.3. >> >> Show us the line, and a few lines around it. > public static function getInfo($params = array()) > { > $results = array(); > > $url = 'http://google.com'; > > > $props = array > ( >'key'=> Yii::app()->params['param1'], > 's'=> Yii::app()->params['param2'] > ); > > if (!empty($params)) > { > $props = array_merge($props, $params); > > $url = $url . http_build_query($props, '', '/'); > > > It may be possible that params has unsafe data in it. The previous dev did > not validate the data passed in via get. > > The code populating params looks like: > > $params = array > ( > 'd' => $_GET['d'], > ); > > $job = Job::getInfo($params); My best guess is that either $props or $params contain a function reference or similar construct. Examine their contents with var_dump. As a check you could expand out the effect of array_merge and see if you still get the same with a PHP implementation. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Fatal error: Call to undefined function ()
On 7 Oct 2013, at 14:24, Michael Alaimo wrote: > We have a server that gets a large number of requests each month. > > After a period of time I began to see this error in our error logs this > weekend. > > PHP Fatal error: Call to undefined function () > > It does not reference a function, so I found it odd. It did give a line to > a function with array_merge on it. > > Has anyone seen this in the apache error logs? We are using PHP 5.3.3. Show us the line, and a few lines around it. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Algorithm Help
On 1 Oct 2013, at 19:51, Floyd Resler wrote: > Here's my task: A group of kids is going to be staying with different host > families throughout the next 8 months. The number of kids staying with a > host family can range from 2 to 10. When deciding which kids should stay > together at a host family, the idea is for the system to put together kids > who have stayed with each other the least on past weekends. So, if a host > family can keep 5 kids, then the group of 5 kids who have stayed together the > least will be chosen. > > I can't think of an easy, quick way to accomplish this. I've tried various > approaches that have resulted in a lot of coding and being very slow. My > idea was to give each group of kids a score and the lowest score is the group > that is selected. However, this approach wound of iterating through several > arrays several times which was really slow. Does anyone have any ideas on > this puzzle? Sounds like a job for a directed graph data structure. I wish I had time to knock up a solution but I don't right now. This article should help you get started: http://www.codediesel.com/algorithms/building-a-graph-data-structure-in-php/ -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache
On 23 Sep 2013, at 11:37, Domain nikha.org wrote: > Tamara Temple am Montag, 23. September 2013 - 06:49: >> >> GoDaddy's default plesk-generated configuration for FastCGI-served PHP > files only looked to see if the file contained ".php" somewhere on it's > path - i.e. it would happily execute 'malicilous.php.txt' as php code, > even something ridiculous like 'malware.phpnoreallyiwantthistorun'. >> > > Yes, looks stupid. > But my service prodider wrote me this, I quote: > ---QUOTE--- > This is because Apache offers features like language negotiation based > on extensions, too -- the final extension doesn't always just specify > the handler; it can specify other things. Apache can automatically pick > a German-language script from these, for example: > > file.php.de > file.php.en > > Whether this is a good idea or not is debatable. It's possible to set > things up in a different way (using FilesMatch instead of AddHandler) > to > avoid this particular problem, but that breaks other things, so there's > no perfect solution. > > More generally, the real problem is that scripts are looking at the > final extension of uploaded files to decide whether they're safe or > not, > which is dangerous. They're simply assuming that a ".gif" file can't > run > a PHP interpreter, for example... which is usually true, but certainly > not always: some people run all their files through PHP. > ---END QUOTE--- This is somewhat daft. Yes, Apache offers this feature, but you don't need to configure it to work will all extensions. I'd be curious to know what their issue is with using FilesMatch, since that provides a way to disable this behaviour. And, honestly, who would have a PHP file per language? I think it's perfectly reasonable to not allow that, because duplicating PHP code across many files is an incredible stupid way to support multiple languages. "Some people run all their files through PHP" - true, but that doesn't mean they should, or that you, as a responsible web host, should be endorsing it. > The problem is the weak PHP upload mechanism! > As workaround my service provider tries to block suspicious filenames, > but the PHP developpers themself should work on this severe security > problem. PHP developers should absolutely validate all content coming in from users in every possible way, but I would be highly dubious about trusting a host who gives the reason above for what I consider a lax and insecure Apache configuration. It's like saying they sliced your arm off with their chainsaw because it's made for cutting things, attempting to dodge all responsibility for having swung it in your direction! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache's PHP handlers
On 19 Sep 2013, at 14:39, Aziz Saleh wrote: > The best way to handle file uploads is to: > > 1) Store the filename somewhere in the DB, rename the file to a random string > without extension and store the mapping in the DB as well. > 2) When sending the file, set the header content to the filename and output > the content of the file via PHP (ex: by readfile). > > Aziz > > This way even if the file is PHP code, it will be of no issue to you. What you describe it highly inefficient, clunky, and unnecessary. You've managed to get PHP and a database involved in serving a static file, for no reason other than to avoid fixing the web server configuration. A misconfigured web server should be fixed, not worked around. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache's PHP handlers
On 19 Sep 2013, at 13:58, "Design in Motion Webdesign" wrote: > it has nothing to do with ".php" in the file name. What the hacker did, was > uploading a .gif file with some malicious php code included to your > webserver. Then he called the .gif file from his own website by using a php > script containing some code like > require_once('http://www.yoursite.com/images/yourimage.gif'). At that moment > the php code inside the .gif file has been executed. In possibly the most pointless way ever! In that scenario the script would be executed on the "hacker"'s server (assuming Apache is set up correctly), so there's no point in her managing to put it on your server at all! Arno: If you can request that file using a web browser, and it gets executed as PHP on your server then there is an error in the Apache configuration. Easy test: create a file in a text editor containing some PHP ( would be enough) and upload it to the www root of your site and name it test.pgif. Then hit http://www.yourdomain.com/test.pgif in your browser. If you see the PHP code or an error then you're fine. If you see PHP's info page then you need to change web host as quickly as possible. I don't care if they fix it - the fact their server was configured to do this by default is enough for me to never trust them again. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] high traffic websites
On 18 Sep 2013, at 12:50, Negin Nickparsa wrote: > to be more in details,suppose the website has 80,000 users and each page > takes 200 ms to be rendered and you have thousand hits in a second so we > want to reduce the time of rendering. is there any way to reduce the > rendering time? > > other thing is suppose they want to upload files simultaneously and the > videos are in the website not on another server like YouTube and so streams > are really consuming the bandwidth. > > Also,It is troublesome to get backups,when getting backups you have problem > of lock backing up with bulk of data. Your question is impossible to answer efficiently without profiling. You need to know what PHP is doing in those 200ms before you can target your optimisations for maximum effect. I use xdebug to produce trace files. From there I can see exactly what is taking the most amount of time, and then I can look in to how to make that thing faster. When I'm certain there is no faster way to do what it's doing I move on to the next biggest thing. Of course there are generic things you should do such as adding an opcode cache and looking at your server setup, but targeted optimisation is far better than trying generic stuff. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP CLI setting cooked terminal mode
On 11 Sep 2013, at 17:37, Alain Williams wrote: > Hi, > > I am running a PHP script at the command line and piping the output through > less: > >./myScript | less > > Since less is an interactive program it puts the terminal into 'raw' mode so > that it can read characters one at a time. However, when I do the above I find > that the commands that I type to less are echoed back to me and not acted on > until I type . This is not as it should be. > > The sript is not doing anything really clever, just looking at a few files and > printing out directory contents, time stamps, ... > > If I run the script under strace I see: > >ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo > ...}) = 0 >ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) > = 0 > > > I can get it to not do this by connect stdout to /dev/null: > >./myScript > /dev/null | less > > another way of getting it to work is (and this shows that it really is PHP > that > is messing the tty modes): > >./myScript > /dev/null | (sleep 10;less) > > However: PHP should not set the terminal to cooked mode in the first place > > Is there any way in which I can get PHP to not do this ? > > TIA > > I am running PHP 5.3.3 on CentOS 6. Make sure output buffering is off by putting this at the top of your script: while(ob_end_clean()); -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED]
On 4 Sep 2013, at 00:03, "Daevid Vincent" wrote: >> -Original Message- >> From: Stuart Dallas [mailto:stu...@3ft9.com] >> Sent: Tuesday, September 03, 2013 2:37 PM >> To: Daevid Vincent >> Cc: php-general@lists.php.net; 'Jim Giner' >> Subject: Re: [PHP] refernces, arrays, and why does it take up so much >> memory? [SOLVED] >> >> On 3 Sep 2013, at 21:47, "Daevid Vincent" wrote: >>> We get over 30,000 hits per second, and even with lots of caching, 216MB >>> vs 70-96MB is significant and the speed hit is only about 1.5 seconds more >>> per page. >>> >>> Here are three distinctly different example pages that exercise >>> different parts of the code path: >>> >>> PAGE RENDERED IN 7.0466279983521 SECONDS >>> MEMORY USED @START: 262,144 - @END: 26,738,688 = 26,476,544 BYTES >>> MEMORY PEAK USAGE: 69,730,304 BYTES >>> >>> PAGE RENDERED IN 6.9327299594879 SECONDS >>> MEMORY USED @START: 262,144 - @END: 53,739,520 = 53,477,376 BYTES >>> MEMORY PEAK USAGE: 79,167,488 BYTES >>> >>> PAGE RENDERED IN 7.55816092 SECONDS >>> MEMORY USED @START: 262,144 - @END: 50,855,936 = 50,593,792 BYTES >>> MEMORY PEAK USAGE: 96,206,848 BYTES >> >> Knowing nothing about your application I'm obviously not in a strong >> position to comment, but seven seconds to generate a page would be >> unacceptable to me and any of my clients. > > It's a "one time hit" and the rest is served from a cache for the next 24 > hours which serves very very fast after that initial rendering. It's just we > have so many thousands of pages that this becomes an issue -- especially > when webcrawlers hit us and thread-out so MANY pages are trying to render at > the same time, especially the ones towards the end where they haven't been > cached since rarely do real people get that far... Like you know, pages 900, > 901, 902, etc... with new content each day, page 1 today is now page 2 > tomorrow, so it's a constant thorn. At 30k requests per second, is it a one-time hit, or is it 225k hit because in the 7 seconds it takes the cache to be built you have that many clients also building the cache? Or is this already an offline script, in which case how long it takes is largely irrelevant. What is your caching strategy? What is cached? At what granularity? When is the cache updated (i.e. on demand or on change)? Why does a page need to retrieve so much data? Can that data not be summarised/processed ahead of demand? >> I'll put money on it being >> possible to cut that time by changing your caching strategy. The memory >> usage is also ridiculous - does a single page really display that amount > of >> data? Granted, there are some applications that cannot be optimised beyond > a >> certain point, but those numbers make me sad! > > HA! It was over 400MB per page a few weeks ago. I keep whittling it down, > but I think I'm hitting the lower limit at this point. That is nuts! What's the website? > It's a tough balance between database hits, cache hits, network traffic > (memcached), disk i/o, page speed, load balancing, etc. All we can do is try > things and tweak and see what works and what brings the servers to their > binary knees. Without knowing anything about the site there's little I can say, but if you want to take this off-list I'm happy to talk about it. I have a fair amount of experience with high-traffic web applications so it's possible I might be able to help. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED]
NDS > MEMORY USED @START: 262,144 - @END: 53,739,520 = 53,477,376 BYTES > MEMORY PEAK USAGE: 79,167,488 BYTES > > PAGE RENDERED IN 7.55816092 SECONDS > MEMORY USED @START: 262,144 - @END: 50,855,936 = 50,593,792 BYTES > MEMORY PEAK USAGE: 96,206,848 BYTES Knowing nothing about your application I'm obviously not in a strong position to comment, but seven seconds to generate a page would be unacceptable to me and any of my clients. I'll put money on it being possible to cut that time by changing your caching strategy. The memory usage is also ridiculous - does a single page really display that amount of data? Granted, there are some applications that cannot be optimised beyond a certain point, but those numbers make me sad! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] refernces, arrays, and why does it take up so much memory?
On 3 Sep 2013, at 02:30, Daevid Vincent wrote: > I'm confused on how a reference works I think. > > I have a DB result set in an array I'm looping over. All I simply want to do > is make the array key the "id" of the result set row. > > This is the basic gist of it: > > private function _normalize_result_set() > { > foreach($this->tmp_results as $k => $v) > { > $id = $v['id']; > $new_tmp_results[$id] =& $v; //2013-08-29 [dv] using a > reference here cuts the memory usage in half! You are assigning a reference to $v. In the next iteration of the loop, $v will be pointing at the next item in the array, as will the reference you're storing here. With this code I'd expect $new_tmp_results to be an array where the keys (i.e. the IDs) are correct, but the data in each item matches the data in the last item from the original array, which appears to be what you describe. > unset($this->tmp_results[$k]); Doing this for every loop is likely very inefficient. I don't know how the inner workings of PHP process something like this, but I wouldn't be surprised if it's allocating a new chunk of memory for a version of the array without this element. You may find it better to not unset anything until the loop has finished, at which point you can just unset($this->tmp_results). > > /* > if ($i++ % 1000 == 0) > { > gc_enable(); // Enable Garbage Collector > var_dump(gc_enabled()); // true > var_dump(gc_collect_cycles()); // # of elements > cleaned up > gc_disable(); // Disable Garbage Collector > } > */ > } > $this->tmp_results = $new_tmp_results; > //var_dump($this->tmp_results); exit; > unset($new_tmp_results); > } Try this: private function _normalize_result_set() { // Initialise the temporary variable. $new_tmp_results = array(); // Loop around just the keys in the array. foreach (array_keys($this->tmp_results) as $k) { // Store the item in the temporary array with the ID as the key. // Note no pointless variable for the ID, and no use of &! $new_tmp_results[$this->tmp_results[$k]['id']] = $this->tmp_results[$k]; } // Assign the temporary variable to the original variable. $this->tmp_results = $new_tmp_results; } I'd appreciate it if you could plug this in and see what your memory usage reports say. In most cases, trying to control the garbage collection through the use of references is the worst way to go about optimising your code. In my code above I'm relying on PHPs copy-on-write feature where data is only duplicated when assigned if it changes. No unsets, just using scope to mark a variable as able to be cleaned up. Where is this result set coming from? You'd save yourself a lot of memory/time by putting the data in to this format when you read it from the source. For example, if reading it from MySQL, $this->tmp_results[$row['id']] = $row when looping around the result set. Also, is there any reason why you need to process this full set of data in one go? Can you not break it up in to smaller pieces that won't put as much strain on resources? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic Auth
On 27 Aug 2013, at 18:45, Jim Giner wrote: > From your latest missive I gleaned that I needed to have a script on my server One last time: YOU DON'T NEED TO CHANGE ANYTHING ON THE SERVER-SIDE! Ok, I see that you've decided to use another method, which is great; HTTP auth is a pretty antiquated way to handle authentication these days. Whatever you're using, I wish you all the best with it. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] Basic Auth
On 27 Aug 2013, at 17:28, Jim Giner wrote: > On 8/27/2013 11:56 AM, Stuart Dallas wrote: >> Oops, sent this message from the wrong email address, so the list rejected >> it. >> >> Begin forwarded message: >> >>> From: Stuart Dallas >>> Subject: Re: [PHP] Basic Auth >>> Date: 27 August 2013 16:36:27 BST >>> To: jim.gi...@albanyhandball.com >>> Cc: php-general@lists.php.net >>> >>> On 27 Aug 2013, at 15:59, Jim Giner wrote: >>> >>>> On 8/27/2013 10:55 AM, Stuart Dallas wrote: >>>>> On 27 Aug 2013, at 15:51, Jim Giner wrote: >>>>> >>>>>> On 8/27/2013 10:39 AM, Stuart Dallas wrote: >>>>>>> On 27 Aug 2013, at 15:18, Jim Giner >>>>>>> wrote: >>>>>>> >>>>>>>> On 8/27/2013 10:14 AM, Stuart Dallas wrote: >>>>>>>>> It's not really confusing so long as you understand how PHP works. >>>>>>>>> Each request is brand new - nothing is retained from previous >>>>>>>>> requests. The two variable you're changing are set by PHP when the >>>>>>>>> request comes in from the browser. The fact you changed them in a >>>>>>>>> previous request is irrelevant because 1) that change was not >>>>>>>>> communicated to the browser in any way, and 2) PHP doesn't retain any >>>>>>>>> data between requests [1]. >>>>>>>>> >>>>>>>>> If you've been coding assuming that changes you make to global >>>>>>>>> variables are retained between requests you must have been having >>>>>>>>> some pretty frustrating times! >>>>>>>>> >>>>>>>>> -Stuart >>>>>>>>> >>>>>>>> Not really - this is the first time I've had something not work as >>>>>>>> expected. >>>>>>> That was said with my tongue very much firmly in my cheek, and so is >>>>>>> this: >>>>>>> >>>>>>> I've been playing with dynamite since I was 4 - hey, it must be a >>>>>>> safe, proper thing to do! >>>>>>> >>>>>>> Just because nothing has blown up in your face yet doesn't mean it >>>>>>> won't, and I'm concerned that you might not actually see how important >>>>>>> it is to make sure you're using the tool correctly. >>>>>>> >>>>>>> -Stuart >>>>>>> >>>>>> This may very well be the first time with this problem because I haven't >>>>>> tried anything like this before. >>>>>> >>>>>> That said - can you give me some pointers on how to do the JS solution? >>>>>> I'm calling a script that is similar to the one I used to signon. It >>>>>> sends out something like: >>>>>> >>>>>> header("WWW-Authenticate: Basic realm=$realm"); >>>>>> header('HTTP/1.0 401 Unauthorized'); >>>>>> echo "You have entered invalid credentials"; >>>>>> echo "Click here to return to the >>>>>> menu."; >>>>>> exit(); >>>>>> >>>>>> when it doesn't detect the PHP_AUTH_USER or it is an invalid value. >>>>>> >>>>>> So - to effect a signoff, what does one do? You said to use an invalid >>>>>> value, but what do I do with that? How do I ignore the 401? Now I'm >>>>>> getting the signin dialog and I'm stuck. >>>>> You don't need to do anything on the server-side. You simply need a JS >>>>> function that sends a request to a URL that requires basic auth, with an >>>>> Authenticate header that contains an invalid username and password. Then, >>>>> when your server responds with a 401 Authentication required (which it >>>>> should already do for an invalid request) you can set location.href to >>>>> whatever URL you want the logged out user to see. >>>>> >>>>> If you don't know how to make a request from Javascript -- commonly known >>>>> as an AJAX
Fwd: [PHP] Basic Auth
Oops, sent this message from the wrong email address, so the list rejected it. Begin forwarded message: > From: Stuart Dallas > Subject: Re: [PHP] Basic Auth > Date: 27 August 2013 16:36:27 BST > To: jim.gi...@albanyhandball.com > Cc: php-general@lists.php.net > > On 27 Aug 2013, at 15:59, Jim Giner wrote: > >> On 8/27/2013 10:55 AM, Stuart Dallas wrote: >>> On 27 Aug 2013, at 15:51, Jim Giner wrote: >>> >>>> On 8/27/2013 10:39 AM, Stuart Dallas wrote: >>>>> On 27 Aug 2013, at 15:18, Jim Giner wrote: >>>>> >>>>>> On 8/27/2013 10:14 AM, Stuart Dallas wrote: >>>>>>> It's not really confusing so long as you understand how PHP works. Each >>>>>>> request is brand new - nothing is retained from previous requests. The >>>>>>> two variable you're changing are set by PHP when the request comes in >>>>>>> from the browser. The fact you changed them in a previous request is >>>>>>> irrelevant because 1) that change was not communicated to the browser >>>>>>> in any way, and 2) PHP doesn't retain any data between requests [1]. >>>>>>> >>>>>>> If you've been coding assuming that changes you make to global >>>>>>> variables are retained between requests you must have been having some >>>>>>> pretty frustrating times! >>>>>>> >>>>>>> -Stuart >>>>>>> >>>>>> Not really - this is the first time I've had something not work as >>>>>> expected. >>>>> That was said with my tongue very much firmly in my cheek, and so is this: >>>>> >>>>> I've been playing with dynamite since I was 4 - hey, it must be a safe, >>>>> proper thing to do! >>>>> >>>>> Just because nothing has blown up in your face yet doesn't mean it won't, >>>>> and I'm concerned that you might not actually see how important it is to >>>>> make sure you're using the tool correctly. >>>>> >>>>> -Stuart >>>>> >>>> This may very well be the first time with this problem because I haven't >>>> tried anything like this before. >>>> >>>> That said - can you give me some pointers on how to do the JS solution? >>>> I'm calling a script that is similar to the one I used to signon. It >>>> sends out something like: >>>> >>>> header("WWW-Authenticate: Basic realm=$realm"); >>>> header('HTTP/1.0 401 Unauthorized'); >>>> echo "You have entered invalid credentials"; >>>> echo "Click here to return to the menu."; >>>> exit(); >>>> >>>> when it doesn't detect the PHP_AUTH_USER or it is an invalid value. >>>> >>>> So - to effect a signoff, what does one do? You said to use an invalid >>>> value, but what do I do with that? How do I ignore the 401? Now I'm >>>> getting the signin dialog and I'm stuck. >>> You don't need to do anything on the server-side. You simply need a JS >>> function that sends a request to a URL that requires basic auth, with an >>> Authenticate header that contains an invalid username and password. Then, >>> when your server responds with a 401 Authentication required (which it >>> should already do for an invalid request) you can set location.href to >>> whatever URL you want the logged out user to see. >>> >>> If you don't know how to make a request from Javascript -- commonly known >>> as an AJAX request -- then google for it. I'd recommend the jquery library >>> if you want a very easy way to do it. >>> >>> -Stuart >>> >> I am familiar with an ajax request (xmlhttprequest) and I have a function >> ready to call a script to effect this signoff. I just don't know what to >> put in that php script I'm calling. From what you just wrote I'm guessing >> that my headers as shown previously may be close - I"m confused about your >> mention of "contains an invalid username...". As you can see from my sample >> I don't include such a thing. > > For the last time: YOU DO NOT NEED TO MAKE ANY CHANGES SERVER-SIDE. > > From the Javascript, request any URL that requires authentication - it > doesn't matter. When you make the AJAX request, pass an Authentication header > that contains an invalid username and password. If you don't know what I mean > by that, please google how HTTP Basic Auth works. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic Auth
On 27 Aug 2013, at 15:51, Jim Giner wrote: > On 8/27/2013 10:39 AM, Stuart Dallas wrote: >> On 27 Aug 2013, at 15:18, Jim Giner wrote: >> >>> On 8/27/2013 10:14 AM, Stuart Dallas wrote: >>>> It's not really confusing so long as you understand how PHP works. Each >>>> request is brand new - nothing is retained from previous requests. The two >>>> variable you're changing are set by PHP when the request comes in from the >>>> browser. The fact you changed them in a previous request is irrelevant >>>> because 1) that change was not communicated to the browser in any way, and >>>> 2) PHP doesn't retain any data between requests [1]. >>>> >>>> If you've been coding assuming that changes you make to global variables >>>> are retained between requests you must have been having some pretty >>>> frustrating times! >>>> >>>> -Stuart >>>> >>> Not really - this is the first time I've had something not work as expected. >> That was said with my tongue very much firmly in my cheek, and so is this: >> >> I've been playing with dynamite since I was 4 - hey, it must be a safe, >> proper thing to do! >> >> Just because nothing has blown up in your face yet doesn't mean it won't, >> and I'm concerned that you might not actually see how important it is to >> make sure you're using the tool correctly. >> >> -Stuart >> > This may very well be the first time with this problem because I haven't > tried anything like this before. > > That said - can you give me some pointers on how to do the JS solution? I'm > calling a script that is similar to the one I used to signon. It sends out > something like: > >header("WWW-Authenticate: Basic realm=$realm"); >header('HTTP/1.0 401 Unauthorized'); >echo "You have entered invalid credentials"; >echo "Click here to return to the menu."; >exit(); > > when it doesn't detect the PHP_AUTH_USER or it is an invalid value. > > So - to effect a signoff, what does one do? You said to use an invalid > value, but what do I do with that? How do I ignore the 401? Now I'm > getting the signin dialog and I'm stuck. You don't need to do anything on the server-side. You simply need a JS function that sends a request to a URL that requires basic auth, with an Authenticate header that contains an invalid username and password. Then, when your server responds with a 401 Authentication required (which it should already do for an invalid request) you can set location.href to whatever URL you want the logged out user to see. If you don't know how to make a request from Javascript -- commonly known as an AJAX request -- then google for it. I'd recommend the jquery library if you want a very easy way to do it. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic Auth
On 27 Aug 2013, at 15:18, Jim Giner wrote: > On 8/27/2013 10:14 AM, Stuart Dallas wrote: >> It's not really confusing so long as you understand how PHP works. Each >> request is brand new - nothing is retained from previous requests. The two >> variable you're changing are set by PHP when the request comes in from the >> browser. The fact you changed them in a previous request is irrelevant >> because 1) that change was not communicated to the browser in any way, and >> 2) PHP doesn't retain any data between requests [1]. >> >> If you've been coding assuming that changes you make to global variables are >> retained between requests you must have been having some pretty frustrating >> times! >> >> -Stuart >> > > Not really - this is the first time I've had something not work as expected. That was said with my tongue very much firmly in my cheek, and so is this: I've been playing with dynamite since I was 4 - hey, it must be a safe, proper thing to do! Just because nothing has blown up in your face yet doesn't mean it won't, and I'm concerned that you might not actually see how important it is to make sure you're using the tool correctly. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic Auth
On 27 Aug 2013, at 15:06, Jim Giner wrote: > > On 8/27/2013 9:46 AM, Stuart Dallas wrote: >> On 27 Aug 2013, at 14:37, Jim Giner wrote: >> >>> I"m using basic auth for a few of my pages that I want to limit access to - >>> nothing of a sensitive nature, but simply want to limit access to. Want to >>> implement a signoff process, but can't figure it out. >>> >>> From the comments in the manual I take it one can't do this by simply >>> unsetting the PHP_AUTH_USER and _PW vars. Can someone explain to me why >>> this doesn't suffice? The signon process expects them to be there, so when >>> they are not (after the 'unset'), how come my signon process still detects >>> them and their values? >> >> The global variables you're referring to are just that, global variables; >> changing them will have no effect on the browser. Basic Auth was not >> designed to allow users to log out, but you can make it happen with some >> Javascript. >> >> Have your log out link call a Javascript function which sends an >> XMLHttpRequest with an invalid username and password. The server will return >> a 401 which you ignore and then take the user to whatever URL you want them >> to see after they log off. Not pretty, but it works. >> >> -Stuart >> > Thanks for the timely response! > > Before I try your suggestion - one question. Since when is a global variable > not changeable? Doesn't the fact that it reflects a modified value when I do > change it tell me it worked? I change the value to 'xxx' and show it having > that value, but when the script is called again the old value appears. Very > confusing! I didn't say you couldn't change it, I said doing so will have no effect on the browser. It's not really confusing so long as you understand how PHP works. Each request is brand new - nothing is retained from previous requests. The two variable you're changing are set by PHP when the request comes in from the browser. The fact you changed them in a previous request is irrelevant because 1) that change was not communicated to the browser in any way, and 2) PHP doesn't retain any data between requests [1]. If you've been coding assuming that changes you make to global variables are retained between requests you must have been having some pretty frustrating times! -Stuart [1] The one exception to this is $_SESSION, but it's important to know how that works. The $_SESSION array is populated when you call session_start(). It's loaded from some form of storage (files by default) and unserialised in to $_SESSION. When the session is closed, either implicitly by the request ending or by a call to one of the methods that explicitly do it, the contents are serialised to the storage system. Once closed, any changes to $_SESSION will not be stored; it becomes just another superglobal (not that it was ever anything else). -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic Auth
On 27 Aug 2013, at 14:37, Jim Giner wrote: > I"m using basic auth for a few of my pages that I want to limit access to - > nothing of a sensitive nature, but simply want to limit access to. Want to > implement a signoff process, but can't figure it out. > > From the comments in the manual I take it one can't do this by simply > unsetting the PHP_AUTH_USER and _PW vars. Can someone explain to me why this > doesn't suffice? The signon process expects them to be there, so when they > are not (after the 'unset'), how come my signon process still detects them > and their values? The global variables you're referring to are just that, global variables; changing them will have no effect on the browser. Basic Auth was not designed to allow users to log out, but you can make it happen with some Javascript. Have your log out link call a Javascript function which sends an XMLHttpRequest with an invalid username and password. The server will return a 401 which you ignore and then take the user to whatever URL you want them to see after they log off. Not pretty, but it works. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP vs JAVA
On 21 Aug 2013, at 15:01, "georg chambert" wrote: > my I shake the subject a little; Ive been doing some PHP and found it "ok" to > work with > not so much fuss, but that was PHP4, what about PHP5 ? > Dont really checked the difference but made a short-scan and found that it > had be > screwed around with ? > > Any think, should I change to 5 ? Yes, even if it's only because PHP4 hasn't been supported in any way, including security fixes, since August 7th, 2008! This fact alone makes it pretty dangerous to be using it on a public site, and that's without getting into all of the improvements that PHP5 has introduced over the past five years! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP vs JAVA
On 20 Aug 2013, at 22:00, Ashley Sheridan wrote: > On Tue, 2013-08-20 at 21:44 +0100, Stuart Dallas wrote: >> On 20 Aug 2013, at 21:30, Dan Munro > > wrote: >> >> >> in my opinion, that would be like asking "how big is the internet?". >> > >> > >> http://www.washingtonpost.com/blogs/the-switch/wp/2013/08/18/heres-what-you-find-when-you-scan-the-entire-internet-in-an-hour/ >> >> >> That's scanning IP addresses and doesn't come close to answering "how big is >> the internet," assuming that means how many sites are there rather than how >> many publicly responsive edge servers exist. >> > I'd argue that a large proportion of really secure servers out there won't > respond to a lot of what Zmap pings out. Nmap works by throwing out requests > on a bunch of different ports, not just ping, which is slow, so I'd be > surprised if Zmap could really rival that while giving the same results. > Bearing in mind there are over 4,000 million (I won't say billion, because > that's a million million, despite what the Americans say!) IPv4 address out > there, 40 minutes is a ridiculous amount of time to even scan half of that, > especially given the fact that IPv6 is being majorly pushed because IPv4 is > apparently running out of free address space! Then not forgetting that lots > of websites exist on the same IP address/range, I would say the article is > lacking on so many details as to be untrue. I wouldn't go so far as to say it's untrue, but it's certainly written with exaggerated implications. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP vs JAVA
On 20 Aug 2013, at 21:30, Dan Munro wrote: >> in my opinion, that would be like asking "how big is the internet?". > > http://www.washingtonpost.com/blogs/the-switch/wp/2013/08/18/heres-what-you-find-when-you-scan-the-entire-internet-in-an-hour/ That's scanning IP addresses and doesn't come close to answering "how big is the internet," assuming that means how many sites are there rather than how many publicly responsive edge servers exist. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP vs JAVA
On 20 Aug 2013, at 21:08, Sebastian Krebs wrote: > 2013/8/20 Steven Staples > >>> My recent question was simply an attempt to get documentation to support >>> which server-side Web Language is the most popular. Both PHP and Java can >>> be used server-side. >>> >>> I also realize that Java is used for native Android because I also teach >>> Mobile Application Development (MAD -- I even coined the name). So, I am >> up >>> to my butt in languages (and people who think different than me) -- I'm >>> just trying to get documentation to back up my what I think I know. >> >> Well, technically any language can be used server side, it is all on how >> you >> set up your server, no? >> > > No. But since node.js I lack an example :D But of course you need the > "link" between the language and the network. The language and the '"link" between the language and the network' are two completely separate things. The "link," as you put it, is the web server. A web server doesn't need to do anything more than set up environment variables and run an executable, and even setting up the environment is technically optional. BASH can build web pages. I wouldn't recommend using BASH, but there's nothing technically preventing it. Node.js is not the only way to run Javascript outside a browser, and other ways of doing so existed long before Node.js arrived. Most limitations people put on technology are artificial constructions rather than real constraints. tedd: I wouldn't trust any stats you might find since, as has been pointed out, it's incredibly difficult to accurately measure. I'd be careful with the word "popular" because it really depends on what you're measuring. If you're talking public websites then I'd agree that, anecdotally at least, PHP is more common than any other server-side language. If you're talking about public site visitors or page views it's definitely the most popular, but that's massively skewed by Facebook if you accept that their way of using PHP can still be called PHP. Enterprise usage of PHP is far lower, mainly due to Microsoft's dominance, but I get the feeling this is changing, albeit incredibly slowly. If he means Java is the most popular as in "developers would prefer to use it" then I'd definitely disagree, but I wouldn't necessarily say that PHP is at the top of that list either. Ultimately I'd want to know what he's trying to prove by saying that. If he's purely engaging in a "mine's bigger than yours" discussion I'd walk away, leave him to his petty games and actually accomplish something with the time instead. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can I submit more than 2000 items of data?
On 19 Aug 2013, at 16:24, Matijn Woudt wrote: > On Mon, Aug 19, 2013 at 5:20 PM, Stuart Dallas wrote: > On 19 Aug 2013, at 15:56, Matijn Woudt wrote: > >> >> On Mon, Aug 19, 2013 at 11:54 AM, Stuart Dallas wrote: >> On 19 Aug 2013, at 10:49, aesbovis wrote: >> >> > I know Javascript can solve it, but I don't want to use Js. >> > Thank you all the same. >> >> I know you've had the right answer, but I think it's worth pointing out that >> use of JSON in no way requires Javascript, despite its name. >> >> -Stuart >> >> >> You might want to explain how you convert form data to JSON without >> javascript? > > PHP can do it. Ruby can do it. .NET can do it. Just because you want to use > JSON in a web browser where Javascript is the go-to method, doesn't mean JSON > requires Javascript. > > -Stuart > > > > Yes, of course they can do it, but then you first need to submit the POST > data (which he could not do because of the above). Javascript is more or less > the only way to do it (yes I know Flash….) I wasn't speaking to his specific issue as that was solved by an earlier response. I was just commenting that the implied intrinsic link between JSON and Javascript in what he had said does not exist. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] How can I submit more than 2000 items of data?
On 19 Aug 2013, at 15:56, Matijn Woudt wrote: > > On Mon, Aug 19, 2013 at 11:54 AM, Stuart Dallas wrote: > On 19 Aug 2013, at 10:49, aesbovis wrote: > > > I know Javascript can solve it, but I don't want to use Js. > > Thank you all the same. > > I know you've had the right answer, but I think it's worth pointing out that > use of JSON in no way requires Javascript, despite its name. > > -Stuart > > > You might want to explain how you convert form data to JSON without > javascript? PHP can do it. Ruby can do it. .NET can do it. Just because you want to use JSON in a web browser where Javascript is the go-to method, doesn't mean JSON requires Javascript. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] How can I submit more than 2000 items of data?
On 19 Aug 2013, at 10:49, aesbovis wrote: > I know Javascript can solve it, but I don't want to use Js. > Thank you all the same. I know you've had the right answer, but I think it's worth pointing out that use of JSON in no way requires Javascript, despite its name. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Mon, Aug 19, 2013 at 4:32 PM, Szopen Xiao wrote: > >> you can use JSON post >> >> 2013/8/19 aesbovis : >>> Hello there >>> I am making a little web-based-tool for our studio to progress a large >>> amount of data, more than 2000 items, but it seems there is a length >> limit >>> of 1000 to $_POST. >>> >>> How can I submit all of the items in one time? >>> >>> Thank you! >>> aesbovis >>> >>> -- >>> *Anywhere @aesbovis!* >> > > > > -- > *Anywhere @aesbovis!* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session_unset - session_destroy issue
On 15 Aug 2013, at 19:16, dealTek wrote: > Hi all, > > I am having trouble with session_destroy - session_unset and $_SESSION = > array()... I am trying to STOP and destroy all session vars.. > > > with the simple code test below I would think it would echo test 1 BUT FAIL > on test2 > - however it shows both for me... > > how do I UNSET - DESTROY SESSIONS? > > > > > session_start(); > > $_SESSION['var1'] = 'test1'; > echo ' test1 '. $_SESSION['var1'].' '; > > session_unset(); > session_destroy(); > $_SESSION = array(); > > > $_SESSION['var1'] = 'test2'; > > echo ' test2 ' . $_SESSION['var1']; > > > > ?> The $_SESSION superglobal variable is nothing more than that. Calling session_start will populate it with an existing session, and when the request ends the contents will be stored. Once you've closed or destroyed the session it does not stop working because it's nothing more than a superglobal variable, it just won't be stored at the end of the request. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ambiguous?
On 9 Aug 2013, at 13:00, Karl-Arne Gjersøyen wrote: > 1) query > foreach($varenr_inn_pa_lager as $vnr){ >include('../../tilkobling.php'); >$sql = "SELECT * FROM exan,dynamit WHERE varenr = '$vnr' LIMIT > 1"; >$resultat = mysql_query($sql, $tilkobling) or > die(mysql_error()); > > 2) Result: > Column 'varenr' in where clause is ambiguous > > 3) Tables in MySQL database > > mysql> SELECT * FROM exan; > ++-+---+--+--+-+ > | leverandor | valgt_lager | un_nr | varenavn | varenr | kg_pa_lager | > ++-+---+--+--+-+ > > mysql> SELECT * FROM dynamit; > ++-+---++---+-++-+ > | leverandor | valgt_lager | type | dim_mm | un_nr | > varenavn| varenr | kg_pa_lager | > ++-+---++---+-++-+ > > 4) My question: > What means with "ambiguous" here? The field exists in both tables, so you need to specify which one you mean. Please learn how to use Google, it knows the answer to almost everything! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class Auto-Assigning to Variable
On 7 Aug 2013, at 20:45, "Brian Smither" wrote: >> I cannot replicate this. > > I don't expect anyone to be able to replicate this behavior. The example > shows an extraordinarily stripped-down sequence of statements that informs > what should work, but do to some unknown agent, which, therefore, cannot be > included in the example, produces unexpected output. > > This conceptual example is not a 'sample' or 'excerpt' of the actual > application. There is much, much more code. None of it is an apparent likely > suspect in causing this behavior. > > I am hoping for a, "Oh, yeah! I've seen that happen before. It's caused by..." > > Let us focus on the central question: > > Would there be a PHP function that would do [what the example describes] as a > side-effect? Yes: $hello = $clsHello; There are only a few variables that get assigned as side effects of functions, but they have very specific names, and none of them are $hello (but I'm guessing that's not the actual variable name) and none of them will assign a userland object. Somewhere in your code there is something that is assigning to $hello. Find everything that's doing that and look at each instance in detail. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to see all sessions sets in server
On 4 Aug 2013, at 14:36, Farzan Dalaee wrote: > I need to inspect each visitor to show how online or who offline for chat > Like facebook chat PHP sessions is a really bad mechanism to use to accomplish this. In the past I've used memcached or redis for presence indicators. Both allow you to set keys that expire after a set period. The problem with this is that a user can appear to be online for up to "set period" seconds longer than they actually are. In the system I'm currently building I've got a node.js daemon to which the browser connects. That daemon exposes an API that the rest of the system can call to get lists of online users, which is easily gathered since it's just the list of connected users. There is then no delay between the browser closing the connection and the daemon deciding that user is no longer online. If you have a chat system I'm curious as to how it works, since presence is usually tied closely to how the client is detecting new messages. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Foreach and mydql_query problem
On 22 Jul 2013, at 13:25, Karl-Arne Gjersøyen wrote: > 2013/7/22 Stuart Dallas > On 22 Jul 2013, at 12:56, Karl-Arne Gjersøyen wrote: > > > 2013/7/22 Stuart Dallas > > > >> > >> On 22 Jul 2013, at 08:04, Tamara Temple wrote: > >> > >>> On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen > >> wrote: > >>> > >>>> Hello again. > >>>> I have this this source code that not work as I want... > >>>> > >>>> THe PHP/HTHML form fields is generated by a while loop and looks like > >> this: > >>>> > >>>> " required="required"> > >>>> > >>>> > >>>> the php source code look like this: > >>>> >>>> if(!empty($_POST['number_of_itemsi'])){ > >>>> include('../../connect.php'); > >>>> > >>>> foreach($number_of_items as $itemi){ > >>>> echo "$itemi"; > >>>> > >>>> $sql = "UPDATE item_table SET number_item = '$item' WHERE date > >>>> = '$todays_date' AND sign = '$username'"; > >>>> mysql_query($sql,$connect) or die(mysql_error()); > >>>> } > >>>> } > >>>> > >>>> ?> > >>>> > >>>> The problem is: > >>>> Foreach list every items as expected in PHP doc and I thought that $sql > >> and > >>>> mysql_query should be run five times when I have five items. > >>>> But the problem is that only the very last number_of_items is written > >> when > >>>> update the form.. > >>>> I believe this is becayse number_of_items = '$item in $sqk override > >> every > >>>> earlier result. > >>>> > >>>> So my querstion is. How to to update the database in this case? > >>>> > >>>> Thanks again for your good advice and time to help me. > >>>> > >>>> Karl' > >>> > >>> Either the code you posted isn't the actual code, or if it is, the > >> errors should be rather obvious. Post *actual* code. > >> > >> The error is rather obvious: it loops around an array running an update > >> statement that will modify a single row in the table, so it's not > >> surprising that it appears like only the last entry in the array has been > >> stored. > >> > >> Yes, i know that only one a singe row is updated and that is the problem. > > What can I do to update several rows at the same time? > > Thank you very much for all your good advice. > > Are you sure you want to update several rows, or do you actually want to > insert several rows? > > This is pretty basic database stuff, and is off-topic for this list. > > > OK. Sorry. I thought it was a PHP question for a way to update several mysql > rows by PHP code. If you want to UPDATE several rows then you must have unique identifiers for those rows. If you don't then I'm guessing what you actually want to do is INSERT those rows. It's off-topic in the same way as asking a mechanic how to fit a bunch of stuff in your car. It's the MySQL part that you're having a problem with, not the PHP. I strongly recommend that you use the MySQL command line to run the queries you think you need to run, checking what the table looks like after each one. Once you know what queries you need to run you will more effectively be able to write the PHP wrapper around those queries. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Foreach and mydql_query problem
On 22 Jul 2013, at 12:56, Karl-Arne Gjersøyen wrote: > 2013/7/22 Stuart Dallas > >> >> On 22 Jul 2013, at 08:04, Tamara Temple wrote: >> >>> On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen >> wrote: >>> >>>> Hello again. >>>> I have this this source code that not work as I want... >>>> >>>> THe PHP/HTHML form fields is generated by a while loop and looks like >> this: >>>> >>>> " required="required"> >>>> >>>> >>>> the php source code look like this: >>>> >>> if(!empty($_POST['number_of_itemsi'])){ >>>> include('../../connect.php'); >>>> >>>> foreach($number_of_items as $itemi){ >>>> echo "$itemi"; >>>> >>>> $sql = "UPDATE item_table SET number_item = '$item' WHERE date >>>> = '$todays_date' AND sign = '$username'"; >>>> mysql_query($sql,$connect) or die(mysql_error()); >>>> } >>>> } >>>> >>>> ?> >>>> >>>> The problem is: >>>> Foreach list every items as expected in PHP doc and I thought that $sql >> and >>>> mysql_query should be run five times when I have five items. >>>> But the problem is that only the very last number_of_items is written >> when >>>> update the form.. >>>> I believe this is becayse number_of_items = '$item in $sqk override >> every >>>> earlier result. >>>> >>>> So my querstion is. How to to update the database in this case? >>>> >>>> Thanks again for your good advice and time to help me. >>>> >>>> Karl' >>> >>> Either the code you posted isn't the actual code, or if it is, the >> errors should be rather obvious. Post *actual* code. >> >> The error is rather obvious: it loops around an array running an update >> statement that will modify a single row in the table, so it's not >> surprising that it appears like only the last entry in the array has been >> stored. >> >> Yes, i know that only one a singe row is updated and that is the problem. > What can I do to update several rows at the same time? > Thank you very much for all your good advice. Are you sure you want to update several rows, or do you actually want to insert several rows? This is pretty basic database stuff, and is off-topic for this list. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Foreach and mydql_query problem
On 22 Jul 2013, at 08:04, Tamara Temple wrote: > On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen wrote: > >> Hello again. >> I have this this source code that not work as I want... >> >> THe PHP/HTHML form fields is generated by a while loop and looks like this: >> >> " required="required"> >> >> >> the php source code look like this: >> > if(!empty($_POST['number_of_itemsi'])){ >> include('../../connect.php'); >> >> foreach($number_of_items as $itemi){ >> echo "$itemi"; >> >> $sql = "UPDATE item_table SET number_item = '$item' WHERE date >> = '$todays_date' AND sign = '$username'"; >> mysql_query($sql,$connect) or die(mysql_error()); >>} >> } >> >> ?> >> >> The problem is: >> Foreach list every items as expected in PHP doc and I thought that $sql and >> mysql_query should be run five times when I have five items. >> But the problem is that only the very last number_of_items is written when >> update the form.. >> I believe this is becayse number_of_items = '$item in $sqk override every >> earlier result. >> >> So my querstion is. How to to update the database in this case? >> >> Thanks again for your good advice and time to help me. >> >> Karl' > > Either the code you posted isn't the actual code, or if it is, the errors > should be rather obvious. Post *actual* code. The error is rather obvious: it loops around an array running an update statement that will modify a single row in the table, so it's not surprising that it appears like only the last entry in the array has been stored. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can this work?
On 5 Jul 2013, at 15:24, Karl-Arne Gjersøyen wrote: > 2013/7/5 Stuart Dallas > >> On 5 Jul 2013, at 15:05, Karl-Arne Gjersøyen wrote: >> >>> 2013/7/5 Stuart Dallas >>> >>>> On 5 Jul 2013, at 14:56, Karl-Arne Gjersøyen >> wrote: >>>> >>>>> Hello. I have a form in HTML/PHP with for loops that generate a >> selected >>>>> list like this: >>>>> for($i = 1; $i< 25;$i++ ){ >>>>> >>>>> } >>>>> >>>>> The lists look like this: >>>>> >>>>> http://localhost/%7Ekarl/kasen/io/kp/index.php>" >>>>> method="post">>>>> value="1-25" selected="selected">1-25>>>> value="1">12>>>> value="3">34>>>> value="5">56>>>> value="7">78>>>> value="9">910>>>> value="11">1112>>>> value="13">1314>>>> value="15">1516>>>> value="17">1718>>>> value="19">1920>>>> value="21">2122>>>> value="23">2324>>>> value="25">25 Kg >>>> name="valgt_dynamit_polse_26-50kg">>>>> selected="selected">26-50>>>> value="26">2627>>>> value="28">2829>>>> value="30">3031>>>> value="32">3233>>>> value="34">3435>>>> value="36">3637>>>> value="38">3839>>>> value="40">4041>>>> value="42">4243>>>> value="44">4445>>>> value="46">4647>>>> value="48">4849>>>> value="50">50 Kg >>>>> >>>>> What I try to do with it is to register the selected value and do >>>> something >>>>> with it. The lists is weight in KG. I hope to select only one value >>>> between >>>>> 1-25kg OR 26-50kg. I don't know if this is possible? What do you think? >>>> >>>> If the range of acceptable values is 1-50, why do you have two select >>>> fields instead of one? >>> >>> The select list has values between 1 and 200. Therefore I split it up for >>> every 25th value. >> >> Ok, but why? > > > I will use my application on iPad and find it more easy to use multiple > select lists than one big list with all 200 values at once. In that case I would recommend using a text input field and validate it with javascript and then validate it again on the server-side with PHP. With multiple select fields the only way you'll know which one the user (i.e. you) meant is by resetting the others to an empty value whenever one of them changes. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can this work?
On 5 Jul 2013, at 15:05, Karl-Arne Gjersøyen wrote: > 2013/7/5 Stuart Dallas > >> On 5 Jul 2013, at 14:56, Karl-Arne Gjersøyen wrote: >> >>> Hello. I have a form in HTML/PHP with for loops that generate a selected >>> list like this: >>> for($i = 1; $i< 25;$i++ ){ >>> >>> } >>> >>> The lists look like this: >>> >>> http://localhost/%7Ekarl/kasen/io/kp/index.php>" >>> method="post">>> value="1-25" selected="selected">1-25>> value="1">12>> value="3">34>> value="5">56>> value="7">78>> value="9">910>> value="11">1112>> value="13">1314>> value="15">1516>> value="17">1718>> value="19">1920>> value="21">2122>> value="23">2324>> value="25">25 Kg >> name="valgt_dynamit_polse_26-50kg">>> selected="selected">26-50>> value="26">2627>> value="28">2829>> value="30">3031>> value="32">3233>> value="34">3435>> value="36">3637>> value="38">3839>> value="40">4041>> value="42">4243>> value="44">4445>> value="46">4647>> value="48">4849>> value="50">50 Kg >>> >>> What I try to do with it is to register the selected value and do >> something >>> with it. The lists is weight in KG. I hope to select only one value >> between >>> 1-25kg OR 26-50kg. I don't know if this is possible? What do you think? >> >> If the range of acceptable values is 1-50, why do you have two select >> fields instead of one? > > The select list has values between 1 and 200. Therefore I split it up for > every 25th value. Ok, but why? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can this work?
On 5 Jul 2013, at 14:56, Karl-Arne Gjersøyen wrote: > Hello. I have a form in HTML/PHP with for loops that generate a selected > list like this: > for($i = 1; $i< 25;$i++ ){ > > } > > The lists look like this: > > http://localhost/%7Ekarl/kasen/io/kp/index.php>" > method="post"> value="1-25" selected="selected">1-25 value="1">12 value="3">34 value="5">56 value="7">78 value="9">910 value="11">1112 value="13">1314 value="15">1516 value="17">1718 value="19">1920 value="21">2122 value="23">2324 value="25">25 Kg name="valgt_dynamit_polse_26-50kg"> selected="selected">26-50 value="26">2627 value="28">2829 value="30">3031 value="32">3233 value="34">3435 value="36">3637 value="38">3839 value="40">4041 value="42">4243 value="44">4445 value="46">4647 value="48">4849 value="50">50 Kg > > What I try to do with it is to register the selected value and do something > with it. The lists is weight in KG. I hope to select only one value between > 1-25kg OR 26-50kg. I don't know if this is possible? What do you think? If the range of acceptable values is 1-50, why do you have two select fields instead of one? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Last Record INSERT
On Wednesday, 26 June 2013 at 19:01, Tedd Sperling wrote: > On Jun 26, 2013, at 1:56 PM, Stuart Dallas (mailto:stu...@3ft9.com)> wrote: > > On Wednesday, 26 June 2013 at 18:39, Tedd Sperling wrote: > > > Let me add, currently I am inserting an email address into a database. > > > > > > To find which record was created, I ask for the record number (ID) back. > > > > > > I am asking simply because mysql_insert_id() is deprecated. > > Now you tell me. :-) > The whole mysql module has been deprecated. The recommended module is now either mysqli or PDO depending on your requirements. Moving to mysqli from mysql will probably be the less painful route. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Last Record INSERT
On Wednesday, 26 June 2013 at 18:39, Tedd Sperling wrote: > Let me add, currently I am inserting an email address into a database. > > To find which record was created, I ask for the record number (ID) back. > > I am asking simply because mysql_insert_id() is deprecated. > How are you doing the insert? If you're inserting with mysql_query() then that's just as deprecated as mysql_insert_id(). -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reseting the auto-increment number in a MySQL database.
On Wednesday, 26 June 2013 at 18:07, Tedd Sperling wrote: > Hi gang: > > I have a client where their next auto-increment number just jumped from 2300 > to 10 for reasons not understood. They want it set back. > > Options such as dropping the primary key and rebuilding the index is NOT > possible -- this is a relational table thing. > > So, is there a way (programmatically) to set the next number in an > auto-increment? > > Something like: > > alter table abc auto_increment = 2301; > ALTER TABLE tbl AUTO_INCREMENT = 2301; -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fwd: Is it possible???
On 24 Jun 2013, at 13:02, Karl-Arne Gjersøyen wrote: > Error in my last post This is corrected: > > $item_amount_in_store = 223; > $update_amount = 7; > $item_amount_in_Store += $update_amount; > > It show the result = 227 and not 230. Why is this happen? Something else is going on to give you 227, but variable names are case sensitive which is why you're not getting what you expect. Output: int(223) int(7) -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > -- Forwarded message -- > From: Karl-Arne Gjersøyen > Date: 2013/6/24 > Subject: Is it possible??? > To: PHP Mailinglist > > > $item_amount_in_store = 223; > $update_amount = 7; > $update_item_amount_in_store += $update_amount; > $update_amoint_in_store is now 227; > > Why? That should be 230! > > Karl > > > > -- > Hjemmeside: http://www.karl-arne.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible???
On 24 Jun 2013, at 12:59, Karl-Arne Gjersøyen wrote: > $item_amount_in_store = 223; > $update_amount = 7; > $update_item_amount_in_store += $update_amount; > $update_amoint_in_store is now 227; > > Why? That should be 230! Because you're using $item_amount_in_store and $update_item_amount_in_store as if PHP should know you mean the same thing. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A Strange Problem
On 20 Jun 2013, at 18:39, Tedd Sperling wrote: > Hi gang: > > I have a very strange problem. > > I can use this statement in one folder: > > $fcontents = file('docs/admin-email.txt'); > > But in a different folder with an exact path having 'docs/admin-email.txt', I > get: > > Warning: file(/docs/admin-email.txt) [function.file]: failed to open stream: > No such file or directory in on line 83 > > This has got me really puzzled. > > I have confirmed these are the exact same folders and files, except only in > two different places on the server. Both are one level down from root. > > Any ideas as to what is going on? > > Cheers, > > tedd Whatever the reason for this, I'd recommend you always specify a path relative to the current script. In PHP 5.3+: $fcontents = file(__DIR__.'/docs/admin-email.txt'); Prior to 5.3: $fcontents = file(dirname(__FILE__).'/docs/admin-email.txt'); -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP is Zero
On 13 Jun 2013, at 12:27, BUSCHKE Daniel wrote: > Hi, > >> It gives up when it finds a non-numeric character (as the documentation >> would tell you) > > Why is PHP doing that? I know it works as designed and I know it is > documented like this but that does not mean that it is a good feature, does > it? So lets talk about the question: Is that behaviour awaited by PHP > software developers? Is that really the way PHP should work here? May we > should change that?! > > BTW: I talked to some collegues and friends since my first post. They all > guessed that "'PHP' == 0" is false within a few seconds. I think the > weak-typed-PHP is a little to weak at this point. I don't know what the actual reasoning is; if you want that I suggest you ask on the internals list, but be careful how you phrase the question. If it's pure curiosity then that's fine, but whether you agree with the reasoning or not it's gone way past the point where it can be changed. My take it that the behaviour is perfectly reasonable. When you compare two different types it has to convert one of them. If you're comparing a string to a number it seems logical to me that the number should be the preferred type, so the string gets converted. What would you expect array(5) == 5 to give you? Would you expect the 5 to be converted in to an array? No. The reason it looks odd for "PHP" == 0 is that there's no reason why the 0 should not be converted to "0", except that strings and numbers are not the only types available and there has to be an order of precedence. And consistency is key. As for how strings get converted to numbers I have no idea why it will take everything up to the first non-e|E|. character. The documentation[1] simply states the behaviour and doesn't go in to why. However, I have to ask why it matters? Why would you want to convert '8315e839da08e2a7afe6dd12ec58245d' to an integer? If you have code that's juggling it automatically, be more explicit. It's fine to be interested in the reasons why it does what it does, but if it's causing you problems then the issue is with your code not being explicit enough, not PHP. -Stuart [1] http://php.net/language.types.string#language.types.string.conversion -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] htaccess to make html act as php suffixed files
On 11 Jun 2013, at 18:16, Tedd Sperling wrote: > Hi gang: > > To get html pages to use php scripts, I've used: > > RewriteEngine on > # handler for phpsuexec. -- this makes these prefixes considered for php > > SetHandler application/x-httpd-php > > > In a .htaccess file. > > However, it works on one site, but not on another -- any ideas as to why? At a rough guess there's an AllowOverride line in the main Apache config that's restricting what you can do in the .htaccess file. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Has this always been the case?
On 31 May 2013, at 12:22, Richard Quadling wrote: > On 31 May 2013 12:17, shiplu wrote: > >> On Fri, May 31, 2013 at 5:12 PM, Stuart Dallas wrote: >>> That is not entirely correct. It must be a literal value. The expression >>> 'a'.'b' is a constant value. >>> I may be being overly picky here, but I think it's an important distinction. >> >> I thought 'a'. 'b' is a constant expression and 'ab' is a constant value. >> Correct me if I am wrong. >> > Literals only is OK. Was/is there plans to allow constant expressions? I believe it's been discussed a few times but I think it's highly unlikely due to the way the engine works. As I said in my reply to shiplu, class constants and member variables are defined not evaluated, so making expressions possible is a fairly major modification for, what I see as fairly minimal benefit. There's definitely an argument to be made that a class definition should not contain anything that needs to be evaluated. I certainly see it as breaking the basics of object oriented design. > It just made me wonder if I was doing something wrong. Technically you were, but nobody died so it's ok :) -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Has this always been the case?
On 31 May 2013, at 12:17, shiplu wrote: > On Fri, May 31, 2013 at 5:12 PM, Stuart Dallas wrote: >> That is not entirely correct. It must be a literal value. The expression >> 'a'.'b' is a constant value. >> I may be being overly picky here, but I think it's an important distinction. >> > > I thought 'a'. 'b' is a constant expression and 'ab' is a constant value. > Correct me if I am wrong. You're correct that 'a'.'b' is a constant expression, but I wouldn't call 'ab' a constant value, it's a literal [1]. While "constant value" makes logical sense there is a long history of agreed terminology for these things and you will find that using it will enable smoother communication with fellow developers. Initial values of class constants and member variables must be literals as they are defined not evaluated. -Stuart [1] http://en.wikipedia.org/wiki/Literal_(computer_programming) -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Has this always been the case?
On 31 May 2013, at 12:08, shiplu wrote: > The property initializer in PHP can not have any expression. It should be > constant value. That is not entirely correct. It must be a literal value. The expression 'a'.'b' is a constant value. I may be being overly picky here, but I think it's an important distinction. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Has this always been the case?
On 31 May 2013, at 11:57, Richard Quadling wrote: > Hi. > > Both > > class Oddity{ > public $var = 'a' . 'b'; > } > ?> > > and > > class Oddity{ > const A_VAR = 'a' . 'b'; > } > ?> > > produce ... > > PHP Parse error: syntax error, unexpected '.', expecting ',' or ';' in - > on line 3 > > For properties, has this always been the case? > > Admittedly, this is the first time I've ever written code to assign a > concatenated string to a static property ... > >static protected $s_NormaliserScript = __DIR__ . '/normalizedError.php'; > > And I was just surprised. > > That's all. Yes, it has. Initial values class constants and member variables must be literal values. If you need to do that use a constructor. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REQUEST
On 29 May 2013, at 18:16, Jim Giner wrote: > On 5/29/2013 12:51 PM, Stuart Dallas wrote: >> Please find your caps-lock key and turn it off! >> >> Also, please include the list when replying, or expect an invoice for my >> consulting services. >> >> On 29 May 2013, at 17:36, Last Hacker Always onpoint >> wrote: >> >>> A SIMPLE MACHINE FUNCTION, IS A FORUM SITE SCRIPT FROM THE SIMPLE MACHINE >>> COMPANY BUT UNLIKE OTHER SCRIPTS IT HAS A DIFFERENT TYPE OF SCRIPTING. >> >> If you're having issues with forum software supplied by a company, please >> contact that company. >> >>> AM STILL LEARNING PHP THOUGH BUT ASK ME A QUESTION SO I CAN PROVE MYSELF >>> WORDY. COZ YOU SEEM TO SEE ME NOT WORDY >> >> At a rough guess you mean worthy, not wordy. Worthy of what? You have >> nothing to prove to me other than the ability to make sense and ask a >> question that can be answered without four tonnes of interpretation. >> >> -Stuart >> > Frankly I am a little reluctant to respond to someone who names himself > "hacker". Makes me worry about what they think they are doing. If the > person hasn't learned enough php yet to be dangerous, why would I want to > help him? Anyone who calls themselves a hacker in a public place such as this does so with absolutely no clue what they're talking about, and that's without getting in to the hacker vs. cracker debate. However, regardless of that I tend not to judge people by the labels they give themselves, they're rarely accurate, especially when they think they're the last and/or best of their kind! [On which note it has to be said he clearly isn't since he couldn't get lasthacker@ and had to settle for lasthacker1@. Just sayin'.] -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REQUEST
On 29 May 2013, at 17:26, Last Hacker Always onpoint wrote: > HEY GUYZ I KNOW, I KNOW THIS IS NOT A PLACE FOR SOMETHING LIKE THIS SO BUT > HEY I HAVE A LITTLE TINY QUESTION FOR MY COOL GUYZ. > > DOES ANYONE HERE USE A SIMPLY MACHINE FUNCTION SCRIPT? BECAUSE THE > SCRIPTINGS ARE A LITTLE HARD FOR ME TO UNDERSTAND PLEASE LET ME KNOW GUYS I > WANT SOMEONE TO TEACH ME. SIMPLE MACHINES FORUM, not SIMPLY MACHINE FUNCTION. Funny how a couple of incorrect words can turn a simple question in to gobbledygook! As for your problems with the product, which I'm guessing are legion, try: http://support.simplemachines.org/ -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REQUEST
Please find your caps-lock key and turn it off! Also, please include the list when replying, or expect an invoice for my consulting services. On 29 May 2013, at 17:36, Last Hacker Always onpoint wrote: > A SIMPLE MACHINE FUNCTION, IS A FORUM SITE SCRIPT FROM THE SIMPLE MACHINE > COMPANY BUT UNLIKE OTHER SCRIPTS IT HAS A DIFFERENT TYPE OF SCRIPTING. If you're having issues with forum software supplied by a company, please contact that company. > AM STILL LEARNING PHP THOUGH BUT ASK ME A QUESTION SO I CAN PROVE MYSELF > WORDY. COZ YOU SEEM TO SEE ME NOT WORDY At a rough guess you mean worthy, not wordy. Worthy of what? You have nothing to prove to me other than the ability to make sense and ask a question that can be answered without four tonnes of interpretation. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Wed, May 29, 2013 at 5:30 PM, Stuart Dallas wrote: > On 29 May 2013, at 17:26, Last Hacker Always onpoint > wrote: > > > HEY GUYZ I KNOW, I KNOW THIS IS NOT A PLACE FOR SOMETHING LIKE THIS SO BUT > > HEY I HAVE A LITTLE TINY QUESTION FOR MY COOL GUYZ. > > > > DOES ANYONE HERE USE A SIMPLY MACHINE FUNCTION SCRIPT? BECAUSE THE > > SCRIPTINGS ARE A LITTLE HARD FOR ME TO UNDERSTAND PLEASE LET ME KNOW GUYS I > > WANT SOMEONE TO TEACH ME. > > 1) Shouting at us will not encourage a helpful attitude. > > 2) Neither will calling us your "cool guyz." > > 3) What is "a simply machine function script?" > > If you want someone to teach you PHP you'll probably need to pony up some > cash. If you want someone to help you while you're learning, show us that > you're working on it and we'll be happy to help. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REQUEST
On 29 May 2013, at 17:26, Last Hacker Always onpoint wrote: > HEY GUYZ I KNOW, I KNOW THIS IS NOT A PLACE FOR SOMETHING LIKE THIS SO BUT > HEY I HAVE A LITTLE TINY QUESTION FOR MY COOL GUYZ. > > DOES ANYONE HERE USE A SIMPLY MACHINE FUNCTION SCRIPT? BECAUSE THE > SCRIPTINGS ARE A LITTLE HARD FOR ME TO UNDERSTAND PLEASE LET ME KNOW GUYS I > WANT SOMEONE TO TEACH ME. 1) Shouting at us will not encourage a helpful attitude. 2) Neither will calling us your "cool guyz." 3) What is "a simply machine function script?" If you want someone to teach you PHP you'll probably need to pony up some cash. If you want someone to help you while you're learning, show us that you're working on it and we'll be happy to help. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
On 23 May 2013, at 21:51, Last Hacker Always onpoint wrote: > Hey I need code for random number 1-30 for my site. Seriously? Did you try to find out how to do this yourself before asking here? http://php.net/rand And, more generally: http://php.net/docs -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple objective which always seems to make me think I'm doing it wrong.
On 23 May 2013, at 15:54, Richard Quadling wrote: > I'm building an XML file. > > It is within an OOP structure and is pretty simple. > > The method is ... > >/** > * Turn an error from the W2GlobalData service into normal document as > this will make it easier to integrate downstream. > * > * @param \SimpleXMLElement $o_XML > * @return \SimpleXMLElement > * @todo Build document to be a correct request header with the > embedded error message. > */ >public function normaliseError($o_XML) >{ >$s_XML = <<< END_XML > > >UK Verification (Edited) > >{$this->a_RequestData['forename']} >{$this->a_RequestData['middlename']} >{$this->a_RequestData['surname']} >{$this->a_RequestData['address1']} >{$this->a_RequestData['address2']} >{$this->a_RequestData['postcode']} >{$this->a_RequestData['gender']} >{$this->a_RequestData['dob']} > > {$this->a_RequestData['drivinglicence']} >{$this->a_RequestData['passport']} >{$this->a_RequestData['mpan']} > > > {$this->a_RequestData['clientreference']} > > > > > > >{$o_XML->error} > > > END_XML; >return new SimpleXMLElement($s_XML); >} > > Nothing particularly difficult to understand, but I just don't like having > the XML embedded this way. > > Ideally, I want a scope aware include function, so I can say _something_ > like ... > > $s_XML = require_once __CLASS__ . DIRECTORY_SEPARATOR . > 'normalisedError.xml'; > > and have the include be aware of the local scope (so $o_XML and $this are > all happy). > > I know I can write a template parser, but I'm just missing an obvious > solution that isn't fat and doesn't require a massive learning for the > other devs. > > Ideas? normalisedError.xml: http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A Good OOP Tutorial/Read?
On 17 May 2013, at 15:04, Tedd Sperling wrote: > Stuart: > > You said: > >> An interface does what it says on the tin: it describes an interface that a >> class can then tell the world it implements. >> >> An abstract class provides functionality as well as an interface >> description. An abstract class cannot be instantiated, it can only be >> extended. >> >> The logging example given by someone earlier in this thread is the most >> common example given for interfaces. This is where the interface is defined >> as an API for others to implement and/or use which then enables users to >> pick and choose the combination of implementations they want to use based on >> their requirements without needing to change any of the code of either class. > > I understand the "stated" differences between abstract and interface. I can > cite what the differences are, but I don't see the practical application > differences. To me there is no difference between an abstract class (without > method declarations) and an interface. That's true, there is no difference if the abstract class has no method declarations. But by the same token, that's the difference. It's a syntactical difference rather than a conceptual difference. > However, I view an interface as a statement (a contract) where IF you want > someone to use your code you outline the methods you require them to > flesh-out in their code -- but I would like to see a simple example of that. That's not what an "interface" is for. I can see how the word is confusing as you can call the API of both an interface and a class (abstract and not) an interface, but in this context the word interface means the thing itself, not an aspect of the thing. An interface is an interface and does nothing more than define the API. An abstract class may also have methods and member variables. > I vaguely get the logging example given by Larry, but I'm not good at > abstract thinking -- I need a concrete simple example. > > I tried to create a demo where I had a Toaster Class that contained > breadNumber() and toastSetting() methods and then created an interface so my > students could use the Toaster, but it didn't really hold up as well as I > wanted. > > So, can anyone give me a simple example where an interface is used so I can > easily explain why they are important? I've knocked up a quick example of the logger use case: https://gist.github.com/3ft9/5599326 Note that if I publish that iLogger interface to others and let them provide implementations against it people can use their logging classes with my user class without any changes. Yes, this could be accomplished by using "abstract class" instead of "interface" but then it's more than just an interface that I'm publishing. If you're looking for a reason why interfaces exist when abstract classes can accomplish the same task you need to talk to someone more academically minded than me. For me, interfaces have their place because they specifically limit what you're getting from a third party to an API definition, rather than it also containing additional code that should be audited before being used in your software. Your toaster example would work, but I think you need to switch from the large object to a smaller aspect for it to make sense. Rather than being able to replace the whole toaster from their code, imagine if they wanted to replace a module within the toaster that determines the pattern to be burnt on to the bread. The Toaster class could optionally take an object that implements iToasterPattern which the students could supply to change the pattern burnt. To enable them to use that you would provide them with the API to the Toaster object so they can talk to it, and the iToasterPattern interface so they can provide their own implementation of iToasterPattern. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A Good OOP Tutorial/Read?
On 17 May 2013, at 14:04, Tedd Sperling wrote: > I thank you for your addition, but what you provided did nothing to explain > the difference between abstract and interface. > > In your example: > >An abstract Shape with Circle and Square inheriting. > > OR > >An interface Shape with Circle and Square implementing. > > Does exactly the same thing -- so where's the difference? An interface does what it says on the tin: it describes an interface that a class can then tell the world it implements. An abstract class provides functionality as well as an interface description. An abstract class cannot be instantiated, it can only be extended. The logging example given by someone earlier in this thread is the most common example given for interfaces. This is where the interface is defined as an API for others to implement and/or use which then enables users to pick and choose the combination of implementations they want to use based on their requirements without needing to change any of the code of either class. Abstract classes are more likely to be used where there is a set of shared functionality that is required by several other classes, but which is not functionally useful by itself. An example of this from a current project of mine is in aggregating news sources (RSS, scraping, custom formats, etc). I have an abstract base class which supplies common code to parse and process data, and some abstract methods that must be implemented by any class that extends it because the abstract class methods may call them. The abstract class also contains a static factory method for getting instances of the type-specific classes. With this architecture the users of the abstract class never see the derived classes so there's no need to publish an interface for them to use. Does that help at all? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems with array_push?
Globals being used in a function. -Stuart On Tue, May 7, 2013 at 11:06 PM, Jay Blanchard wrote: > I know that I must be missing something really ridiculous, but when I > print_r these arrays they are empty. I have confirmed that $arrayElement > is properly formed, it just seems that array_push is not working. I know > I have done this before, but I cannot find my older code. Can someone > clear the mud from my eyes? > $issueDifferently = array(); > $issueProblem = array(); > $issueComment = array(); > function addToArray($id, $namecred, $product, $level, $type, $message) { > $arrayElement = $id > .'|'.$namecred.'|'.$product.'|'.$level.'|'.$type.'|'.$message; > if('DoDifferently' == $type) { > array_push($issueDifferently, $arrayElement); > } elseif ('Problem' == $type){ > array_push($issueProblem, $arrayElement); > } elseif ('Comments' == $type) { > array_push($issueComment, $arrayElement); > } > } > print_r($issueDifferently); > print_r($issueProblem); > print_r($issueComment); > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A little confused
On 23 Apr 2013, at 11:13, Chris Knipe wrote: > Yes, > > strtotime() does convert the $_SESSION value to a unix epoc, as expected. > However, date_format still complains that the argument is a Integer value, > instead of a DateTime. Sorry, I didn't read your email properly and didn't realise you were trying to use DateTime objects. $datetime = new DateTime('2013-04-23'); If all you're doing is formatting the date you'll find using date($unix_timestamp) far more efficient than date_format($datetime_object). -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Tue, Apr 23, 2013 at 12:09 PM, Stuart Dallas wrote: > On 23 Apr 2013, at 11:07, "Chris Knipe" wrote: > > > $_SESSION['ExpiryDate'] = "2013-04-23"; > > echo date_format($_SESSION['ExpiryDate'], "D, \t\h\e jS \o\f M Y"); > > > > Required Result: Mon, the 23rd of Apr 2013 > > > > I get however: PHP Warning: date_format() expects parameter 1 to be > > DateTime, integer given in > > > > I've had a look at the date/time function list, but I cannot seem to find > > any way to convert $_SESSION['ExpiryDate'] to an DateTime?? > > http://php.net/strtotime > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > > > > -- > > Regards, > Chris Knipe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A little confused
On 23 Apr 2013, at 11:07, "Chris Knipe" wrote: > $_SESSION['ExpiryDate'] = "2013-04-23"; > echo date_format($_SESSION['ExpiryDate'], "D, \t\h\e jS \o\f M Y"); > > Required Result: Mon, the 23rd of Apr 2013 > > I get however: PHP Warning: date_format() expects parameter 1 to be > DateTime, integer given in > > I've had a look at the date/time function list, but I cannot seem to find > any way to convert $_SESSION['ExpiryDate'] to an DateTime?? http://php.net/strtotime -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 22 Apr 2013, at 00:36, Glob Design Info wrote: > Ever heard of the MySQL C Connector? > > http://www.karlkraft.com/index.php/2010/06/02/mysql-and-objective-c/ That would be Objective-C, not C. I have used libmysqlclient extensively, but there's a lot more to a MySQL management tool than connecting to a MySQL server and running queries. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 22 Apr 2013, at 00:35, Glob Design Info wrote: > A very complex solution that takes time to learn, configure, and install, vs. > a single file I can toss on the server. > > Over-engineering is what is daft. Building your house by making your own bricks is daft. Using bricks somebody else has built is not. Or, if it makes more sense substitute a car and inventing wheels. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 22 Apr 2013, at 00:16, Glob Design Info wrote: > Except that I want to use my script and form - precisely because I have > already sunk time into it. I'm not going to sink *more* time into something > that could potentially create *another* problem. The idea of sunk time is that it's already been spent, so spending more in an attempt to justify the fact you spent it (i.e. to make it work because it's already cost you time/money) is daft when you discover a pre-built solution. To refuse to investigate it due to a refusal to throw the result of that time away is pure stubbornness, a normally expensive path to walk. > I want the script to work - as it should if PHP is 1/2 what it's cracked up > to be. If not, I'll have to look for another solution (like C which I have > been using for 20 years). Am I supposed to care whether you use PHP or not? But sure, let me know how much time it takes you to write a web-based MySQL management tool in C. In the meantime I'll install phpMyAdmin in five minutes, show it to your client, and probably not even charge them for it. C? Really? Why not assembly language, since the relationship between PHP and C is the same as that between assembly and C? Hell, take it all the way to punch cards if you want -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_connect noob question
On 22 Apr 2013, at 00:14, Glob Design Info wrote: > However, I may have found the problem: the port. As a security measure the > BaaS provider appears to have changed MySQL to a non-standard port. > So > > On the command line: > > sudo mysql --host=instance43490.db.xeround.com --port=8904 --user= > --password= > > WORKS perfectly - entering the MySQL Monitor. > > However, on the same host, same command line: > > sudo mysql --host=instance43490.db.xeround.com:8904 --user= > --password= The MySQL command line doesn't support putting the port number there, but the first parameter of mysql_connect does. If this is the problem then it cannot be true that replacing the variables you were taking from $_POST with literal strings for the username and password worked, as I asked earlier to which you said it does. Replace the first parameter to your mysql_connect call with 'instance43490.db.xeround.com:8904' and it will probably work. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 21 Apr 2013, at 23:01, Glob Design Info wrote: > I should note my user name in this case *is* an email address, however the > dots in that address are *not* being converted to underscores as mentioned > (at least not visibly). This could be the culprit. Try using a username without an @ in it. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 21 Apr 2013, at 22:43, Glob Design Info wrote: > Except that a) I already have my form and script done, b) don't have time to > learn phpMyAdmin, c) want to know why the script doesn't work as-is. You have multiple database users who will need to do this, or just one database user? If just one then it makes more sense to hard-code the username and password in the script and use something else like HTTP authentication to protect the script from unauthorised users. Giving internal database credentials to external users is generally a really really bad idea. Also, consider the time it will take to learn phpMyAdmin (it's simple - install, use) against the time it's taking to get your script working. The time you've spent developing the script is already sunk so there's no point sinking more in an effort to make that already-sunk time worthwhile. Also, how well tested is your script? I don't know but I can say with absolute confidence that phpMyAdmin has been tested far more. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Apr 21, 2013, at 12:46 PM, David OBrien wrote: > >> Not meaning to beat the proverbial dead horse >> >> I am developing a web portal that has to display the tables in the DB via a >> form/script. The web page has a login with user and password. Right now I am >> just trying to connect. >> This for a commercial app - the client wants both an API connect via PHP and >> a web portal in which they can login from a web page and view the tables in >> the DB. Right now I am just trying to get the form/PHP interaction to work. >> >> This sounds like a very good use statement for http://www.phpmyadmin.net/ >> >> You can set it for http auth in the config ... they enter a mysql username >> and password and they only see the databases and tables you want them to see >> >> Might be easier than reinventing the wheel and stressing all of us :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_connect noob question
On 21 Apr 2013, at 20:29, Glob Design Info wrote: > If that is the case then why does logging in with exactly the same params > from a UNIX shell work fine? Command line login supposedly would be adding > the @localhost or @IP_address as well but isn't. Only when I pass the > variables to the script is that happening. What makes you so sure it's not? It is. I promise you it is. You're not seeing it because you're not getting an error logging in. Do it on the command line again, but use a username that doesn't exist and you will see the host it's adding in the error message. > I am doing exactly as you stated: > >> mysql_connect('localhost', $_POST['username'], $_POST['password']); > > Except that I am first storing $_POST['username'] in local $user and > $_POST['password'] in local $pass first and then passing those to > mysql_connect. And I am connecting to a remote server, not localhost. Side note: why are you putting them in other variables first when you're only going to use them in that one place? It's a waste of memory. It's a minor niggle but it's a pet hate of mine. > I have already documented both the exact HTML and PHP code in this thread and > so see no need to post it elsewhere. And you're saying that when, instead of using $_POST variables you hard-code the username and password in the script it work? I doubt it. On the command line are you simply doing "mysql -u -p" and then entering the password? In that case it's using localhost. Is MySQL running on the same server as PHP? If so, try changing the remove server name to "localhost" in your script. I'm better a magnum of decent champagne that it works. It's very rare (and pretty stupid) for a web host to allow remote servers to connect to their MySQL instances, unless they have a shared MySQL instance for all of their customers. Given that you have command line access to the MySQL server, and can log in without specifying the host, I'm thinking you're trying to use it in a way they don't allow. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Apr 21, 2013, at 6:32 AM, Stuart Dallas wrote: > >> On 21 Apr 2013, at 11:20, Glob Design Info wrote: >> >>> I don't understand why mysql_connect should append something in the case of >>> a passed variable but not in the case of a local variable. Unless there is >>> something in the form parsing machinery I am unaware of. >> >> Nothing is being added by anything. When you log in to MySQL it takes both >> the username and the IP address/hostname of the machine you're logging in >> from and looks those up in the users table. This means that user abc logging >> in on localhost becomes abc@localhost. User abc logging in from >> 192.168.0.187 becomes abc@192.168.0.187, and is treated as a completely >> separate user from abc@localhost. >> >> The host comes from your end of the connection. So if you connect on >> localhost, your end is also localhost. If you connect on the IP address or >> hostname, your end is the rDNS lookup of your IP address - note that this >> may be the same address as the one to which you are connecting, but will >> represent a different user to @localhost as far as MySQL is concerned. >> >> The only thing that may be being added to the variable when the form data is >> parsed is slashes, and then only if you have magic_quotes_gpc switched on in >> php.ini. I believe this has already been eliminated as the cause earlier in >> this thread. >> >> The problem you describe is not possible, so I'm betting your description is >> missing something. Given a request with POST parameters of username=abc and >> password=def, the following two lines are equivalent: >> >> mysql_connect('localhost', 'abc', 'def'); >> mysql_connect('localhost', $_POST['username'], $_POST['password']); >> >> If this is exactly what you're doing then something very strange is going >> on. If this is not exactly what you're doing, please narrow your code down >> to the minimum required to demonstrate the problem and post it somewhere >> like gist.com then send us the link. >> >> However, a more important question for me is why you are doing this. You say >> you are aware of the security implications, and that you'll "deal with that >> later," but I question how you're going to deal with it. What exactly are >> you developing that requires DB credentials to come from a form on a web >> page? >> >> -Stuart >> >> -- >> Stuart Dallas >> 3ft9 Ltd >> http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 21 Apr 2013, at 15:46, tamouse mailing lists wrote: > On Sun, Apr 21, 2013 at 9:12 AM, Tedd Sperling > wrote: >> On Apr 21, 2013, at 9:32 AM, Stuart Dallas wrote: >>> However, a more important question for me is why you are doing this. You >>> say you are aware of the security implications, and that you'll "deal with >>> that later," but I question how you're going to deal with it. What exactly >>> are you developing that requires DB credentials to come from a form on a >>> web page? >>> >>> -Stuart >> >> You and I are asking the same question, but I am afraid the poster is not >> listening. Instead, he is pursuing a course of action that simply repeats >> his problem. His focus is on a specific tree instead of the forest. He >> doesn't want to widen his view. >> >> Until the poster answers our question, I'm afraid our recommendations will >> fall on deaf ears. >> >> Some days you can help and some days you can't. >> >> Cheers, >> >> tedd > > There's the Zen saying "When the student is ready, the teacher > appears." -- which to me says more about those attempting to teach > than those attempting to learn. :) To me that means that you won't recognise the teacher until you're ready to learn. Teachers are always all around all of us, we just need to be willing to learn. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_connect noob question
On 21 Apr 2013, at 11:20, Glob Design Info wrote: > I don't understand why mysql_connect should append something in the case of a > passed variable but not in the case of a local variable. Unless there is > something in the form parsing machinery I am unaware of. Nothing is being added by anything. When you log in to MySQL it takes both the username and the IP address/hostname of the machine you're logging in from and looks those up in the users table. This means that user abc logging in on localhost becomes abc@localhost. User abc logging in from 192.168.0.187 becomes abc@192.168.0.187, and is treated as a completely separate user from abc@localhost. The host comes from your end of the connection. So if you connect on localhost, your end is also localhost. If you connect on the IP address or hostname, your end is the rDNS lookup of your IP address - note that this may be the same address as the one to which you are connecting, but will represent a different user to @localhost as far as MySQL is concerned. The only thing that may be being added to the variable when the form data is parsed is slashes, and then only if you have magic_quotes_gpc switched on in php.ini. I believe this has already been eliminated as the cause earlier in this thread. The problem you describe is not possible, so I'm betting your description is missing something. Given a request with POST parameters of username=abc and password=def, the following two lines are equivalent: mysql_connect('localhost', 'abc', 'def'); mysql_connect('localhost', $_POST['username'], $_POST['password']); If this is exactly what you're doing then something very strange is going on. If this is not exactly what you're doing, please narrow your code down to the minimum required to demonstrate the problem and post it somewhere like gist.com then send us the link. However, a more important question for me is why you are doing this. You say you are aware of the security implications, and that you'll "deal with that later," but I question how you're going to deal with it. What exactly are you developing that requires DB credentials to come from a form on a web page? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect noob question
On 20 Apr 2013, at 16:25, Jim Giner wrote: >> Why are you allowing anyone to connect to your database from a form? >> > A little OT, but... > What do you mean by this question? How do you check someone's credentials if > not by connecting to a db to verify the login? Cause I'm doing the same kind > of thing all over the place. With good practices on validation and such > before doing my query of course. I'm pretty sure that's not what tedd meant. The code is logging in to the database server using the username and password from the form. There are very few legitimate reasons to be doing this, so the question is well worth asking. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] timezone
On Mon, Apr 15, 2013 at 10:06 PM, Larry Martell mailto:la...@software-horizons.com";>> wrote: On Mon, Apr 15, 2013 at 2:57 PM, Maciek Sokolewicz wrote: > On 15-4-2013 22:12, Larry Martell wrote: >> >> On Mon, Apr 15, 2013 at 1:59 PM, Lester Caine wrote: >>> >>> Larry Martell wrote: > > > No, I don't - this app runs in different locations all over the world. I found some code at php.net that does this: date_default_timezone_set(@date_default_timezone_get()); $deftz = date('T'); And that is working for me and giving me what I need. >>> >>> >>> >>> But do you ACTUALLY know what time zone is stored IN the database? What >>> if >>> te database was from another server? >>> >>> One of the 'standards' adopted when working world wide is to ensure what >>> is >>> stored IN the database is always UTC based. So you can always compare >>> times >>> on the same consistent base. The only time you need the offset is to >>> display >>> a local time, and that is either the time local to the server, or the >>> time >>> local to the client. >>> >>> The 'default' timezone is not necessarily the right one in either case ;) >> >> >> I misspoke - the data in the db is in UTC. This is used to covert the >> time of day on the server to the user's local timezone. >> > > You are aware that the code you used is really bad practice, right? You're > basically hiding the error "no default timezone set" by getting the default > timezone, which returns an error; surpressing that error, providing the > date_default_timezone_set function with the default value of > date_default_timezone_get if none is defined (which there should!!), being > "UTC". > > So in short, you're saying "set the default timezone to the default timezone > if no timezone is set, which I know there is not". That's very hard to > understand for future programmers reading your code. Why not just set > "date_default_timezone_set('UTC')". It's clear, resolves the warning and > works perfectly, instead of relying on vague defaults somewhere, in the hope > they're set right. > > On a sidenote; the reason why your original "fix" did not work: > $deftz = date.timezone; > Is because date.timezone is an ini setting. Not valid PHP code. And the > error actually tells you you need to SET date.timezone, not set a variable > TO the ini setting. In other words, you wanted date.timezone = "UTC" instead > of $tz = date.timezone (which makes no sense anyway) But UCT is not the timezone. When this app runs in New Mexico (where I am) it's Mountain time. When it runs in NY it's Eastern. When it runs in Tokyo it's JST, etc. The user has the option of setting the timezone all times are displayed in. They can select any timezone regardless of where they are. The app displays the last update time in the user selected TZ. So I have to convert the time I get from the server to th...@lsces.co.uk>@gmail.com>@gmail.com> You don't need to convert anything! Store as unix timestamps, and call date_default_timezone_set with the user's selection before you use any other date-related functions and everything will just work. This is not as hard as everyone seems to think!-Stuart — Sent from my leaf blo...@gmail.com>@lsces.co.uk>@gmail.com>@lsces.co.uk>@gmail.com>
Re: [PHP] JPGraph new GanttBar ... bar caption on left, right side
On 9 Apr 2013, at 11:23, "Meli Marco" wrote: > Hello, > I would like to know how to print captions (normally used for percentage > completion) on the left (start date) and right (end date) side of the > bar, instead just on the right. > Below the method for bar creation: > $planbar = new GanttBar ($c,'', $aData[PLANSTART][$y], > $aData[PLANENDE][$y], ( chr(32).$aData[PLANSTART][$y].' - > '.$aData[PLANENDE][$y] ) ); > Thanks. > Marco. This is a mailing list for PHP, not things written using PHP. You want a mailing list for JPGraph. https://groups.google.com/forum/?hl=en-GB#!forum/jpgraph Would you email the Oxford English Dictionary for help with using the English language? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Set process custom identifier
On 2 Apr 2013, at 15:11, Sorin Badea wrote: > I'm trying to implement a standalone threading component, and in current > implementation I'm using `popen` to run a separate process with some > arguments that I'm using to identify them (for example `php > some_dummy_file.php -thread_id=`). This way when I'm trying to see > which are my threads I don't have to check every stored pid and see if they > are still up. Personally I would be storing the PIDs somewhere, but that's just me. The other way you could probably do it is by having the main script (the one executed on the command line) named something unique, the use dirname(__FILE__) to get that name from within that script. Then parse the PS output for that script name. You may need to exclude lines containing bash or similar depending on how the script was executed. Seriously, PIDs are the way to go! Based on what you've put above you already have some sort of storage that's tracking threads (they have a hash), so why not add the PID to that? Or, even better, use the PID as that hash? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Tue, Apr 2, 2013 at 5:02 PM, Stuart Dallas wrote: > On 2 Apr 2013, at 14:50, Sorin Badea wrote: > >> I don't want to wait for it and surely I don't want to safe that pid in >> same place. I just want to use `ps` with a pattern to return my forked >> process. > > Storing the PID of a process you need to monitor is the established method, > and is certainly the most reliable. Why can't you use the PID as the pattern > to look for? If there's a reason then please explain it as that will help us > assist you. If there's no reason then I don't understand why you're trying to > over-complicate it. > > If you're just wanting to monitor it from the process that forked it then you > don't need to store the PID anywhere other than a variable, and you don't > need to wait for it. > > If you absolutely must do this then the only way is via an extension such as > proctitle: http://php.net/setproctitle > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > >> On Tue, Apr 2, 2013 at 4:48 PM, Matijn Woudt wrote: >> >>> Hi, >>> >>> pcntl_fork will return the pid of the fork, what is wrong with using that >>> pid to identify the process? >>> >>> - Matijn >>> >>> >>> On Tue, Apr 2, 2013 at 3:38 PM, Sorin Badea wrote: >>> >>>> Hi guys, >>>> I'm trying to find a solution to identify a php process that is spawned >>>> with pnctl_fork. I've tried to set a custom gid but this isn't viable >>>> because I have to run the parent proc with administrative permissions. I >>>> need to do this native without any pecl extensions. >>>> Is there a way to do this ? >>>> >>>> Regards, >>>> -- >>>> Badea Sorin (unu.sorin) >>>> sorin.bade...@gmail.com >>>> unu_so...@yahoo.com >>>> >>> >>> >> >> >> -- >> Badea Sorin (unu.sorin) >> sorin.bade...@gmail.com >> unu_so...@yahoo.com >> Pagina personala: >> http://badeasorin.com > > > > > -- > Badea Sorin (unu.sorin) > sorin.bade...@gmail.com > unu_so...@yahoo.com > Pagina personala: > http://badeasorin.com
Re: [PHP] Set process custom identifier
On 2 Apr 2013, at 14:50, Sorin Badea wrote: > I don't want to wait for it and surely I don't want to safe that pid in > same place. I just want to use `ps` with a pattern to return my forked > process. Storing the PID of a process you need to monitor is the established method, and is certainly the most reliable. Why can't you use the PID as the pattern to look for? If there's a reason then please explain it as that will help us assist you. If there's no reason then I don't understand why you're trying to over-complicate it. If you're just wanting to monitor it from the process that forked it then you don't need to store the PID anywhere other than a variable, and you don't need to wait for it. If you absolutely must do this then the only way is via an extension such as proctitle: http://php.net/setproctitle -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Tue, Apr 2, 2013 at 4:48 PM, Matijn Woudt wrote: > >> Hi, >> >> pcntl_fork will return the pid of the fork, what is wrong with using that >> pid to identify the process? >> >> - Matijn >> >> >> On Tue, Apr 2, 2013 at 3:38 PM, Sorin Badea wrote: >> >>> Hi guys, >>> I'm trying to find a solution to identify a php process that is spawned >>> with pnctl_fork. I've tried to set a custom gid but this isn't viable >>> because I have to run the parent proc with administrative permissions. I >>> need to do this native without any pecl extensions. >>> Is there a way to do this ? >>> >>> Regards, >>> -- >>> Badea Sorin (unu.sorin) >>> sorin.bade...@gmail.com >>> unu_so...@yahoo.com >>> >> >> > > > -- > Badea Sorin (unu.sorin) > sorin.bade...@gmail.com > unu_so...@yahoo.com > Pagina personala: > http://badeasorin.com
Re: [PHP] target question
On 25 Mar 2013, at 16:35, "Ford, Mike" wrote: >> -Original Message- >> From: Paul M Foster [mailto:pa...@quillandmouse.com] >> Sent: 25 March 2013 16:09 >> >> This behavior of the browser actually conforms to the standard as >> far as >> I know. The "target" attribute is attached only to the tag, >> according to w3schools.com > > Actually, the W3C HTML 4.01 Recommendation says: > >target = frame-target [CI] > >This attribute specifies the name of a frame where a document >is to be opened. > >By assigning a name to a frame via the name attribute, authors >can refer to it as the "target" of links defined by other >elements. The target attribute may be set for elements that >create links (A, LINK), image maps (AREA), and forms (FORM). > > In the current HTML5 draft, target is explicitly a permitted > attribute of the form tag -- although I believe it was originally > marked as deprecated. Indeed. In fact w3schools.com is known to be a very unreliable source of information these days. My advice would be to avoid it at all costs! http://w3fools.com/ -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] application level variable file
On 22 Mar 2013, at 14:22, wrote: > I am very new to the PHP application and would like to create a new project. > I would like to have a file to save my application level variable and > functions. > > I would like to know does PHP have any default file name and file path for > this file like Web.config file for ASP.Net and Application.cfm for > ColdFusion? No. Without the use of extensions, PHP follows a shared-nothing architecture. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] significance of escape character in string in PHP
On 18 Mar 2013, at 15:08, Matijn Woudt wrote: > On Mon, Mar 18, 2013 at 2:19 PM, Sebastian Krebs wrote: > >> 2013/3/18 Ken Robinson >> >>> >>> >>> On 18.03.2013 09:10, Norah Jones wrote: >>> >>>> I am having an string which was have few ' (single quote) and few " >>>> (double quotes) and was not able to insert into the mysql database. I >>>> have replaced them with \' and \" and everything is fine. >>>> Though this are fine now but don't understand the working and I could >>>> have missed few corner cases also. Please suggest the working and also >>>> if there is some better way to achieve this. >>>> >>> >>> You should be using either mysql_real_escape_string or >>> mysqli_real_escape_string (preferably the later) depending on how you're >>> accessing the DB. >> >> >> You shouldn't use ext/mysql at all! >> Use prepared statements with PDO_MYSQL or MySQLi >> >> > And here comes the flame war again... There's no need for it to be a flame war. The mysql extension is officially not recommended for writing new code, so anyone using it should be informed of this fact. I think it should consist of more than "don't use that," but at the very least that should cause the questioner to want to know why. http://php.net/intro.mysql This issue is problematic for exactly the reason Norah demonstrates above: "it's working." Great that in this case it hasn't been left at that, but most will see it work and think they've "got it right." I believe the community has a responsibility to give good advice and recommend best practices as well as directly addressing people's problems, so it's right that things like this get repeatedly pointed out where appropriate. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] actually HTML again; resizeing images
On 17 Mar 2013, at 13:22, "georg" wrote: > Anyone knows a good reading about how and when images displayd with HTML tags > are > re-sized ? Not entirely sure what you mean, but a downloaded image will be resized when it needs to be shown in different dimensions to the actual image, whether that's due to width and height attributes on an img tag, or CSS styles, or whatever. The specific algorithm used (which I'm guessing is what you mean by "how" is up to the browser and cannot be controlled. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] rather a HTML Q; however 2-FRAME
On 15 Mar 2013, at 13:34, "georg" wrote: > To make things clearer. I already have the frames since earlier and > want to fill then again, so it is not at the "initial filling" of the frames > at "creation". You want one action to change the content in two frames? For that you'll need to use Javascript, or reload the parent frame, neither of which involve PHP. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing Files Outside the Web Root
On 15 Mar 2013, at 13:11, "Dale H. Cook" wrote: > At 09:44 PM 3/14/2013, tamouse mailing lists wrote: > >> If you are delivering files to a (human) user via their browser, by whatever >> mechanism, that means someone can write a script to scrape them. > > That script, however, would have to be running on my host system in order to > access the script which actually delivers the file, as the latter script is > located outside of the web root. If a browser can get at it then a spider can get at it. All this talk of the web root is daft. Unless your site is being specifically targeted (highly unlikely) then it automated systems that are downloading your content and offering it on other websites. The only way such a system can discover content is if it's linked from somewhere. Whether that link uses a script that inside or outside the web root is completely irrelevant. Since copies of the content is now out there, anything you add now to protect your content is not going to get it back. You'll have to pursue legal avenues to prevent it being made available, and that's usually prohibitively expensive. Based on your description of your users, you have the age-old dilemma of balancing ease of use and security. The more you try to protect the content from these spiders the harder you'll make it for users. Here's what I'd do: make sure your details and your website info are plastered across every page of the PDF files. Make sure that where copies exist it's going to be obvious where the content came from. It sounds like you don't charge for the content (this problem wouldn't exist if you did), so you have nothing financial to gain from controlling these external copies, other than wanting it to be clear from whence it came and where to find more. At the end of the day the question is this: would you rather control access to your creation (in which case charge a nominal fee for it), or would you prefer that it (and your name/cause) gets in to as many hands as possible. As a professional photographer I made the latter choice a long time ago and haven't looked back since. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Introduction ... !
On 2 Mar 2013, at 16:25, Jay Blanchard wrote: >> [snip] >> I've been on this list since the early 2000's. I used to participate a lot >> back then but then took up a non-php related job and I stopped paying >> attention to the list. I've been working again with php for the past 4.5 >> years but choose to just monitor the list and haven't participated much. >> Perhaps I should participate more. But yeah, I've been here like 12 years >> or so. God I'm getting old. >> [/snip] > No - Tedd is old. The rest of us are just Spring chickens. Speak for yourself, I'm an autumn turkey! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] phpinfo()
On 20 Feb 2013, at 19:23, John Taylor-Johnston wrote: > > > Design in Motion Webdesign wrote: >> >>> >>> >>> John Taylor-Johnston wrote: >>> I cannot find button2 in phpinfo() when I click it. I was hoping to find a $_POST["button2"] value. What am I doing wrong? >>> onclick="formSubmit()"> I really wanted to use a button to pass a different condition than a >>> >>> Use a different value or name on the button. Don't >>> use JavaScript to trigger the form like that. Its not necessary and will >>> bite you in the ass if ypu get a visitor who browses without JavaScript, >>> which can include security aware users, blind users, etc >>> Thanks, >>> Ash >>> http://www.ashleysheridan.co.uk >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> Try $_POST['button2'] >> >> Best regards. >> Steven >> > > $_POST['button2'] does not exist. I'm using radio to get aorund it for now. A > button would have been cleaner. You were given the answer, did you not try it? Starting with the code in your original post: 1) Change the type to submit. 2) Remove the onclick. 3) Job done! -Stuart -- Sent from my leaf blower -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined Variables
On 14 Feb 2013, at 20:57, Al wrote: > On 2/14/2013 1:54 PM, Stuart Dallas wrote: >> Sorry for the top post! >> >> I don't know numbers, but my gut instinct is that the cycles wasted raising >> the notice (it gets raised even if it goes nowhere so turning display and >> log doesn't remove the hit completely) are better spent executing defensive >> code. >> >> There is no reason, ever, that production code should raise notices about >> which you don't care. If PHP is telling you something might be wrong, >> something might be wrong! And if you're investigating the code already, >> figure out what's happening and deal with it properly. >> >> Only lazy and/or developers ignore notices. If you're one of them and this >> statement offends you, you probably know it's right! >> >> -Stuart >> > > I agree with Stuart. > > To minimize the overhead of testing every possible undefined variable with > isset(), I assign them at the top of the page which uses them. e.g., > > $userInstrHtmlSizeWarning = false; > $currentUserRecArray = array(); > if(!isset($_SESSION['pwPassed']))$_SESSION['pwPassed'] = false; > > I also have this snippet at the top of my app config file. > > if(true){ // TRUE for debug only > ini_set("display_errors", "on"); //use off if users will see them > error_reporting(E_ALL) > $error_reporting = 'Error display and logging > on '; > } > else $error_reporting=null; > > I put this at a convenient place on the page so I don't forget to turn off > the error reporting when the code goes live. > > if($error_reporting) echo $error_reporting; I've used the following method for accessing elements of the global arrays for a long time. It saves a lot of typing! http://stut.net/2011/04/12/php-snippet-array-element-access/ Note that if you're using PHP5 you should remove the & before the $a in the function definition. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined Variables
Sorry for the top post! I don't know numbers, but my gut instinct is that the cycles wasted raising the notice (it gets raised even if it goes nowhere so turning display and log doesn't remove the hit completely) are better spent executing defensive code. There is no reason, ever, that production code should raise notices about which you don't care. If PHP is telling you something might be wrong, something might be wrong! And if you're investigating the code already, figure out what's happening and deal with it properly. Only lazy and/or developers ignore notices. If you're one of them and this statement offends you, you probably know it's right! -Stuart -- Sent from my leaf blower On 14 Feb 2013, at 18:04, Roman Gelfand wrote: > Is there a performance hit when a variable is undefined? or, perhaps, > aside from the obvious uncontrolled conditions, are there other > impacts? > > Thanks in advance > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache to serve RESTful requests using PHP
On 10 Feb 2013, at 06:57, AmirBehzad Eslami wrote: > Stuart, thanks for your detailed response. > > >> I find it unlikely that Apache is your bottleneck, > >> especially with a service involving MySQL. > >> How have you come to this conclusion? > > Apache is the entry-point to our service, and I did a > benchmark with AB to see how it can handle concurrent > requests in a timely fashion. After a number of 50 concurrent > requests, the average "time per request" reached from less than > a second to 5 seconds. I *strongly* recommend you try the same test with nginx. Unless this is due to the way your code works I'm confident you'll see this effect disappear! > >> As far as keep-alive goes, how frequently will individual > >> clients be accessing the service? > > There are only "a few" clients that call the service. These clients > are PHP-driven web pages. Each page has its own unique ClickID > and a set of other unique parameters per user visit. These pages send these > parameters to the service using php-curl, and expect a generated > response to be returned. That's why I'm saying each request and > response is unique. > > Whenever a user visits a web-page, there would be a call to the > web-service. At the moment, we don't know number of concurrent > visits. We're looking for a way to figure that out in Apache. > > Is there a way to see if the requests are using the previously keep-alived > http channel? Because same client will send requests to the service, > and I'm curious to know if the Apache will allocate the already-opened > channel, or will create a new one? If it's making one request to your service per page request, keep-alive is pointless as it won't be able to reuse the connection. In this instance I would turn keep-alive off. > >> If you are using joins to pull in extra data (i.e. IDs to a name > >> or similar) look at using Memcache for those, but make sure > >> that when they're updated in the DB they're also updated in Memcache. > > Memcache or Redis, I'm going to add a caching layer between > MySQL and PHP, to store the de-normilized data. For simple caching I'd recommend Memcache over Redis, purely because Redis is more complex due to its support for sets, queues and other very useful stuff. The only reason I'd use Redis for simple caching is because it can periodically flush the cache to disk so if it has to restart it can start with a primed cache. However, in most cases that is not a huge advantage. If each request and response is unique you need to be careful about what you choose to cache such that you don't incur caching costs without reaping benefits that make it worthwhile. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is header() malfunction due to PHP5.3.3 -> 5.4.11 transition?
On 9 Feb 2013, at 21:00, Jonathan Eagle wrote: > Stuart, > > Thanks for getting back to me you were right - I had misread the > headers_sent() Return Value statement. When I went back and tested > it turns out that the 'initialize' routine is somehow prematurely > sending output out. So, now I have to figure out which of the ten > called routines and classes/objects in the initialize script are the > culprit. > > I greatly appreciate the assistance, The error message that should be being displayed tells you where output was started. Check your error_reporting and display_errors settings to make sure errors are being displayed and you should be able to save a lot of time. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On 2/9/2013 2:34 PM, Stuart Dallas wrote: >> On 9 Feb 2013, at 19:00, Jonathan Eagle wrote: >> >>> I'm having a problem with a very straightforward routine; one that works >>> in one PHP installation but not on the other. The only difference that I >>> can see between the working version and the non-working version is that >>> the one that doesn't work is running on the later version of PHP. The >>> following basic log-in routine works fine on my personal development >>> server, running PHP 5.3.3, but doesn't work on the production server, >>> hosted by 1&1.com that is running PHP 5.4.11. >>> >>> >> require_once('../includes/initialize.php'); //<== $session object >>> init'd and set to false >>> >>> if(!$session->is_logged_in()) >>> { >>> header("Location: login.php"); >>> exit; >>> } >>> ?> >>> >>> login.php is in the same directory as the file that has this code at the >>> very top of the file. >>> >>> Everything works as expected right up to the 'exit;' line. >>> * $session->is_logged_in() is false >>> * when tested immediately after the 'header("Loc...)' statement, >>> 'headers_sent()' reports true. >>> * no error messages result (like: 'header already sent', etc.) >>> >>> Instead of the program flow moving to 'login.php', the URL indicates >>> that the destination is the original file, except that the file is empty >>> - zero bytes. I've tried accessing the routine via three different >>> computers, all running different MS operating systems from XP to Win7 >>> and they all behave identically. The behavior is also consistent >>> between browsers (i.e., FireFox, Chrome, and Windows Explorer). >>> >>> I also did a $_SERVER variable dump immediately before and after the >>> 'header(...' line, expecting to see a difference in at least one of the >>> 'REDIRECT_*' elements, but both outputs where identical with the >>> exception that the $_SERVER ouput after the header statement was >>> executed was missing the following line: >>> >>> ["HTTP_CACHE_CONTROL"]=> "max-age=0" >>> >>> It doesn't look relevant to me, but I include it to be thorough. >>> >>> I looked through the PHP changelog pages, but I don't see mention of the >>> problem (of course, that might just be due to my ignorance). The ISP >>> for the production version of PHP indicated that I should come here for >>> help, so here I am. >>> >>> Can anyone shed some light as to what is (or might be) going on? >>> >>> Any help or guidance that can be offered will be greatly appreciated. >> >> >> Check the output buffering settings. You say no errors are displayed, but >> are you sure that errors are set to be displayed? >> >> You mention the headers_sent() result immediately after the header() >> function call is true. If the header() function call had worked it would not >> be true, it would be false. You have output being sent to the client before >> that header() function call. >> >> -Stuart >> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is header() malfunction due to PHP5.3.3 -> 5.4.11 transition?
On 9 Feb 2013, at 19:00, Jonathan Eagle wrote: > I'm having a problem with a very straightforward routine; one that works > in one PHP installation but not on the other. The only difference that I > can see between the working version and the non-working version is that > the one that doesn't work is running on the later version of PHP. The > following basic log-in routine works fine on my personal development > server, running PHP 5.3.3, but doesn't work on the production server, > hosted by 1&1.com that is running PHP 5.4.11. > > require_once('../includes/initialize.php'); //<== $session object > init'd and set to false > > if(!$session->is_logged_in()) > { >header("Location: login.php"); >exit; > } > ?> > > login.php is in the same directory as the file that has this code at the > very top of the file. > > Everything works as expected right up to the 'exit;' line. > * $session->is_logged_in() is false > * when tested immediately after the 'header("Loc...)' statement, > 'headers_sent()' reports true. > * no error messages result (like: 'header already sent', etc.) > > Instead of the program flow moving to 'login.php', the URL indicates > that the destination is the original file, except that the file is empty > - zero bytes. I've tried accessing the routine via three different > computers, all running different MS operating systems from XP to Win7 > and they all behave identically. The behavior is also consistent > between browsers (i.e., FireFox, Chrome, and Windows Explorer). > > I also did a $_SERVER variable dump immediately before and after the > 'header(...' line, expecting to see a difference in at least one of the > 'REDIRECT_*' elements, but both outputs where identical with the > exception that the $_SERVER ouput after the header statement was > executed was missing the following line: > > ["HTTP_CACHE_CONTROL"]=> "max-age=0" > > It doesn't look relevant to me, but I include it to be thorough. > > I looked through the PHP changelog pages, but I don't see mention of the > problem (of course, that might just be due to my ignorance). The ISP > for the production version of PHP indicated that I should come here for > help, so here I am. > > Can anyone shed some light as to what is (or might be) going on? > > Any help or guidance that can be offered will be greatly appreciated. Check the output buffering settings. You say no errors are displayed, but are you sure that errors are set to be displayed? You mention the headers_sent() result immediately after the header() function call is true. If the header() function call had worked it would not be true, it would be false. You have output being sent to the client before that header() function call. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache to serve RESTful requests using PHP
On 9 Feb 2013, at 16:42, AmirBehzad Eslami wrote: > We're a developing a PHP-driven web service with a RESTful API, > and we have a dedicated Linux server for that with 6GB of RAM. > > Since this service will be used by many clients in a concurrent > manner, we'll face with a high-load on our web-server. But > web-services are different from web pages, for instance they > don't include images, or in this case we only serve JSON. > > I'm wondering what are the recommended configurations for > the Apache web-server in these situations? Should we disable > keep-avlie? What about other directives? Apache is our > bottleneck, and we're trying to optimize it. Should we use nginx instead? I find it unlikely that Apache is your bottleneck, especially with a service involving MySQL. How have you come to this conclusion? I would personally recommend nginx + php-fpm over Apache + mod-php every time. The pre-request memory footprint is massively reduced and I've seen nothing but upsides since migrating most of my client's sites, and my own. As far as keep-alive goes, how frequently will individual clients be accessing the service? Are they likely to be using client software that supports keep-alive? You basically want to weigh up the cost of potentially keeping the connection open against the likelihood that the majority of clients will make use of it for multiple requests. My gut reaction based on your description would be to set it to 1 as suggested by Bastien so it has minimal impact while still allowing clients who support it to be that bit more efficient. Focus your optimisation efforts on MySQL. If the bulk of requests will be reads you'll benefit from read-only slaves. If the data can be neatly sharded then that's definitely worth investigating. When writing data get it as close to the structure that will be needed when reading, including de-normalising it if necessary. If you are using joins to pull in extra data (i.e. IDs to a name or similar) look at using Memcache for those, but make sure that when they're updated in the DB they're also updated in Memcache. Do the DB query, get all the Memcache keys you need a do a multi-get request. The other way to do this is to de-normalise as discussed above, but that makes updating the data very expensive (as every row needs to be updated). In my tests breaking it out to a Memcache instance was far more efficient. At the end of the day there will always be things you can do that are only applicable to your service, but the general rule is to need to do as little as possible to serve the data when it's requested, shifting as much of the work as possible to when it is written (assuming a mostly-read service). -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Pear Page2
On 6 Jan 2013, at 18:42, Tedd Sperling wrote: > I also realize there is a language problem here -- while I cannot speak your > language, what you say in mine and my replies, may be misinterpreted -- but > in any case, no offense was meant. Indeed. I'm guessing that when Silvio said "All websites are created manually. (nano + html/css Tags)" he meant "All of the websites are created manually. (nano + html/css Tags)" meaning the sites he's working on rather than every site in existence. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable placeholders in a text file
Please excuse the top post, but this may be helpful: http://stut.net/2008/10/28/snippet-simple-templates-with-php/ -Stuart -- Sent from my leaf blower On 31 Dec 2012, at 19:59, Ashley Sheridan wrote: > On Mon, 2012-12-31 at 13:39 -0600, Nelson Green wrote: > >> Hello, >> >> I have created a simple function that prints a personalized greeting by >> reading >> the greeting contents from a file. I pass the user's name to the function, >> and the function reads the file contents into a string variable. I am then >> using str_replace to replace the word USER in the string with the user's >> name that was passed to the function. Then the function correctly prints >> the personalized greeting as I wish. >> >> My question is, is there another way to do something similar, such as >> embedding a variable name directly into the text file? In other words, >> instead of my text file reading: >> >> Hello USER ... >> >> Can I do something like this: >> >> Hello $user_name ... >> >> and then write my function to replace $user_name with the passed >> parameter prior to printing? >> >> The reason I ask is because I am going to want to do three substitutions, >> and I'd rather not do three str_replace calls if I don't have to. Plus the >> latter seems to be a more robust way of making the changes. >> >> Thanks, and apologies if this has been asked before and I missed it. I'm >> just not sure how to phrase this for a search engine. >> >> Nelson > > > You could use an existing templating solution, like Smarty, although for > what you want to do it might be overkill. A few str_replace() calls > shouldn't produce too much overhead, but it depends on the size of the > text string in question. If it's just a couple of paragraphs of text, no > problem, something closer to a whole chapter of a book will obviously be > more expensive. > > You could try eval() on the block of text, but if you do, be really > careful about what text you're using. I wouldn't recommend this if > you're using any text supplied by a user. As a last option, you could > have the text stored as separate parts which you join together in one > string later. This might be less expensive in terms of processing power > required, but it also makes maintenance more of a hassle later. > > > Thanks, > Ash > http://www.ashleysheridan.co.uk > >
Re: [PHP] Can't use the SNMP class
On 4 Dec 2012, at 17:42, "Marc-Andre Bergeron" wrote: > When I try to use the SNMP class I got the following error: PHP Fatal error: > Class 'SNMP' not found. I use the following version: PHP 5.3.3 (cli) and it > runs on CentOS release 6.2 (Final). I've also installed > net-snmp-5.5-41.el6_3.1.x86_64. According to the documentation "In order to > use the SNMP functions requires installation of the » Net-SNMP package". I > can use the snmp functions (ex: snmpget, snmpset, etc) but not the SNMP > class. Any idea? The class is only available in PHP 5.4+. http://php.net/snmp.construct -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: shared memory on php servers?
On 4 Dec 2012, at 10:51, rene7705 wrote: > I would also like to hear any thoughts on how to efficiently add, > delete and edit data in this large and deep array structure from > multiple sessions at nearly the same time.. > > On Tue, Dec 4, 2012 at 11:49 AM, rene7705 wrote: >> Hi folks.. >> >> I'm wondering, what's the fastest way to put a large and deep array() >> structure in shared memory on a PHP server? Split the data up into smaller pieces. There's rarely a valid reason to store a huge array of data as a single blob. It's an array, so it breaks up by the first level of keys at the very least. Look at APC, memcached, and redis. These are the most popular ways to store data in shared memory. Note that APC is a PHP extension so you can only access the shared memory from one machine, whereas memcached and redis are separate daemons so you can access them from multiple servers. Also, as Sebastian says, a database is another option unless you have a good reason to want the data in shared memory rather than a DB. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Switch - Case Statement Questions
On 19 Nov 2012, at 19:35, Tim Streater wrote: > On 18 Nov 2012 at 14:44, Jim Giner wrote: > >>>>>> 2. Using Switch {ALWAYS FIRST CASE!!!} >>>>>> >>>>>> //$boxes = 1; >>>>>> //switch ($count) { >>>>>> //case ($count > 14): >>>>>> //$boxes = 3; >>>>>> //break; >>>>>> //case ($count > 7 && $count <= 14): >>>>>> //$boxes = 2; >>>>>> //break; >>>>>> //case ($count <= 7): >>>>>> //default : >>>>>> //$boxes = 1; >>>>>> //break; >>>>>> //} > > >> To answer Iñigo's comment - the OP's version is very much like an >> If-ElseIF structure, and nothing like a Switch. > > Just so. Perhaps those who are not grasping the point could re-read their > copy of "The Elements of Programming Style" by Kernighan and Plauger where > this sort of issue is covered. And of course, nothing is allowed to have changed since 1978! Using a switch in that manner is normal for me. Should I change my style simply because you don't agree with it? If so, why don't you change your style because I don't agree with that? Code is art; there is no "right" way to do it. Can code be shown to be more efficient, elegant, faster, cleaner? Yes. Right or wrong? No. > See, it's all about expectations. When I worked at SLAC, there was a wise guy > there who had removed the catalytic converter from his Scirocco and who > though it clever to race up 280 from San Jose to SLAC at 100mph, sometimes > slipstreaming behind another idiot doing the same. If I look in my rear-view > mirror, I expect those I can see to be doing 70mph tops (that's what a lot of > people did 30 years ago on 280), not 100, and to make judgements accordingly. > Equally, I have certain expectations when I see a switch statement; it trying > hard to look like if-elseif-etc is not one of them. Why is it their fault for doing 100mph and not yours for assuming they're only doing 70mph? I'm not saying they're right to be doing 100mph, but I'm definitely saying you're wrong for assuming they're only doing 70mph. Assumptions are the mother of all f*** ups. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Switch - Case Statement Questions
On 17 Nov 2012, at 10:53, Tim Streater wrote: > On 17 Nov 2012 at 01:33, Iñigo Medina wrote: > >> On Fri, 16 Nov 2012, Jim Giner wrote: > >>> Maybe I'm way out of touch, but when I look at php.net for the syntax of the >>> switch statement I see: >>> switch($var){ >>> case (value): >>> (do something) >>> case (other value): >>> (do something else) >>> } >>> >>> IN your example, you are using a switch syntax that is nothing like that. I >>> think that your "case " statements are not actually evaluating the value of >>> $count, but are themselves evaluating to a true value that has nothing to do >>> with $count. >> >> That `switch` is evaluating to true each case. It's an alternative of using >> if-elseif structure. > > It may be an alternative, but it breaks the principle of least surprise. If > I'm looking through someone's code, and I see a switch, I expect to see it > used as Jim described. If the writer needs a different type of logic to make > a decision, that is what the cascaded if-elseif-elseif construct is for, when > the tests don't fall into a simple set-of-values choice. I don't see how it breaks the "principle of least surprise" (which is a new one on me. KISS, yes. Least surprise? Wassat?). If you consider that behaviour to be surprising the don't ever go near Perl. A switch statement is basically saying "take this value and compare it to each case below in the order they're presented until one matches, then execute that block of code until you hit a break which will jump execution out of the switch statement." I don't see how making "this value" true or false makes it any more surprising than if it's "squirlookle." > The job of a programmer is not to be "clever" with a view to impress those > who follow, but to achieve the desired outcome while at the same time making > life easy for those who follow. I don't consider that usage of the switch statement to be "clever." It's a valid usage of the statement which gives it a lot more power. Specifically the ability to have the code for a given case deliberately fall through to the next case block is worth any price of admission. And finally, in my opinion, it's far cleaner than a succession of if/elseif/else statements, and ultimately gets compiled to very similar opcodes. I agree that the job of a programmer is to balance providing a fast, efficient, correct solution and minimising maintenance issues. I see neither side being compromised by using a switch statement in this manner, in fact I see both sides potentially getting a boost. Just because the usage is unfamiliar or even surprising to you doesn't mean it's wrong. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date comparison going wrong, wrong, wrong
On 11 Nov 2012, at 19:24, "Terry Ally (Gmail)" wrote: > I reversed it as you suggested and every future show is displaying as having > ended. In that case the code you're showing us is not the code you're running, because that's the obvious error in test.php. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On 11 November 2012 19:11, Stuart Dallas wrote: > Please include the list when replying. > > On 11 Nov 2012, at 19:08, "Terry Ally (Gmail)" wrote: > > > What I want is the reverse. > > > > I want that if people attempt to access the show page after the show has > > ended that it triggers an error which takes it to another page. The actual > > conditional statement is as follows (which I will replace with timestamp): > > > > $todaydate = date("D, M jS, Y g:i:s a"); > > $showenddate = date("D, M jS, Y g:i:s a", > > strtotime($showsRecord['end_date'])); > > if ($todaydate > $showenddate) { > > header( 'Location: eventdetails_error.php' ) ; > > } > > This is what you have: > > if ($todaydate > $showenddate): > echo "The date of the show has not yet arrived"; > else: > echo "The show has ended"; > endif; > > That says: if the current time is later than the end date of the show, tell > them the date of the show hasn't arrived yet. > > What you mean is: if the current time is later than the end of the show, tell > them the show has ended. > > if ($todaydate < $showenddate): > echo "The date of the show has not yet arrived"; > else: > echo "The show has ended"; > endif; > > It's a simple logic error. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > > > On 11 November 2012 19:04, Stuart Dallas wrote: > > On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)" wrote: > > > > > Hi Shiplu and Stuart, > > > > > > Comparing timestamps was my first option. I've reinstated it. Have a look > > > at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you > > > will see that PHP is still outputting the wrong thing. > > > > > > I just can't figure out what's wrong. > > > > Your comparison is backwards: > > > > if ($todaydate > $showenddate): > > > > should be > > > > if ($todaydate < $showenddate): > > > > -Stuart > > > > -- > > Stuart Dallas > > 3ft9 Ltd > > http://3ft9.com/ > > > > > On 11 November 2012 18:48, shiplu wrote: > > > > > >> You can always use timestamp which is integer. > > >> > > >> $todaydate = time(); > > >> $showenddate = strtotime($showsRecord['end_date']); > > >> > > >> > > >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) > > >> wrote: > > >> > > >>> Hi all, > > >>> > > >>> I am having a problem with comparing time. I am using the following: > > >>> > > >>> $todaydate = date("D, M jS, Y g:i:s a"); > > >>> $showenddate = date("D, M jS, Y g:i:s a", > > >>> strtotime($showsRecord['end_date'])); > > >>> > > >>> if ($todaydate > $showenddate): > > >>>echo "The date of the show has not yet arrived"; > > >>> else: > > >>>echo "The show has ended"; > > >>> endif; > > >>> > > >>> The problem that I am encountering is that PHP is rendering the reverse > > >>> of > > >>> the equation. For example: > > >>> > > >>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov > > >>> 2012*, > > >>> the message that I am getting is *the show has ended* which is wrong. A > > >>> > > >>> test example is at http://www.lakesidesurrey.co.uk/test.php. > > >>> > > >>> You can also me what I am doing wrong? > > >>> > > >>> Thanks > > >>> Terry > > >>> > > >> > > >> > > >> > > >> -- > > >> Shiplu.Mokadd.im > > >> ImgSign.com | A dynamic signature machine > > >> Innovation distinguishes between follower and leader > > >> > > >> > > > > > > > > > -- > > > *Terry Ally* > > > Twitter.com/terryally > > > Facebook.com/terryally > > > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > > > To print or not to print this email is the environmentally-searching > > > question! > > > Which has the highest ecological cost? A sheet of paper or constantly > > > switching on your computer and connecting to the Internet to read your > > > email? > > > > > > > > > > -- > > Terry Ally > > Twitter.com/terryally > > Facebook.com/terryally > > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > > To print or not to print this email is the environmentally-searching > > question! > > Which has the highest ecological cost? A sheet of paper or constantly > > switching on your computer and connecting to the Internet to read your > > email? > > > > > > > -- > Terry Ally > Twitter.com/terryally > Facebook.com/terryally > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > To print or not to print this email is the environmentally-searching question! > Which has the highest ecological cost? A sheet of paper or constantly > switching on your computer and connecting to the Internet to read your email? >
Re: [PHP] Date comparison going wrong, wrong, wrong
Please include the list when replying. On 11 Nov 2012, at 19:08, "Terry Ally (Gmail)" wrote: > What I want is the reverse. > > I want that if people attempt to access the show page after the show has > ended that it triggers an error which takes it to another page. The actual > conditional statement is as follows (which I will replace with timestamp): > > $todaydate = date("D, M jS, Y g:i:s a"); > $showenddate = date("D, M jS, Y g:i:s a", > strtotime($showsRecord['end_date'])); > if ($todaydate > $showenddate) { > header( 'Location: eventdetails_error.php' ) ; > } This is what you have: if ($todaydate > $showenddate): echo "The date of the show has not yet arrived"; else: echo "The show has ended"; endif; That says: if the current time is later than the end date of the show, tell them the date of the show hasn't arrived yet. What you mean is: if the current time is later than the end of the show, tell them the show has ended. if ($todaydate < $showenddate): echo "The date of the show has not yet arrived"; else: echo "The show has ended"; endif; It's a simple logic error. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On 11 November 2012 19:04, Stuart Dallas wrote: > On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)" wrote: > > > Hi Shiplu and Stuart, > > > > Comparing timestamps was my first option. I've reinstated it. Have a look > > at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you > > will see that PHP is still outputting the wrong thing. > > > > I just can't figure out what's wrong. > > Your comparison is backwards: > > if ($todaydate > $showenddate): > > should be > > if ($todaydate < $showenddate): > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > > > On 11 November 2012 18:48, shiplu wrote: > > > >> You can always use timestamp which is integer. > >> > >> $todaydate = time(); > >> $showenddate = strtotime($showsRecord['end_date']); > >> > >> > >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) > >> wrote: > >> > >>> Hi all, > >>> > >>> I am having a problem with comparing time. I am using the following: > >>> > >>> $todaydate = date("D, M jS, Y g:i:s a"); > >>> $showenddate = date("D, M jS, Y g:i:s a", > >>> strtotime($showsRecord['end_date'])); > >>> > >>> if ($todaydate > $showenddate): > >>>echo "The date of the show has not yet arrived"; > >>> else: > >>>echo "The show has ended"; > >>> endif; > >>> > >>> The problem that I am encountering is that PHP is rendering the reverse of > >>> the equation. For example: > >>> > >>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*, > >>> the message that I am getting is *the show has ended* which is wrong. A > >>> > >>> test example is at http://www.lakesidesurrey.co.uk/test.php. > >>> > >>> You can also me what I am doing wrong? > >>> > >>> Thanks > >>> Terry > >>> > >> > >> > >> > >> -- > >> Shiplu.Mokadd.im > >> ImgSign.com | A dynamic signature machine > >> Innovation distinguishes between follower and leader > >> > >> > > > > > > -- > > *Terry Ally* > > Twitter.com/terryally > > Facebook.com/terryally > > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > > To print or not to print this email is the environmentally-searching > > question! > > Which has the highest ecological cost? A sheet of paper or constantly > > switching on your computer and connecting to the Internet to read your > > email? > > > > > -- > Terry Ally > Twitter.com/terryally > Facebook.com/terryally > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > To print or not to print this email is the environmentally-searching question! > Which has the highest ecological cost? A sheet of paper or constantly > switching on your computer and connecting to the Internet to read your email? > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date comparison going wrong, wrong, wrong
On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)" wrote: > Hi Shiplu and Stuart, > > Comparing timestamps was my first option. I've reinstated it. Have a look > at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you > will see that PHP is still outputting the wrong thing. > > I just can't figure out what's wrong. Your comparison is backwards: if ($todaydate > $showenddate): should be if ($todaydate < $showenddate): -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On 11 November 2012 18:48, shiplu wrote: > >> You can always use timestamp which is integer. >> >> $todaydate = time(); >> $showenddate = strtotime($showsRecord['end_date']); >> >> >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) >> wrote: >> >>> Hi all, >>> >>> I am having a problem with comparing time. I am using the following: >>> >>> $todaydate = date("D, M jS, Y g:i:s a"); >>> $showenddate = date("D, M jS, Y g:i:s a", >>> strtotime($showsRecord['end_date'])); >>> >>> if ($todaydate > $showenddate): >>>echo "The date of the show has not yet arrived"; >>> else: >>>echo "The show has ended"; >>> endif; >>> >>> The problem that I am encountering is that PHP is rendering the reverse of >>> the equation. For example: >>> >>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*, >>> the message that I am getting is *the show has ended* which is wrong. A >>> >>> test example is at http://www.lakesidesurrey.co.uk/test.php. >>> >>> You can also me what I am doing wrong? >>> >>> Thanks >>> Terry >>> >> >> >> >> -- >> Shiplu.Mokadd.im >> ImgSign.com | A dynamic signature machine >> Innovation distinguishes between follower and leader >> >> > > > -- > *Terry Ally* > Twitter.com/terryally > Facebook.com/terryally > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > To print or not to print this email is the environmentally-searching > question! > Which has the highest ecological cost? A sheet of paper or constantly > switching on your computer and connecting to the Internet to read your > email? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php