|
Lankiveil posted:What is the current cool framework to use for PHP? At the moment I'm playing with CodeIgniter, but I'm happy to jump ship if there's something better out there. If you like CodeIgnitor, check out Kohana. It's a PHP5 based framework originally built from CI, but completely rewritten to take advantage of PHP5's 'features'. It is a really robust framework and I use it all the time in my projects. https://www.kohanaphp.com
|
# ? Nov 26, 2008 01:45 |
|
|
# ? May 16, 2024 07:29 |
|
Anveo posted:If you are going to look into it, you will probably want to start with version 1.2. I've just had a quick look through the docs, and it actually looks fairly good. I'll have a bit of a play with this, thanks for the tip!
|
# ? Nov 26, 2008 13:14 |
|
duz posted:Commonly request scripts These have been checked for security Does anyone bother altering HTTP status codes for errors? Taking R1CH's upload script for example: php:<? header('HTTP/1.1 503 Service Unavailable'); die ("..."); ... header('HTTP/1.1 400 Bad Request'); $error = "Upload failed, please check the filename and try again."; ... header('HTTP/1.1 413 Request Entity Too Large'); $error = "File size exceeded, maximum allowed file is {$config['max_size']}... ... header('HTTP/1.1 500 Internal Server Error'); $error = "Internal error, unable to open uploaded file."; ?> php:<? header('HTTP/1.1 415 Unsupported Media Type'); $error = "Unknown file format, only JPEG, PNG and GIF files are allowed."; ?> php:<? header('HTTP/1.1 409 Conflict'); $error = 'File already uploaded'; ?> php:<? header('HTTP/1.1 410 Gone'); $error = 'File has been removed'; ?> php:<? header('HTTP/1.1 201 Created'); ?> <p>Your file was uploaded successfully.</p> ... ?> Is this only really useful if a program is going to interact with a webservice so they don't have to scrape? In the meantime, enjoy a set of icons representing HTTP status codes on Flickr: http://www.flickr.com/photos/apelad/sets/72157594388426362/
|
# ? Nov 27, 2008 13:12 |
|
I've been having a hell of a time getting this to work properly and it still isn't quite doing what I've been wanting it to. I've been lately working with MySQLI and for the life of me I cannot get it to sort by what I want using variables.php:<? $result = mysqli_prepare($dbh, "SELECT * FROM vidinfo ORDER BY ? LIMIT ?, 15"); mysqli_stmt_bind_param($result, "si", $sort, $limit); mysqli_stmt_execute($result); mysqli_stmt_bind_result($result, $id, $path, $vwidth, $vheight, $title, $author, $game, $fore, $back, $dnd, $uploader); ?> Here's the fetch: php:<? while (mysqli_stmt_fetch($result)) ?> Edit: Some solutions I've come up with are to just make a ton of if's (looks ugly, would rather not resort to that) or maybe try: php:<? $result = mysqli_prepare($dbh, "SELECT * FROM vidinfo ORDER BY ".$sort." LIMIT ?, 15"); ?> Static_Fiend fucked around with this message at 04:14 on Nov 28, 2008 |
# ? Nov 28, 2008 03:13 |
|
MrMoo posted:Does anyone bother altering HTTP status codes for errors? Taking R1CH's upload script for example: Yes, I use some obscure status codes (402 and 405, for instance) for things like malformed requests or unsupported requests. Perhaps not so useful for screenscrapers (who are the only ones who usually do these things), but useful for log tracking to see what bots are getting up to.
|
# ? Nov 28, 2008 06:01 |
|
Static_Fiend posted:stuff Edit: Nevermind. You cannot use bind_param for returning results. You can only use it for INSERT, UPDATE, and DELETE requests. What you're looking for is bind_result: http://us3.php.net/manual/en/mysqli-stmt.bind-result.php Mackerel, the Thief fucked around with this message at 07:56 on Nov 28, 2008 |
# ? Nov 28, 2008 07:47 |
|
Lankiveil posted:Yes, I use some obscure status codes (402 and 405, for instance) for things like malformed requests or unsupported requests. I just tried a 502 and PHP trimmed off the entity content, so if it's the same with many of the other codes it's pretty much impossible to use them for direct browser facing resources. (edit) also 504 munged, and to quite a problem 413 is munged too. 500 and other 4xx codes seem to go through. MrMoo fucked around with this message at 08:07 on Nov 28, 2008 |
# ? Nov 28, 2008 07:58 |
|
Mackerel, the Thief posted:Edit: Nevermind. You cannot use bind_param for returning results. You can only use it for INSERT, UPDATE, and DELETE requests. What you're looking for is bind_result: http://us3.php.net/manual/en/mysqli-stmt.bind-result.php Edit: Nevermind, documentation for mysqli_prepare told me what's up: quote:However, they are not allowed for identifiers (such as table or column names), in the select list that names the columns to be returned by a SELECT statement, or to specify both operands of a binary operator such as the = equal sign. So basically what I'm trying to do won't fly with this, ah well, guess I'm gonna have to do it another way. Static_Fiend fucked around with this message at 10:12 on Nov 28, 2008 |
# ? Nov 28, 2008 09:25 |
|
I'm having trouble with PHP and SOAP. The company whose server we are trying to access has sent us a sample soapclient script that they wrote using PHP4 and NuSoap that they claim works on their end. Our shop is PHP5, so I decide to convert the thing to use PHP5's SoapClient. This is where I stand. I can connect to the SOAP Server fine. However, it keeps telling me that it is unable to parse the XML I'm sending it. To see if my server is misconfigured, I copy the script locally to my own machine and try it again. No dice. Out of curiosity, I wireshark the packets being sent to it, and I find out that indeed, the XML body is nowhere to be found. At this point, I figure that my inexperience with SOAP in general has caused me to cock up something somewhere along the line. So I decide to download NuSOAP for PHP5, modify the script they gave me to account for the class naming fuckery, and give it a shot. Strangely enough, although the script works fine, I get the exact same XML parsing error, and sure enough upon wiresharking the outgoing packets the XML body is nowhere to be found; this time in a script that they claim works on their end. I'm now at a loss. I have zero prior experience with SOAP, so I don't even know how to begin to figure out what's wrong, but something tells me that it's not my code that's the problem, instead there is some configuration setting I have to toggle, since both scripts are being wonky in the exact same way. What is going on here?
|
# ? Nov 28, 2008 17:10 |
|
The posting URL needs to point to a WSDL document; where I work, our customers give us URL's that look like this http://soap.example.com/post.asmx but what you want is http://soap.example.com/post.asmx?WSDL That might not be what's going on with you, but it's gotten me plenty of times.
|
# ? Nov 28, 2008 17:22 |
|
royallthefourth posted:The posting URL needs to point to a WSDL document; where I work, our customers give us URL's that look like this Yep, that looks like the URL that I post to, but thanks. Also, keep in mind that they claim that the script they gave me worked on their end, but when I tried it, I ran into the same problem as doing it using PHP5's SoapClient.
|
# ? Nov 28, 2008 17:27 |
|
Are you creating the SoapClient from a remote WSDL file or something local? Try downloading the WSDL and pointing the SoapClient at the local WSDL file instead?
|
# ? Nov 30, 2008 01:33 |
|
gibbed posted:Are you creating the SoapClient from a remote WSDL file or something local? Try downloading the WSDL and pointing the SoapClient at the local WSDL file instead? Remote. Tried to download it and use it locally with no luck. Pretty much everything here did work though so at least I can rule out the feature being totally broken for whatever reason - at least going local -> local. Unboxing Day fucked around with this message at 18:48 on Dec 1, 2008 |
# ? Dec 1, 2008 18:06 |
|
Does the SOAP API you are referencing require attachments? I was working with a SOAP API with attachments and found that for some reason in php5 its totally borked due to libxml or some such dependency. I ended up fixing it by hacking around with the pear soap library and I finally got it to work that way. Also, you might want to try fiddler instead of wireshark. Its heaven for this kind of stuff, a lot easier than wireshark.
|
# ? Dec 1, 2008 21:39 |
|
I've got a relatively simple (I hope) regular expression question... I have some templates which are written like.. quote:Hi People. <a href="http://site/invoice.php?i=[[INV_NUM]]">Click here to view invoice [[INV_NUM]]</a> on our site. I'd like to replace all these (there's a bunch of them) with <span class="previewtag">[[INV_NUM]]</span> so that it gets highlighted in a pretty colour so people know we'll deal with it later. My problem comes with not replacing the tag if it's inside an HTML tag. Basically I guess I need something that matches [[INV_NUM]] that isn't <.*[[INV_NUM]].*>. Or something like that. Thanks!
|
# ? Dec 2, 2008 08:29 |
|
It seems like it would be much more straightforward and flexible in the future just to put <span class="previewtag">[[INV_NUM]]</span> in the template itself. Even if you're not doing a proper MVC application, you really should keep your code and HTML output as separate as possible. Is there any reason you're not doing this now?
|
# ? Dec 2, 2008 08:39 |
|
Zorilla posted:It seems like it would be much more straightforward and flexible in the future just to put <span class="previewtag">[[INV_NUM]]</span> in the template itself. Even if you're not doing a proper MVC application, you really should keep your code and HTML output as separate as possible. They will then be able to preview these, and it'll highlight the bits that will ultimately change. Finally, it'll email out to a bundle of people, with each one having their name or invoice number substituted in.
|
# ? Dec 2, 2008 10:25 |
|
Makes sense. I suck at regular expressions, so you could probably do this for now:php:<?php $template = str_replace( "[[INV_NUM]]", "<span class=\"previewtag\">".$inv_num."</span>", $template ); // fix all the false positives $template = str_replace( "<a href=\"http://site/invoice.php?i=<span class=\"previewtag\">".$inv_num."</span>", "<a href=\"http://site/invoice.php?i=".$inv_num."\">", $template ); ?> Again, I'm bad as regular expressions and this is probably totally wrong, but maybe this will put you on the right path to finding the right one: php:<?php // replace all instances of [[INV_NUM]] except those between < and > $template = preg_replace( "(?<!<)(?!>)(\[\[INV_NUM\]\])", "$1", $template ?> Zorilla fucked around with this message at 14:36 on Dec 2, 2008 |
# ? Dec 2, 2008 13:47 |
|
NoSpoon posted:I've got a relatively simple (I hope) regular expression question... How about php:<? //note the space before the first bracket $tpl = str_replace(' [[INV_NUM]]',' <span class="previewtag">[[INV_NUM]]</span>',$tpl); ?>
|
# ? Dec 2, 2008 15:33 |
|
Munkeymon posted:How about The <span class> bit is only for a preview - so people can create a template, and see what it actually looks like, with the bits that will ultimately change highlighted (I do realise there's a WYSIWYG editor, but however - we want the [[STUFF]] highlighted). Putting a space before it would probably work, but if someone bolds the invoice number on the templates - "Please pay invoice <strong>[[INV_NUM]]</strong> now" then it'd break.
|
# ? Dec 2, 2008 21:28 |
|
NoSpoon posted:Ultimately the mail will be sent out to dozens (well, a few more than that) of people, with their respective invoice numbers, names, email addresses, etc being substituted in. Oh, I thought from your description that you were maintaining full control of the templates until some indefinite time in the future where you had time to add features. You could have 2 tags: [[INV_NUM]] and [[INV_URL]] so your users wouldn't have to know how to form a URL to the invoices and, if the pattern changes, could be blissfully unaware of it with no disruption in service: code:
|
# ? Dec 2, 2008 22:04 |
|
This may be more html but I have a database that contains a field with upside down text using Unicode characters "IE: uʍop ǝpısdn sı sıɥʇ" how would I get the upside characters to display correctly using echo $upsidedowntext; . I know the variable is stored in the database correctly but when I display the variable I get "u?op ?p?sdn s? s???" am i missing some encoding I have to specify or something?
|
# ? Dec 3, 2008 19:16 |
|
bleh posted:I get "u?op ?p?sdn s? s???" am i missing some encoding I have to specify or something?
|
# ? Dec 3, 2008 19:46 |
|
I'm not sure if this might be a more web dev question but - I'm trying to overlay a 50x50 png with another 50x50 png, the top png to have some transparency. Is there a way to do this with PHP, or maybe CSS (which I'd be generating with PHP anyway)?
|
# ? Dec 4, 2008 10:20 |
|
gently caress the ROW posted:I'm not sure if this might be a more web dev question but - I'm trying to overlay a 50x50 png with another 50x50 png, the top png to have some transparency. Is there a way to do this with PHP, or maybe CSS (which I'd be generating with PHP anyway)? php:<?php $image1["data"] = imagecreatefrompng(BASE_IMAGE); $image2["data"] = imagecreatefrompng(OVERLAY_IMAGE); list($image1["x"], $image1["y"]) = getimagesize($image1["data"]); list($image2["x"], $image2["y"]) = getimagesize($image2["data"]); imagecopyresampled( $image1["data"], $image2["data"], 0,0, 0,0, $image1["x"],$image1["y"], $image2["x"],$image2["y"] ); ?> You could totally do this with CSS intead though, and I prefer this since managing images is much easier when you don't have to apply gloss/whatever to each one: code:
Zorilla fucked around with this message at 22:18 on Dec 4, 2008 |
# ? Dec 4, 2008 11:36 |
|
Zorilla posted:
Just remember that IE6 can't handle alpha channels in PNGs normally so you'll have to use that activex filter or reduce the top image to 8bit color.
|
# ? Dec 4, 2008 18:52 |
|
duz posted:Just remember that IE6 can't handle alpha channels in PNGs normally so you'll have to use that activex filter or reduce the top image to 8bit color. Yeah, that slipped my mind for some reason while writing that at 5:30 in the morning. It's now fixed. Zorilla fucked around with this message at 21:49 on Dec 4, 2008 |
# ? Dec 4, 2008 21:38 |
|
I've just started to delve into using PHP5's simpleXML class and have a couple of questions. I am so used to using MySQL and just regular queries I am a little bit lost when it comes to 'querying' XML files themselves. The basic structure of my XML file is something like this php:<? <cgt> <employee> <username>blah</username> <...lots of other tags> </employee> </cgt> ?> code:
php:<? foreach($xml->employee as $employee) { $name = $employee->firstname; echo '<tr>'; echo '<td><a href="view.php?id='.$employee->username.'">' . $employee->firstname . " " . $employee->lastname . '</a></td>'; echo '<td class="email">' . $employee->email . '</td>'; echo '<td>' . $employee->phone . '</td>'; echo '</tr>'; ?> But I am lost as to how to perform this 'query' with simpleXML. Do I have to use xpath or something? ilikechapstick fucked around with this message at 21:43 on Dec 4, 2008 |
# ? Dec 4, 2008 21:41 |
|
ilikechapstick posted:Ideally I would get all of the information and then just scatter $employee->NODENAME wherever I need the info. php:<?php $xml = simplexml_load_file("somefile.xml"); or exit("File not found"); ?> <table> <tr> <th>Name</th> <th>Email</th> <th>Phone Number</th> </tr> <?php foreach ($xml->xpath("/cgt/employee[name='".$user_id."']") as $employee) { ?> <tr> <td><a href="view.php?id=<?php echo $employee->username; ?>"><?php echo $employee->firstname; ?> <?php echo $employee->lastname; ?></a></td> <td class="email"><?php echo $employee->email; ?></td> <td><?php echo $employee->phone; ?></td> </tr> <?php } ?> </table> I've never used SimpleXML before, so I have no idea if this example works exactly right. Zorilla fucked around with this message at 03:04 on Dec 5, 2008 |
# ? Dec 4, 2008 22:12 |
|
Ok, I think I actually found out something. php:<? $xml->xpath("//*[username='".$userID."']"); $fullname = $xml->employee->firstname . $xml->employee->lastname; ?> That code should insert the <firstname> and <lastname>'s of the person with the username of $userID, right? For some reason it's stopping at the first entry? However, if I do a php:<? print_r($xml->xpath("//*[username='".$userID."']")); ?> EDIT: I'm dumb, never assigned the array to a variable! php:<? $employee = $xml->xpath("//*[username='".$userID."']"); $fullname = $employee[0]->firstname . $employee[0]->lastname; $email = $employee[0]->email; $phone = $employee[0]->phone; $fax = $employee[0]->fax; ?> ilikechapstick fucked around with this message at 22:27 on Dec 4, 2008 |
# ? Dec 4, 2008 22:17 |
|
edit: I can't read edit2: though your corrections were kind of what I was alluding to Zorilla fucked around with this message at 22:28 on Dec 4, 2008 |
# ? Dec 4, 2008 22:20 |
|
Yeah, thanks for the inspiration. Another question though. In my XML file, some professors have a tag like: code:
I successfully looped through and linked everything with this code php:<? foreach ($employee[0]->course as $course) { echo "<li><a href='" . $course->attributes()->link . "'>" . $course . "</a></li>"; } ?>
|
# ? Dec 4, 2008 22:57 |
|
ilikechapstick posted:But how would I check if that tag doesn't exist? I want to put some default text in if they don't teach any classes. Something like php:<?php if (empty($employee[0]->course)) echo "Your default text here."; else foreach ($employee[0]->course as $course) echo "<li><a href='" . $course->attributes()->link . "'>" . $course . "</a></li>"; ?>
|
# ? Dec 4, 2008 23:09 |
|
Zorilla posted:A simple copy ought to do it. This is exactly what I was looking for - I had found examples of the CSS but this way fits what I'm doing a lot better, thanks a billion.
|
# ? Dec 5, 2008 00:00 |
|
Now I have a new problem. I am trying to update a users password, and the XML file looks something like this:code:
php:<? // load the xml file $xml = simplexml_load_file('xml/users.xml', 'SimpleXMLElement', LIBXML_NOCDATA); // select the username $user = $xml->xpath("//*[@username='".$_SESSION["username"]."']"); //update the XML file, yeah right! $user[0]->attributes()->password = '"'.$password.'"'; echo $xml->asXML(); ?>
|
# ? Dec 5, 2008 04:04 |
|
Ok, I am going to stop posting these things. I figured it out.php:<? $user[0]['password'] = $password; file_put_contents('xml/users.xml', $xml->asXML()); ?>
|
# ? Dec 5, 2008 04:17 |
|
I'm using a framework that handles database queries with prepared statements. Lately I've been struggling with huge dynamic queries that need to swap joins and other clauses based on various conditions. It's a major headache to do it by manipulating strings. I've looked at ORM frameworks like Propel, but they seem like more trouble than they're worth for this project. All I really need is a library that helps me generate dynamic SQL without forcing me to append strings and fight over misplaced clauses and commas. My current solution is a class that works something like this: php:<? $select = new Select(); $select->table('customer'); $select->field('customer.name', 'customer.email'); $select->order('customer.name'); $select->where('customer.country = ?', 'US'); if ($user == $not_an_administrator) { // Add a join and a where clause to filter for customers that belong to // this user $select->innerJoin('representative', 'representative.id = customer.repid'); $select->where('representative.id = ?', $userid); } ?>
|
# ? Dec 5, 2008 13:32 |
|
You just need to know the right search terms.
|
# ? Dec 5, 2008 14:16 |
|
Mercator posted:You just need to know the right search terms. I'm looking for something to help me build dynamic SQL queries against arbitrary table definitions. An ORM framework isn't out of the question, but the actual object-relational mapping isn't the important feature to me. I've browsed the documentation for Doctrine and Propel, but quote:I don't want a framework that requires a bunch of boilerplate
|
# ? Dec 5, 2008 15:23 |
|
|
# ? May 16, 2024 07:29 |
|
What's the easiest way to get just the current formatted system timestamp? Instead of something like 2006-09-19 16:56:56 just 16:56:56 Here's what I have code:
Whilst farting I fucked around with this message at 20:59 on Dec 6, 2008 |
# ? Dec 6, 2008 20:57 |