|
Just to add further: code:
I assume then, that there's something preventing PDO variables from being reused? Again, I still don't understand what/why. Edit: Looks like I may have found the problem - http://bugs.php.net/bug.php?id=38861 Stephen fucked around with this message at 21:55 on Jul 11, 2008 |
# ? Jul 11, 2008 21:49 |
|
|
# ? May 16, 2024 18:35 |
|
drcru posted:So I'm trying to implement Dijkstra's algorithm for a side project I'm working on but I'm having difficulty grasping how the whole thing works... I've done this before but I don't have the code in front of me, so bear with me. But yes, I made the "sectors" or "room" the vertices and then had a separate table that acted as vertices/paths. The main drawback with my method was that one had to have the entire graph in memory, which was a bit of a downer when you only wanted to go across to the next node. If you haven't got working code, this might help: http://en.giswiki.net/wiki/Dijkstra's_algorithm
|
# ? Jul 13, 2008 14:38 |
|
I've got a bit of an issue with setting up a mail server with multiple levels (Squirrelmail, Postfix, Dovecot). Right now, I have a single login page that redirects to the proper site based on the "level" set in MySQL. The problem is that after the user is logged in, all they have to do is change the URL to access any other level. I'm passing the username and password in a hidden POST to Squirrelmail, and I think the issue is that it's retaining the POST variables. Is there any way to clear them?
|
# ? Jul 14, 2008 16:29 |
|
I was transferring working code to another server and presto it decided that it no longer wants to work. Here it is working NWS (no bad pictures but those words might get you) http://www.willworkforpie.com/theproject/index.php NWS and here it is breaking NWS (same reason as before) http://www.peoplepersonporn.com/ NWS As you can see if you go to the broken website it spews out Warning: Cannot modify header information - headers already sent by (output started at /f1/content/peopleperson/public/index.php:5) in /f1/content/peopleperson/public/index.php on line 103 (bottom of the code, setcookie...) How can I fix it while still ensuring the cookies get set? Oh and if you see anything horribly inefficient please do tell me. code:
|
# ? Jul 14, 2008 16:48 |
|
Put ob_start(); as the first line of the page and ob_end_flush(); as the last one. Should work.
|
# ? Jul 14, 2008 17:01 |
|
I had tried it before and it didn't work, I tried it again and.... still didn't work =/. EDIT I'm an idiot, it works thank you. Duck and Cover fucked around with this message at 06:40 on Jul 15, 2008 |
# ? Jul 14, 2008 17:22 |
|
LightI3ulb posted:I've got a bit of an issue with setting up a mail server with multiple levels (Squirrelmail, Postfix, Dovecot). Right now, I have a single login page that redirects to the proper site based on the "level" set in MySQL. The problem is that after the user is logged in, all they have to do is change the URL to access any other level. Why not just use a LoggedIn session variable?
|
# ? Jul 14, 2008 18:27 |
|
How would I check in PHP if a string exists as a variable? isset will only tell me if a variable exists, and does not accept a string as a parameter.
|
# ? Jul 14, 2008 21:10 |
Stephen posted:How would I check in PHP if a string exists as a variable? isset will only tell me if a variable exists, and does not accept a string as a parameter. php:<? $var = "hello"; $varName = "var"; if (isset($$varName)) //this is like writing if (isset($var)) echo $var; ?>
|
|
# ? Jul 14, 2008 21:22 |
|
Stephen posted:How would I check in PHP if a string exists as a variable? isset will only tell me if a variable exists, and does not accept a string as a parameter. php:<?php $foo = "bar"; $baz = "foo"; // the name of the variable you want to check. if (isset($$baz)) ... ?> e: f;b
|
# ? Jul 14, 2008 21:22 |
|
Stephen posted:How would I check in PHP if a string exists as a variable? isset will only tell me if a variable exists, and does not accept a string as a parameter.
|
# ? Jul 14, 2008 21:58 |
|
waffle iron posted:While the solutions above are right, it makes me wonder if the real problem isn't the architecture of the code. If you're using register globals that's probably a bad idea. If you just need arbitrary data storage with string names, a better idea would be to use associative arrays (i.e. $data["foo"]). Sort of what CakePHP does with their html helper. e.g. code:
|
# ? Jul 14, 2008 22:15 |
|
Evil Angry Cat posted:Put ob_start(); as the first line of the page and ob_end_flush(); as the last one. Should work. I apparently did not read carefully. First line of the page means just that before everything, even the html etc. I in my brilliant fashion decided it meant the first line of php code. Thank you it works now. Duck and Cover fucked around with this message at 06:40 on Jul 15, 2008 |
# ? Jul 15, 2008 00:38 |
|
I've been browsing and I can't make sense of how to get my CSV file into an array so I can begin working with the data in the script. The file is uploaded fine and the location of the file is in $file, I then want something like $Col1[0] $Col2[0] and $Col3[0] respectively with the 200 or so rows that are in the file.
|
# ? Jul 15, 2008 01:36 |
|
Safety Shaun posted:I've been browsing and I can't make sense of how to get my CSV file into an array so I can begin working with the data in the script. http://us3.php.net/fgetcsv should do the trick. php:<?php $fh = fopen($file, "r"); $data = array(); $titles = fgetcsv($fh, 1000, ','); // you can skip this to have the column // titles be $data[0] while (($data[] = fgetcsv($fh, 1000, ',')) !== FALSE) { ... } fclose($fh); ?> jasonbar fucked around with this message at 01:51 on Jul 15, 2008 |
# ? Jul 15, 2008 01:39 |
|
jasonbar posted:http://us3.php.net/fgetcsv should do the trick. Excellent! Now I have this output: php:<? $row = 1; $handle = fopen($loc, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); ?> php:<? 3 fields in line 1: STRING 1 STRING 2 STRING 3 3 fields in line 2: STRING A STRING B STRING C ?>
|
# ? Jul 15, 2008 02:25 |
Safety Shaun posted:Excellent! Your first question could have been answered by googling "php csv" (fgetcsv is the FIRST RESULT). Now you have copied and pasted the example code from that page and asked another extremely basic question that you should be able to figure out on your own. Either pay somebody to write this script for you or actually take the time to learn how to write it.
|
|
# ? Jul 15, 2008 02:32 |
|
fletcher posted:Your first question could have been answered by googling "php csv" (fgetcsv is the FIRST RESULT). Now you have copied and pasted the example code from that page and asked another extremely basic question that you should be able to figure out on your own. Either pay somebody to write this script for you or actually take the time to learn how to write it. This is a place for people to ask for help and some people are very helpful.
|
# ? Jul 15, 2008 02:41 |
|
Safety Shaun posted:This is a place for people to ask for help and some people are very helpful. In the long run, people making you learn on your own are more helpful than those doing your homework.
|
# ? Jul 15, 2008 02:48 |
|
Safety Shaun posted:I'm learning. So gently caress off jerkbag. Come on, man. You're not even trying. Your previous post seems to indicate that you know how an array works, so how can you not be able to figure out what you want to do from the example you copied? Here's a hint: $data is an array of the columns.
|
# ? Jul 15, 2008 04:16 |
|
DaTroof posted:Come on, man. You're not even trying. Your previous post seems to indicate that you know how an array works, so how can you not be able to figure out what you want to do from the example you copied? Thank you. I'm not sure if this was the easiest way to go about it but it works for me: php:<? while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $row++; for ($c=0; $c < $num; $c++) { $entry[$row-1][$c+1] = $data[$c]; //this line } } ?>
|
# ? Jul 15, 2008 04:48 |
|
I'm trying to crawl a webpage using file_get_contents(), but it is giving me a 403 error. If I copy the exact same URL that the function is betting to a webbrowser, the page loads fine, but in PHP I get this error: Warning: file_get_contents(http://gc.kls2.com/airport/HECA) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /var/www/logbook/classes/map_class.php on line 252 I assume the site owner has some anti-spam thing in place which is why I'm blocked. Is there any way around this? This particular function is only going to be ran once or twice a month, so its not like I'm going to be overloading the site's bandwidth... nbv4 fucked around with this message at 06:38 on Jul 16, 2008 |
# ? Jul 16, 2008 06:32 |
|
nbv4 posted:I'm trying to crawl a webpage using file_get_contents(), but it is giving me a 403 error. If I copy the exact same URL that the function is betting to a webbrowser, the page loads fine, but in PHP I get this error: They are clearly trying to block what you are attempting. However, to answer your question: php:<?php // Use any useragent string you want. ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0'); var_dump(file_get_contents('http://gc.kls2.com/airport/HECA')); ?>
|
# ? Jul 16, 2008 07:01 |
|
jasonbar posted:This worked for me - please only use it for good. sweeeet, that worked. I won't be bad I promise. Bandwidth usage from this script will probably amount to a few hundred KB's per month.
|
# ? Jul 16, 2008 08:28 |
|
Is there any good reason why implode() has to take an array? IE, why this:code:
Seriously, I want to know if I missed some blatantly obvious reason. I'm a Perl guy (yeah, I know, burn the heretic), not a PHP guy, I just have to deal with it a lot at work.
|
# ? Jul 16, 2008 12:05 |
|
dagard posted:Is there any good reason why implode() has to take an array? IE, why this: Take a look at its syntax here. It expects exactly two parameters as input. Parameter one is the glue string (such as a comma) and parameter two is a set of strings you wish to implode. I think it's a good way of doing things because it allows future versions of PHP to expand functionality by possibly allowing extra parameters after the second one. Zorilla fucked around with this message at 12:25 on Jul 16, 2008 |
# ? Jul 16, 2008 12:19 |
|
dagard posted:Is there any good reason why implode() has to take an array? IE, why this: The reason that won't work is that in your example you are giving implode 5 parameters when it is expecting two.
|
# ? Jul 16, 2008 12:20 |
|
dagard posted:Is there any good reason why implode() has to take an array? IE, why this: func_get_args() has to be called explicitly to do it "the Perl way". php:<? function perl_implode() { $args = func_get_args(); $glue = array_shift($args); return implode($glue, $args); } perl_implode('|', 'A', 'B', 'C', 'D', etc..); ?>
|
# ? Jul 16, 2008 12:27 |
|
Does anyone have any idea on how to efficiently create a random maze via PHP? I found this one but I'm not quite sure on how to make it better. It takes quite awhile for it to make 20x20 maze as it seems to make them by going through every cell in the grid. Anyone happen to know the name of the formula that makes up a maze?
|
# ? Jul 17, 2008 12:06 |
|
drcru posted:Does anyone have any idea on how to efficiently create a random maze via PHP? Google says: http://en.wikipedia.org/wiki/Maze_generation_algorithm. Seems like Kruskal or Prim will be your friends.
|
# ? Jul 17, 2008 19:17 |
|
drcru posted:Does anyone have any idea on how to efficiently create a random maze via PHP? A much faster maze generation algorithm is Eller's algorithm. The mazes might not be quite as pretty or have as nice properties, but it is perfect, and it's easy to do efficiently-- I used it to do maze generation in TI-89 BASIC, using only a few single-dimensional arrays and integers. The idea is that you generate and output the maze one line at a time-- there's a good summary at http://www.astrolog.org/labyrnth/algrithm.htm (Ctrl-F Eller) The mazes are pretty good if you tweak it properly. Scaevolus fucked around with this message at 08:49 on Jul 18, 2008 |
# ? Jul 18, 2008 08:45 |
|
How do I pause a PHP script? I've played with the sleep(); function, but it seems to 'lock' the rendering of the page until the sleep timer is up. I want to set variables -> render a web page -> *wait 2 minutes* -> then execute code using the variables set earlier. Is this possible?
|
# ? Jul 18, 2008 20:37 |
Treytor posted:How do I pause a PHP script? I've played with the sleep(); function, but it seems to 'lock' the rendering of the page until the sleep timer is up. After you render the page, insert a new row into a table with a timestamp and whatever variables you need for the script. Setup a cron job to run ever minute or something, and it just queries that table and looks for any jobs it needs to complete. They're not directly connected, but one sets up the other.
|
|
# ? Jul 18, 2008 20:44 |
|
Couldn't you use fork and have the child process sleep for 2 minutes?
|
# ? Jul 18, 2008 22:31 |
|
edit: nvm edit: not nevermind call flush() right before you call sleep() - although if you are doing any onload stuff, it won't ever happen until 2 minutes later. php:<?php ... flush(); sleep($x); ... ?> jasonbar fucked around with this message at 22:57 on Jul 18, 2008 |
# ? Jul 18, 2008 22:37 |
Avenging Dentist posted:Couldn't you use fork and have the child process sleep for 2 minutes? What about when the server crashes, how do you know which ones were sleeping and haven't been completed yet? (if that is a concern of his)
|
|
# ? Jul 18, 2008 23:44 |
|
Thanks again for your feedback, guys. I don't really understand that fork thing, but am willing to give it a shot (I'm very new to PHP). This application is not mission critical, so worrying about server crashes is minimal. I've also tried the flush(); thing, but that's still preventing the page from loading. Here is what I have: code:
EDIT: I don't have terminal access or to a cron job, as this is fairly basic web hosting. A cron wouldn't be frequest enough, anyway as I want this to run exactly 2 minutes after page load. With a cron, there could be a minute delay if they page load right after the last cron goes through. Treytor fucked around with this message at 00:27 on Jul 19, 2008 |
# ? Jul 19, 2008 00:24 |
|
Treytor posted:I've also tried the flush(); thing, but that's still preventing the page from loading. No sir, flush AFTER the html, right BEFORE the sleep(). Here is a working example: http://burntmail.net/flush.php
|
# ? Jul 19, 2008 00:30 |
|
jasonbar posted:No sir, flush AFTER the html, right BEFORE the sleep(). Here is a working example: http://burntmail.net/flush.php Would PHP being in safe mode interfere with this at all? Your script works perfectly on your page (obviously), but if I copy that code exactly and run it on mine, the page doesn't load until after sleep is done.
|
# ? Jul 19, 2008 01:05 |
|
|
# ? May 16, 2024 18:35 |
|
Treytor posted:Would PHP being in safe mode interfere with this at all? Your script works perfectly on your page (obviously), but if I copy that code exactly and run it on mine, the page doesn't load until after sleep is done. mod_gzip being enabled will result in that not working. Others have had mixed success using a combination of ob_start(), ob_end_flush() and flush(). You can try: php:<?php // your html ob_end_flush(); // note that you need not call ob_start() flush(); sleep(5); ?> code:
|
# ? Jul 19, 2008 02:14 |