|
I'm trying to get the output of a shell command and it's only returning the first element of a long output.php:<?php $output = shell_exec('pwgen'); print($output); ?> code:
code:
|
# ? Sep 9, 2009 19:07 |
|
|
# ? May 16, 2024 17:07 |
|
royallthefourth posted:Is there a way to make shell_exec give me the correct output or do I need to make some crazy workaround with temp files? passthru might do what you want, even though the documentation makes it sound like it'll only output a binary result for some reason.
|
# ? Sep 9, 2009 19:49 |
|
pwgen(1) posted:The pwgen program is designed to be used both interactively, and in shell scripts. Hence, its default behavior differs depending on whether the standard output is a tty device or a pipe to another program. [...] When standard output (stdout) is not a tty, pwgen will only generate one password, as this tends to be much more convenient for shell scripts, and in order to be compatible with previous versions of this program. Manpages are helpful!
|
# ? Sep 9, 2009 20:21 |
|
ShoulderDaemon posted:Manpages are helpful! Thanks for the tip. I thought I knew how to use the program, but I certainly wasn't expecting this. I don't often write programs that interact with the shell; is this sort of changing behaviour common?
|
# ? Sep 9, 2009 21:43 |
|
Regarding SFTP in PHP. Can anyone offer any advice or solutions for using this protocol? I still can't believe PHP doesn't have this support built in. I can't access SFTP in cURL without an upgrade to the libraries. =(
|
# ? Sep 10, 2009 00:52 |
|
Stephen posted:Regarding SFTP in PHP. Can anyone offer any advice or solutions for using this protocol? I still can't believe PHP doesn't have this support built in. I can't access SFTP in cURL without an upgrade to the libraries. =( Use proc_open to drive a command-line sftp session? http://www.molecularsciences.org/PHP/proc_open_tutorial_and_examples Or mount it with FUSE and use normal filesystem functions? http://fuse.sourceforge.net/sshfs.html
|
# ? Sep 10, 2009 06:37 |
|
http://www.php.net/manual/en/book.ssh2.php
|
# ? Sep 10, 2009 07:04 |
|
well would you look at that
|
# ? Sep 10, 2009 07:05 |
|
Im pretty new to php and im having trouble with sessions. Basicly what im trying to do is make a simple shopping cart for t-shirts. The cart needs to store tshirt_ID, quantity and size. Im fine with the ID and quantity but size is giving me a real ball ache. My add cart function is displayed below code:
Where im sure im going wrong is in the view cart script. Which is fine until: code:
Thanks in advance for your help.
|
# ? Sep 11, 2009 17:49 |
|
Lyric Proof Vest posted:Im pretty new to php and im having trouble with sessions. Basicly what im trying to do is make a simple shopping cart for t-shirts. The cart needs to store tshirt_ID, quantity and size. Im fine with the ID and quantity but size is giving me a real ball ache. Lets say your $tid is 'myshirt' and size is xxl and add it to the cart, that means your cart array would look something like 'myshirtxxl' => array (quantity => '1') In your foreach loop, the $tid variable will contain 'myshirtxxl' and the items would contain an the array with quantity => '1' in it. If you think the error is in how you are displaying your cart, why don't you post that code, because I am not sure how you are trying to extract the size from the array. Also, print_r is your friend. You call print_r($_SESSION) then load the page and view the source, and you can see the contents of the cart and exactly how its stored. Another useful one is var_dump that will show the contents of a variable and its exact type.
|
# ? Sep 11, 2009 19:13 |
|
Is there any way to make php's shell_exec thing pretend to be a tty? Git is irritating as gently caress to work with from php. Does passthru do this?
Rat Supremacy fucked around with this message at 13:08 on Sep 12, 2009 |
# ? Sep 12, 2009 13:05 |
|
No, passthru still behaves the same way.
|
# ? Sep 12, 2009 18:24 |
|
haywire posted:Is there any way to make php's shell_exec thing pretend to be a tty? Git is irritating as gently caress to work with from php. Does passthru do this?
|
# ? Sep 12, 2009 18:27 |
|
gibbed posted:proc_open? Yummy, cheers
|
# ? Sep 13, 2009 01:02 |
|
php:<? $myArray = $_REQUEST["myArray"]; print_r($myArray); //prints the contents fine //^^^ Array ( ['someVar1'] => text woo ['someVar2'] => text wee ['someVar3'] => text omg ['someVar4'] => ['someVar5'] => ) echo "test: alias = " . $myArray['someVar1']. "<br>"; //blank? ?>
|
# ? Sep 16, 2009 15:00 |
|
Safety Shaun posted:
"Array ( ['someVar1'] => text woo ['someVar2'] => text wee ['someVar3'] => text omg ['someVar4'] => ['someVar5'] => ) " and not an array at all.
|
# ? Sep 16, 2009 18:34 |
When I pass in an $id to my object's constructor, it looks for it in cache and if there isn't one then it queries the database and fills out the rest of the info about that object. How can I do some sort of reassign of $this so I dont have to manually assign each field? Basically I want some one line thing: code:
code:
fletcher fucked around with this message at 02:25 on Sep 17, 2009 |
|
# ? Sep 17, 2009 02:22 |
|
fletcher posted:When I pass in an $id to my object's constructor, it looks for it in cache and if there isn't one then it queries the database and fills out the rest of the info about that object. How can I do some sort of reassign of $this so I dont have to manually assign each field? if the cached object is just a cached version of the object then why not; code:
code:
|
# ? Sep 17, 2009 02:56 |
wolf_man posted:if the cached object is just a cached version of the object then why not; I am retarded and didn't even think of returning anything from the constructor. Thank you!
|
|
# ? Sep 17, 2009 03:44 |
|
fletcher posted:I am retarded and didn't even think of returning anything from the constructor. Thank you! PHP does not let you return values from a constructor. It sounds like you should use a static function. You can make the constructor private so the only way to retrieve the object is through the static function. php:<? class CachedObject { private function __construct($id) { // Code to create the object from the db (and save it to the cache) } public static function Get($id) { $obj = $cache->get($id); if ($obj != null) { return $obj; } else { return new CachedObject($id); } } } $x = new CachedObject('12345'); // This won't work $y = CachedObject::Get('12345'); // This will ?>
|
# ? Sep 17, 2009 07:45 |
|
It sure looks to me like this code should list the events AFTER the table header...code:
I'm used to working in ASP so I'm sorta clueless here. Can someone give me a clue please?
|
# ? Sep 17, 2009 17:26 |
|
frumpus posted:It sure looks to me like this code should list the events AFTER the table header... Your table is malformed. Your loop puts content directly in the <tr> element instead of a <td> element. The empty <tr></tr> right before the loop might be a problem, too.
|
# ? Sep 17, 2009 17:30 |
|
DaTroof posted:Your table is malformed. Your loop puts content directly in the <tr> element instead of a <td> element. The empty <tr></tr> right before the loop might be a problem, too. Thanks, I'll stick some td tags in there and see if that straightens it out. Leave it to me to get wrapped up in learning php and forgetting basic html. The empty row I actually added after the problem arose to see if it changed anything. edit: Yeah, that fixed it. I'm dumb. frumpus fucked around with this message at 17:46 on Sep 17, 2009 |
# ? Sep 17, 2009 17:33 |
DaTroof posted:PHP does not let you return values from a constructor. It sounds like you should use a static function. You can make the constructor private so the only way to retrieve the object is through the static function. Oh, maybe that's why I didn't think of doing it! Thanks for the snippet.
|
|
# ? Sep 17, 2009 20:10 |
|
Does any language with OO constructs let you return something from the constructor? I can't think of one that does.
|
# ? Sep 17, 2009 21:17 |
|
After spending a few hours trying to get Jack's formmail.php script working and not having any luck, I gave up and wrote my own. Since I'm pretty new at PHP, I was hoping someone with a little more experience could give my code a quick look over to make sure I'm not doing anything obviously stupid before I put the code on a public web page. code:
|
# ? Sep 17, 2009 22:55 |
|
Two things: I have this code: php:<? $Size = 0; if ($Size === "S" || $Size === 0) $Test = "S"; if ($Size === "LGG") $Test = "LGG"; if ($Size === "SGG") $Test = "SGG"; if ($Size > 0 && $Size <=9) $Test = $Size; if ($Size === "A" ) $Test = "A"; echo $Test; ?> Agrikk fucked around with this message at 07:09 on Sep 18, 2009 |
# ? Sep 18, 2009 07:03 |
|
Agrikk posted:Two things: php:<? $Size=0; $Test=($Size===0)?'S':$Size; if(!preg_match('~^(S|LGG|SGG|[0-9]|A)$~',$Size) unset($Test); // this line might be unneccessary, depending echo $Test; ?>
|
# ? Sep 18, 2009 07:23 |
|
Filthy Lucre posted:After spending a few hours trying to get Jack's formmail.php script working and not having any luck, I gave up and wrote my own.
|
# ? Sep 18, 2009 09:34 |
|
Probably needs it's own thread, but anyone found or created anything useful for OpenID? I'm looking for a PHP equivalent of this site as setup by Google to demonstrate fancy pants OpenID login: It's a JSP and Java Servlet combination and the magic is probably happening below. It takes the domain of an entered email address and magically conjures up the OpenID Identity URL. code:
I'm looking at the PHP-OpenID library that's bundled in Debian but it's rather obtuse on quick inspection, the demo is certainly not so useful, http://openidenabled.com/php-openid/trunk/examples/consumer/ You need to enter "https://www.google.com/accounts/o8/" for Google as the Identity URL, but this wouldn't work for Yahoo!, Facebook or whatever other popular OpenID systems are out there.
|
# ? Sep 18, 2009 12:21 |
|
Standish posted:You're never assigning anything from $_POST to $to and $bcc (they're hardcoded to "me@mydomain.com" and "" respectively), so there should be no need to sanitize them, unless they're being automatically assigned because you have register_globals turned on, which is really really bad and should be turned off immediately. I was sanitizing them because I was worried about someone doing something like http://www.mydomain.com/myscript.php?to=spammee@address.com&bcc=everyone@world to use the script to send email. Are you saying having register_globals=off prevents that sort of thing anyway? As you can tell, I don't have a lot of experience with PHP.
|
# ? Sep 18, 2009 16:09 |
|
Filthy Lucre posted:register_globals is off. I had read that having it on is a security risk. Yes, register globals turns that off. If you are not sure, then try doing your example above and see what happens. As for your sanitize script, its super duper whacky. Where did you get that snippet and what exactly is it doing?
|
# ? Sep 18, 2009 17:12 |
|
You should just compose $messageBody out of the elements of $_POST you want to use rather than try to sanitize and include whatever some jerkass pases in.php:<? $messageBody = $_POST['body']."\r\n"; $subject = $_POST['sub']."\r\n"; //whatever else you _know_ you want ?> edit: also, in_array is better than a for loop to see if some value is in an array
|
# ? Sep 18, 2009 17:13 |
|
Begby posted:Yes, register globals turns that off. If you are not sure, then try doing your example above and see what happens. The sanitize portion was doing two things; code:
code:
The whole function would then return the message body into $msgBody which would go out in the mail() call.
|
# ? Sep 18, 2009 18:59 |
|
Munkeymon posted:You should just compose $messageBody out of the elements of $_POST you want to use rather than try to sanitize and include whatever some jerkass pases in. It's mailing the results of a survey form from a web page. I may or may not be the one building survey page, so I was trying to build something generic. I have no way of knowing the names of the fields used on the form, hence the foreach going through $_POST rather than just pulling the elements straight out.
|
# ? Sep 18, 2009 19:06 |
MrMoo posted:Probably needs it's own thread, but anyone found or created anything useful for OpenID? This may be a dumb question, but what is to stop me from putting a fake login on some site that claims to be an "OpenID login" and just stealing a bunch of OpenID credentials?
|
|
# ? Sep 18, 2009 20:10 |
|
fletcher posted:This may be a dumb question, but what is to stop me from putting a fake login on some site that claims to be an "OpenID login" and just stealing a bunch of OpenID credentials?
|
# ? Sep 19, 2009 01:27 |
|
fletcher posted:This may be a dumb question, but what is to stop me from putting a fake login on some site that claims to be an "OpenID login" and just stealing a bunch of OpenID credentials? The OpenID server provides a unique ID bound to that provider so cannot imitate another provider. I found some more PHP code that has a basic hard coded array of domains to Identity URLs, but there should be some method for automatic "federated" discovery. http://perplexed.co.uk/867_openid.htm code:
|
# ? Sep 19, 2009 03:32 |
|
Some progress on this, I have a discovery mechanism setup patched to XRDS-Simple. The mechanism is called host-meta, patch: To SVN of Diso/XRDS-Simple: Then code for the Idp Discovery can run like this: code:
code:
MrMoo fucked around with this message at 09:42 on Sep 21, 2009 |
# ? Sep 21, 2009 09:40 |
|
|
# ? May 16, 2024 17:07 |
|
Does anyone have any neat methods for preparing a associative array for use in a SQL update statement? Normally I do something like this:code:
|
# ? Sep 21, 2009 16:04 |