|
Zorilla posted:If PHP isn't configured, the web server interprets it as text/plain and just sends off the script without processing it. (beaten)
|
# ? Oct 12, 2008 15:08 |
|
|
# ? May 15, 2024 18:07 |
|
gibbed posted:This is especially nasty when the Apache server begins to break down for some reason (hardware failure, etc) and stops handling PHP (been bitten by this, not just once, but twice). Which is why I put any important code outside of webroot now and include it. Can't take that chance again. I see, I guess if that could be a worry then I ought to go find out how to move the file containing database account information to a safe location. Thanks.
|
# ? Oct 12, 2008 17:40 |
|
Hammerite posted:I see, I guess if that could be a worry then I ought to go find out how to move the file containing database account information to a safe location. Thanks. It's pretty easy.. if your web root is at /var/apache/htdocs/ for example, then store your important stuff in a new folder like /var/apache/hidden/ and then include of the full path to the files: php:<? require_once('/var/apache/hidden/top_secret_db_info.php'); ?>
|
# ? Oct 13, 2008 14:51 |
|
Lumpy posted:It's pretty easy.. if your web root is at /var/apache/htdocs/ for example, then store your important stuff in a new folder like /var/apache/hidden/ and then include of the full path to the files: Thanks, I hadn't hit on the idea of creating a new directory outside of the web root and just directing php to look there. For some reason I wasn't thinking of the idea of just creating a new directory up there; didn't think it would be allowed, or something. The web root is titled public_html; it sits inside a directory called ABC, so I now have a new directory called DEF sitting inside ABC which contains commonthings.php. The files for the actual site are in a subdirectory of the main website, i.e. in a subdirectory GHI of public_html (which no longer contains a copy of commonthings.php). So the include statement now reads code:
(obviously ABC, DEF, GHI stand in for the real names of these things)
|
# ? Oct 13, 2008 22:02 |
|
Hammerite posted:So the include statement now reads The only "problem" with that is when you move your including page to a new level in the directory hierarchy. Then "../../" points somewhere else, and everything breaks. Try to use absolute paths as much as possible. But if it works for now, then you done good, and keeping passwords / usernames, etc. outside of web root is always a good thing, no matter how you go about doing it.
|
# ? Oct 13, 2008 22:42 |
|
Lumpy posted:The only "problem" with that is when you move your including page to a new level in the directory hierarchy. Then "../../" points somewhere else, and everything breaks. Try to use absolute paths as much as possible. But if it works for now, then you done good, and keeping passwords / usernames, etc. outside of web root is always a good thing, no matter how you go about doing it. It seems cheesy to hardcode the absolute path to files for one particular server. Is there a way to acquire the web server's DocumentRoot path so things can be easily moved from server to server?
|
# ? Oct 14, 2008 04:27 |
|
Zorilla posted:It seems cheesy to hardcode the absolute path to files for one particular server. Is there a way to acquire the web server's DocumentRoot path so things can be easily moved from server to server? This will only work when accessed in such a way that this stuff is set (i.e. through Apache and NOT through the command line.) php:<? $doc_root = getenv("DOCUMENT_ROOT"); ?>
|
# ? Oct 14, 2008 04:35 |
Zorilla posted:It seems cheesy to hardcode the absolute path to files for one particular server. Is there a way to acquire the web server's DocumentRoot path so things can be easily moved from server to server? php:<? //config.php define("ROOT_PATH", "/home/fletch/www/website.com/"); define("PATH_TO_IMAGES", ROOT_PATH."public/img/"); ?>
|
|
# ? Oct 14, 2008 05:50 |
|
Zorilla posted:It seems cheesy to hardcode the absolute path to files for one particular server. Is there a way to acquire the web server's DocumentRoot path so things can be easily moved from server to server? php:<? $dr = $_SERVER['DOCUMENT_ROOT']; ?> Lumpy fucked around with this message at 14:38 on Oct 14, 2008 |
# ? Oct 14, 2008 14:31 |
|
I have found the best way to get the absolute path is thisphp:<? define("ROOT_PATH", dirname(__FILE__)); ?> This will work either in a command line program or website.
|
# ? Oct 14, 2008 16:27 |
|
Begby posted:That works if the file it is called from is in the root, or you can get the dirname and explode it into an array using DIRECTORY_SEPARATOR as the delimiter, pop some directories off the end, and implode it back into a string and use that as the root path.
|
# ? Oct 14, 2008 16:38 |
|
I just usecode:
It's true that moving commonthings.php would break this, but 1) that doesn't happen too often and 2) fixing it usually requires a single fairly swift find/replace on the rest of the codebase.
|
# ? Oct 14, 2008 19:54 |
|
I have this:php:<?php /* Header Inclusion */ include("header.php"); $url = $_REQUEST['url']; /* $go is true if $url is set */ $go = isset($url); $purl = parse_url($url); $host = $purl[host]; /* Check to see if $url is set */ if ($go == FALSE){ Stuff } else { /* If Go is yes, then this is what is shown */ echo $url; echo $host; } include("footer.php"); ?>
|
# ? Oct 15, 2008 01:38 |
|
Sparta posted:I have this: Why don't you use $_SERVER['HTTP_HOST']; to get the host? No parsing required. [EDIT] Try printing $purl with print_r($purl) and see if it's actually setting a host to see if it's the parsing or something else.... Lumpy fucked around with this message at 01:47 on Oct 15, 2008 |
# ? Oct 15, 2008 01:45 |
|
Lumpy posted:Why don't you use $_SERVER['HTTP_HOST']; to get the host? No parsing required. $url is variable, it's not the current site's host. Trying print_r now.
|
# ? Oct 15, 2008 02:02 |
|
Returns Array ( [path] => https://www.mikemanfrin.com/hello ) http://metrics.cc/url.php?url=www.mikemanfrin.com/hello Sparta fucked around with this message at 05:21 on Oct 15, 2008 |
# ? Oct 15, 2008 02:43 |
|
I have an image that was created from imagecreatefromjpeg() in a php script. I have PHPMailer up and running but I can't figure out how to send the image as an attachment without first writing the file to disk. Is it possible to send it without it being a file? I can't seem to find any real good documentation for phpmailer and I also don't really know how encoding attachments works so any help would be greatly appreciated. Thanks.
|
# ? Oct 15, 2008 03:36 |
|
sonic bed head posted:I have an image that was created from imagecreatefromjpeg() in a php script. I have PHPMailer up and running but I can't figure out how to send the image as an attachment without first writing the file to disk. Is it possible to send it without it being a file? I can't seem to find any real good documentation for phpmailer and I also don't really know how encoding attachments works so any help would be greatly appreciated. Thanks. I believe imagecreatefromjpeg() loads a JPEG into memory, uncompressed and likely taking up seveal MB because of it. That's not something you want to attach to an email. Unless PHPMailer has a method for accepting GD image objects as file attachments where it compresses it back down for you, you'll probably have to save the image to a temporary location using imagejpeg(). Unless PHP provides a graceful way to store files temporarily in 1-2 lines of code, I would just save the file with a random name like md5(session_id()).".jpg", destroy the copy in memory, email it, then delete it. Zorilla fucked around with this message at 06:54 on Oct 15, 2008 |
# ? Oct 15, 2008 06:47 |
|
I have a div with a set width and height and a background image. How do I place images (in other divs possibly) randomly inside the main div? I want to try doing this without them overlapping. If PHP is overkill, could I do this with Javascript?
|
# ? Oct 15, 2008 11:40 |
|
drcru posted:I have a div with a set width and height and a background image. If the desired result is a slightly jumbled appearance, you might try setting float: left on each image and giving each a random amount of margin within 10-50px.
|
# ? Oct 15, 2008 12:47 |
edit: nevermind
fletcher fucked around with this message at 19:01 on Oct 15, 2008 |
|
# ? Oct 15, 2008 18:57 |
|
Or if you want to have more control, set the containing div to position:relative and the images to position:absolute and set the left/top of the images to precise values. (with style attributes if you're doing this in the PHP, and you could find the image dimensions with GD so you could generate this from any directory of images) Then you can make sure they fit if you know the width/height of the div and the widths/heights of the images Depends how random you want it, and how particular about them not overlapping. With that method you could even overlap them nicely and in a controlled manner using z-order and shuffle them around with javascript, hmmmm... KuruMonkey fucked around with this message at 19:02 on Oct 15, 2008 |
# ? Oct 15, 2008 19:00 |
|
Sparta posted:Returns Array ( [path] => https://www.mikemanfrin.com/hello ) I do not know much (read: anything) about parse_url. Could it be because it does not have 'http://' in front of it? If *none* of your url vars are going to have [url]http://[/url] in front of them, why not use explode() and then grab the first element of the resulting array?
|
# ? Oct 15, 2008 19:54 |
|
sonic bed head posted:I have an image that was created from imagecreatefromjpeg() in a php script. I have PHPMailer up and running but I can't figure out how to send the image as an attachment without first writing the file to disk. Is it possible to send it without it being a file? I can't seem to find any real good documentation for phpmailer and I also don't really know how encoding attachments works so any help would be greatly appreciated. Thanks. PHPMailer is defunct. SwiftMailer is the way to go.
|
# ? Oct 15, 2008 20:23 |
|
Zorilla posted:Unless PHP provides a graceful way to store files temporarily in 1-2 lines of code, I would just save the file with a random name like md5(session_id()).".jpg", destroy the copy in memory, email it, then delete it. http://us.php.net/manual/en/function.tempnam.php
|
# ? Oct 15, 2008 20:43 |
|
|
# ? Oct 15, 2008 20:43 |
|
duz posted:http://us.php.net/manual/en/function.tempnam.php That works great! I don't have to worry about chmoding some directories, it automatically gets a directory that is writable. Is there a way to allow execution of a script to continue after someone closes a browser window? I want someone to be able to go to blah.com/sendMeAnEmail.php?email=blah and then just close the browser and have all of the script continue execution that might take some time because it involves an HTTP Request. edit:I found it. ignore_user_abort(TRUE); Let me just say, I am beginning to get very very annoyed by the odd naming conventions in PHP. sonic bed head fucked around with this message at 22:11 on Oct 15, 2008 |
# ? Oct 15, 2008 22:03 |
|
Hey guys. I'm trying to teach myself php basically by writing psudocode and then looking things up on w3schools. I'm trying to make a php program to shuffle and draw 6 cards (A-6 of spades) from a deck at random. Just to kinda give me an idea of what I was loving up I also had it print the number of cards remaining and their values. I can't get this to work though. Any help would be greatly appreciated. A live version of the site can be found at http://www.furbyarmy.com/poker.php code:
a cat fucked around with this message at 00:17 on Oct 17, 2008 |
# ? Oct 17, 2008 00:13 |
|
jstirrell posted:php:<?php function drawFromDeck($cards) { $deck = array("As", "2s", "3s", "4s", "5s", "6s"); for($i = 0; $i < $cards; $i++) { shuffle($deck); $card = array_pop($deck); print "Drew $card<br>\n"; print "Remaining cards:<br>\n"; foreach($deck as $k => $v) { print $v . " "; } print "<br>\n"; print "---------"<br>\n"; } } print drawFromDeck(5); ?>
|
# ? Oct 17, 2008 08:47 |
|
J. Elliot Razorledgeball posted:
Syntax error on that line.
|
# ? Oct 17, 2008 16:14 |
|
I had a friend write me some code. I don't understand what -> does. Can someone link me an article and explain it? Also is $this just a variable or a defined variable that means something special in php? code:
|
# ? Oct 17, 2008 19:48 |
|
simcole posted:I had a friend write me some code. I don't understand what -> does. Can someone link me an article and explain it? -> is the equivalent of the "." in most languages. An English translation would be " method or property of " an object. $blah->talk(); is like "call the talk() method of the $blah object" and echo $pie->flavor; is "echo the flavor property of the $pie object" $this is a self-reference. If I have code inside an object, $this refers to the object said code is running in.
|
# ? Oct 17, 2008 19:53 |
|
Thanks so much. I knew what . was but I couldn't find -> anywhere. I figured $this was a keyword but I never saw it defined. Thanks agian.
|
# ? Oct 17, 2008 20:01 |
|
This is more of a caching question, but is there a good way to serve a cached PHP page while adding to total page views? Additionally, what is the most efficient way to track page views? I'm thinking that an "UPDATE page_views" query on every page load is probably not the best way.
|
# ? Oct 17, 2008 23:46 |
|
Lumpy posted:Syntax error on that line. whoops php:<? print "--------<br>\n"; ?>
|
# ? Oct 17, 2008 23:48 |
|
Lumpy posted:-> is the equivalent of the "." in most languages. An English translation would be " method or property of " an object. One thing I've never found documentation on is what the &= assignment operator is supposed to be. Or why I sometimes see functions as ___somename(). Can somebody tell me what the purpose of these are?
|
# ? Oct 18, 2008 00:18 |
|
Zorilla posted:One thing I've never found documentation on is what the &= assignment operator is supposed to be. Or why I sometimes see functions as ___somename(). Can somebody tell me what the purpose of these are? =& __somename()
|
# ? Oct 18, 2008 00:32 |
|
double post
|
# ? Oct 18, 2008 00:32 |
|
Zorilla posted:One thing I've never found documentation on is what the &= assignment operator is supposed to be. Or why I sometimes see functions as ___somename(). Can somebody tell me what the purpose of these are? &= is "bitwise AND" assignment. $a = $a & 16; $a &= 16; are equivalent statements. Functions like __function() are so-called "magic functions" and are reserved for future use by PHP. No user-defined function, constant, or method should start with "__". e:f;b. edit: Ha I was right though. "&=" != "=&"
|
# ? Oct 18, 2008 00:32 |
|
|
# ? May 15, 2024 18:07 |
|
Atom posted:&= is "bitwise AND" assignment. 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.
|
# ? Oct 18, 2008 00:45 |