|
Zorilla posted:I should have asked about =& specifically since I saw it here. I still can't quite figure out what it's supposed to do differently than = does. It makes a reference (which you can read about a few posts up..well the link in a few posts up). Objects by default are referenced just using =, but when a =& is done, they perform a clone (a shallow copy essentially...sometimes called a hard link). Think of it this way. $a = 1; $b =& $a; $b++; // $a will be 2 here. var_dump($a); if you did $b = $a, $a would still be 1. Instead of holding a value, it basically just links to another variable...a reference. It gets a bit more complicated when you start using references inside objects and passing in to functions, but it's pretty easy.
|
# ? Oct 18, 2008 00:50 |
|
|
# ? Jun 3, 2024 21:40 |
|
Oops, why didn't I see that link
|
# ? Oct 18, 2008 00:54 |
|
$a = 3; $b = $a; //$b is a copy of $a; $b++; //changing $b does not change $a echo "$a != $b"; //Prints 3 != 4 $a = 3; $b =& $a; //$b is a reference of $a; $b++; //changing $b DOES change $a echo "$a == $b"; //Prints 4 == 4 edit: gently caress BEATEN AGAIN YOU ASSHOLES. Atom fucked around with this message at 01:03 on Oct 18, 2008 |
# ? Oct 18, 2008 01:01 |
What type of situation would it be useful to use the =&? I understand what it does, I just don't understand why you would want that.
|
|
# ? Oct 18, 2008 01:40 |
|
fletcher posted:What type of situation would it be useful to use the =&? I understand what it does, I just don't understand why you would want that. If you wanted a function that could return two values, you couldn't in php, because each function can only return one value to its caller. The way to get around this would be to send in a pointer to the function as a parameter and allow changes to be done on that. I use pointer here as something that is assigned using the =&.
|
# ? Oct 18, 2008 01:42 |
sonic bed head posted:If you wanted a function that could return two values, you couldn't in php, because each function can only return one value to its caller. The way to get around this would be to send in a pointer to the function as a parameter and allow changes to be done on that. I use pointer here as something that is assigned using the =&. Ohhhhh that makes sense. Whenever I needed to do that I just returned an array with everything I need in it.
|
|
# ? Oct 18, 2008 01:48 |
|
sonic bed head posted:If you wanted a function that could return two values, you couldn't in php, because each function can only return one value to its caller. The way to get around this would be to send in a pointer to the function as a parameter and allow changes to be done on that. I use pointer here as something that is assigned using the =&. It also helps when you don't want your data being copied all over the place. Say you're operating on a huge array, and instead of passing it in to a function, you could reference it in. It also comes in very handy when you're using recursive functions.
|
# ? Oct 18, 2008 02:31 |
|
Edit: Oops, question already answered.
DaTroof fucked around with this message at 05:47 on Oct 18, 2008 |
# ? Oct 18, 2008 05:44 |
|
How can I make this simpler and or better?php:<? if($curr_sector < $start_of_line) $curr_sector = -1; elseif($curr_sector >= $start_of_line + $size) $curr_sector = -1; elseif($curr_sector > $end_sector) $curr_sector = -1;?>
|
# ? Oct 18, 2008 11:52 |
|
drcru posted:How can I make this simpler and or better? php:<? if(($curr_sector < $start_of_line) || ($curr_sector >= ($start_of_line + $size)) || ($curr_sector > $end_sector)) { $curr_sector = -1; } ?> (did you really intend the result of all three options to be the same?) Also consider if its simpler / clearer to test for the cases where you shouldn't be setting curr_sector to -1, and test for that negated: php:<? if(!(SIMPLER_CLAUSE)) { $curr_sector = -1; } ?> php:<? $val = myfunc(); if($val !== FALSE && YOUR_OTHER_TESTS_ARE_PASSED) { // use $val knowing its valid } ?> php:<? if(($curr_sector > $end_sector) || ($curr_sector < $start_of_line) || ($curr_sector >= ($start_of_line + $size))) { $curr_sector = FALSE; } ?> KuruMonkey fucked around with this message at 14:57 on Oct 18, 2008 |
# ? Oct 18, 2008 14:44 |
|
Just curious, Any Kohana Framework users here?
|
# ? Oct 18, 2008 18:24 |
|
Yup, I got a site running on Kohana 2.1 (that I have to probably upgrade to 2.2 soon) and a cms for said site in the works. It's a pretty sweet lil' framework.
|
# ? Oct 18, 2008 21:41 |
|
KuruMonkey posted:
Oh god, thanks. None of this was registering last night.
|
# ? Oct 19, 2008 01:33 |
|
OK, stumped myself again using mysql 4.1 I've sent data to the page via a form POST, and converted the POST results into variables I'm trying to run an UPDATE query with the data from the form using the following $sql = "UPDATE `projects` SET 'ProjName' = $name WHERE `Key` = $key123"; $result = mysql_query($sql) or die("Couldn't execute result query."); <---this is where I die I've verified that my variables are correct by running an echo on just them. Any ideas? vv Thank you. I never would have figured out the difference between ` and '. Grand Poobah fucked around with this message at 18:23 on Oct 25, 2008 |
# ? Oct 21, 2008 02:49 |
|
Your SQL looks a little off. Try this:php:<? $sql = "UPDATE `projects` SET `ProjName` = '$name' WHERE `Key` = '$key123'"; $result = mysql_query($sql) or die("Couldn't execute result query."); ?>
|
# ? Oct 21, 2008 08:03 |
|
Additionally, you could die with a more useful error:code:
|
# ? Oct 21, 2008 15:09 |
|
jschmidt posted:OK, stumped myself again Shouldn't you be escaping your php variables from the sql string? $sql = "UPDATE `projects` SET 'ProjName' = {$name} WHERE `Key` = {$key123}"; or alternatively $sql = "UPDATE `projects` SET 'ProjName' = ".$name." WHERE `Key` = ".$key123;
|
# ? Oct 21, 2008 17:58 |
|
H0TSauce posted:Shouldn't you be escaping your php variables from the sql string? If it's inside double quotes, "simple" variables will be replaced. Complex ones (array values, object properties) would need to be escaped, but not here.
|
# ? Oct 21, 2008 19:08 |
H0TSauce posted:Shouldn't you be escaping your php variables from the sql string? Use PDO so you can just write nice clean SQL statements, and you never have to worry about escaping a variable again. (this needs to be in the OP, this comes up time and time again) php:<? $query = $database->prepare("SELECT field FROM table WHERE other_field = :value"); $query->bindParam(":value", $whatever); ?>
|
|
# ? Oct 21, 2008 19:25 |
|
mysqli also supports prepared statements, but yes prepared statements are the way to go.
|
# ? Oct 21, 2008 19:39 |
|
Are there any extremely light-weight CMS systems that are easy to modify to fit in to an existing framework? Things I am looking for: Very simple user table (accountId, Username, Password, Email, Access) so it can just use the existing one News posts/static pages (updates / information pages) Article types with varying access requirements and an easy way for admins to revert edits (wiki-like system for documentation) Loads a php file and passes it an array or object with page information (no smarty, no intricate templating systems) All requirements don't have to be met. I know I am going to have to modify whatever I do choose to use. I cringe at the sight of most CMS systems I've checked out. TikiWiki and MediaWiki are bloated and geared more toward lame wiki sites than practical applications. Most of the smaller CMS projects seem poorly implemented or downright bad. I'm fairly close to coding it myself, but it's a bad idea for me to take on another project. I have far too many left unfinished and an ever decreasing amount of free time.
|
# ? Oct 23, 2008 19:42 |
|
Khorne posted:TikiWiki and MediaWiki Have you looked at DokuWiki? I know it's not really a CMS, but neither are those, and it's pretty easy to set up and use. Edit: http://www.dokuwiki.org/
|
# ? Oct 23, 2008 20:17 |
|
fletcher posted:Use PDO so you can just write nice clean SQL statements, and you never have to worry about escaping a variable again. (this needs to be in the OP, this comes up time and time again) I assume PDO cleans bound parameters of nasties, or must one still do that manually?
|
# ? Oct 23, 2008 20:25 |
|
Lumpy posted:I assume PDO cleans bound parameters of nasties, or must one still do that manually? It cleans them for you.
|
# ? Oct 23, 2008 21:29 |
|
Munkeymon posted:Have you looked at DokuWiki? I know it's not really a CMS, but neither are those, and it's pretty easy to set up and use.
|
# ? Oct 23, 2008 22:15 |
|
cka posted:Yup, I got a site running on Kohana 2.1 (that I have to probably upgrade to 2.2 soon) and a cms for said site in the works. It's a pretty sweet lil' framework. Have you used CodeIgniter before? Do you feel that there are that many advantages to Kohana's strict PHP5 framework vs CodeIgniter's which supports both PHP4 and 5? How often is Kohana updated? I always wanted to transfer over to Kohana but was always worried about the project being abandoned.
|
# ? Oct 24, 2008 19:07 |
|
So I'm working with a guy to make a site for the use of people in the musician's lounge subforum. The guy I'm working with got a SA authentication script from the gbsfm guys. At first glance it looks pretty solid, but I can't get it to correctly set the cookies necessary so that the script can check a user's profile for the auth key. So here's the relevant portion of the script (I hope this isn't crossing any lines with the gbsfm crew): php:<? # The user we want to check, and they key to check $user = stripslashes('roctor'); $key = '36188438ac1d50cfb5eb7ae34882b988'; # SA parameters. Use your SA user ID and the md5 hash of your password # This is the user ID of my gimmick account, $sauserid = '83280'; $sapasswordhash = '(my password hash)'; # Setup values to use in the CURL operation $url = "http://forums.somethingawful.com/member.php?s=&action=getinfo&username=".urlencode(stripslashes($user)); $cookie = "bbuserid=$sauserid;bbpassword=$sapasswordhash"; # These aren't necessary, but it helps to prevent setting off any alarms $useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0'; $referer = 'http://forums.somethingawful.com/usercp.php?s='; # Initialize CURL and start collecting the output buffer $ch = curl_init(); ob_start(); # Setup CURL options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_REFERER, $referer); # Execute and close CURL curl_exec($ch); # Get the returned HTTP text and release the output buffer $response = ob_get_contents(); ob_end_clean(); ?> I'm kind of at a loss about how to get the verification working correctly since there's not really a whole lot of easy to find documentation out there. Anybody know what I'm doing wrong here? Could it be some sort of server configuration? If it's any help, the script is currently up at https://www.musicianslounge.org/test
|
# ? Oct 24, 2008 22:34 |
|
Roctor posted:So I'm working with a guy to make a site for the use of people in the musician's lounge subforum. The guy I'm working with got a SA authentication script from the gbsfm guys. At first glance it looks pretty solid, but I can't get it to correctly set the cookies necessary so that the script can check a user's profile for the auth key. Contact r1ch and use his AuthDB system instead of trying to scrape the forums yourself.
|
# ? Oct 25, 2008 00:55 |
|
duz posted:Contact r1ch and use his AuthDB system instead of trying to scrape the forums yourself. Nothing makes me happier than this. Thanks for the link/referral.
|
# ? Oct 25, 2008 01:00 |
duz posted:Contact r1ch and use his AuthDB system instead of trying to scrape the forums yourself. I'm confused, this requires a user to enter in their SA password? Or is the 'pass' that you post just whatever code you are looking for in the profile?
|
|
# ? Oct 25, 2008 01:09 |
|
fletcher posted:I'm confused, this requires a user to enter in their SA password? Or is the 'pass' that you post just whatever code you are looking for in the profile? I contacted r1ch earlier and he told me it's the user's alluvian.org password.
|
# ? Oct 25, 2008 02:58 |
|
fletcher posted:I'm confused, this requires a user to enter in their SA password? Or is the 'pass' that you post just whatever code you are looking for in the profile? Here's an example of another site that uses this. You must have an Alluvion account, which only requires that you put something in your SA profile to verify. No entering of your SA password anywhere. So yeah, two separate accounts.
|
# ? Oct 25, 2008 03:03 |
|
Strong Sauce posted:Have you used CodeIgniter before? Do you feel that there are that many advantages to Kohana's strict PHP5 framework vs CodeIgniter's which supports both PHP4 and 5? How often is Kohana updated? I always wanted to transfer over to Kohana but was always worried about the project being abandoned. Nah, I haven't really used CI. I read up on a few frameworks and decided on Kohana cause it was strictly written for PHP5, which is fine since that's what we're running on our server (and it seemed like the easiest to get my project off the ground with.) For the most part, Kohana is really easy to work with, and while the documentation isn't as stellar as I'd like it to be it does the job (as does their forum.) What I like about it so far, and I'm not sure if CI has this functionality too, is that I can override core functionality easily with my own libraries. I have my own default controller class that handles session stuff and authorization with users in a vBulletin database in the CMS I talked about. The big problem with it right now is that it's still in a wild state of development -- they changed a bunch of the core functionality between 2.1 and 2.2, and nothing really feels concrete in it still since there seems to be even more core changes in the 2.3 svn version. My site uses some on-the-fly routing with the _default() class function, which is one of those major changes they made in 2.2. That's partially why I've stuck with 2.1 so far (the other reasons being I've been busy with my other, real job and extreme laziness/procrastination in my spare time.) Plus, if it ain't broke... I don't think you have to worry about it being abandoned, but if you did want to switch over I'd follow their update trac/changelogs for awhile to make sure they aren't drastically changing how core functionality works.
|
# ? Oct 25, 2008 23:34 |
|
cka posted:Nah, I haven't really used CI. I read up on a few frameworks and decided on Kohana cause it was strictly written for PHP5, which is fine since that's what we're running on our server (and it seemed like the easiest to get my project off the ground with.) For the most part, Kohana is really easy to work with, and while the documentation isn't as stellar as I'd like it to be it does the job (as does their forum.) What I like about it so far, and I'm not sure if CI has this functionality too, is that I can override core functionality easily with my own libraries. I have my own default controller class that handles session stuff and authorization with users in a vBulletin database in the CMS I talked about.
|
# ? Oct 26, 2008 02:08 |
|
I'm using imagepng to create PNGs out of code into a certain directory. That all works fine, but why on the page where i use imagepng it spits out weird characters and how do I get rid of them? To see what I mean, just draw some nonsensical thing on the page, type in the CAPTCHA and then the page where it says it was successful shows that mess. Just to let you know, depending what people have made, might be considered not work safe. But they are just pixelated small images. http://www.majoroutput.com/TestMOCode2/index.php edit: I don't know if there's any alternate way of using it, but here's the line of code: imagepng($thumb, "blocks/".$numOfFiles.".png"); If I get rid of that, it takes away the characters. LP0 ON FIRE fucked around with this message at 02:25 on Oct 26, 2008 |
# ? Oct 26, 2008 02:19 |
|
awdio posted:I'm using imagepng to create PNGs out of code into a certain directory. That all works fine, but why on the page where i use imagepng it spits out weird characters and how do I get rid of them? php:<? ob_start(); imagepng($thumb, "blocks/".$numOfFiles.".png"); ob_end_clean(); ?>
|
# ? Oct 26, 2008 03:19 |
|
Internet Headache posted:I'm not sure why imagepng would function that way. As a short-term hack for a library of hacks, you could use output buffering around the function and just dump the contents. Excellent! It works, thank you.
|
# ? Oct 26, 2008 03:51 |
|
Internet Headache posted:
Apropos of nothing, please, don't do that. Fan out your directories, don't put everydamnthing in one directory. readdir() calls will start beating the hell out of your performance. A better way would be, let's say $numOfFiles is 38234234, write it to: blocks/038/234/234.png Storage, especially if/when you get to the point where you're using shark/netapp/isilon/whatever, is going to plotz if it has to stat() across a directory of 10000+ files. Try to keep it around 1-2k, you're golden, and really, it can scale forever. (Ex: 3823423482340238423.png translates to 003/823/423/482/340/238/423.png), and you're looking at, max, around 2k entries per directory, which about any OS or storage system should be able to handle File size versus FS sector size being left as a discussion for later, as is the extended cost of walking up that whole directory tree.
|
# ? Oct 26, 2008 17:42 |
|
dagard posted:Apropos of nothing, please, don't do that. Fan out your directories, don't put everydamnthing in one directory. readdir() calls will start beating the hell out of your performance. A better way would be, let's say $numOfFiles is 38234234, write it to: Thanks. Yes, it will eventually go to different directories. I never thought of the way you suggested, so thank you. edit: Isn't that scaling way further into the trillions of possible files? LP0 ON FIRE fucked around with this message at 00:07 on Oct 27, 2008 |
# ? Oct 26, 2008 21:09 |
|
|
# ? Jun 3, 2024 21:40 |
|
With an array like this:php:<? Array ( [0] => Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => -1 ) [1] => Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => -1 ) [2] => Array ( [0] => -1 [1] => -1 [2] => 1 [3] => 2 [4] => 3 ) [3] => Array ( [0] => -1 [1] => -1 [2] => 26 [3] => 27 [4] => 28 ) [4] => Array ( [0] => -1 [1] => -1 [2] => 51 [3] => 52 [4] => 53 ) )?>
|
# ? Oct 27, 2008 00:47 |