Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Experto Crede
Aug 19, 2008

Keep on Truckin'

Mister Chief posted:

Try:

echo implode(' & ', $_POST);

Perfect, thank you :D

Adbot
ADBOT LOVES YOU

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

Experto Crede posted:

Perfect, thank you :D

Don't ever just echo user input though, that's just cruisin' for a bruisin'.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

Experto Crede posted:

Perfect, thank you :D

You should look into http://us3.php.net/http_build_query if you're going to be doing anything with that data like using it for GET parameters on a subsequent request.

revmoo
May 25, 2006

#basta
Does anybody know a way to get PHP Codesniffer to care about php doc blocks? I tried some squizz sniffs but they were way too strict or something. phpcs works great for PSR-2 but doesn't care how you write comments.

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

Anyone know how you set the default php.ini directory on windows? I am tearing my hair out! It thinks it is in C:\Windows but it is not. I can't find a registry entry for it either.

Depressing Box
Jun 27, 2010

Half-price sideshow.

jiggerypokery posted:

Anyone know how you set the default php.ini directory on windows? I am tearing my hair out! It thinks it is in C:\Windows but it is not. I can't find a registry entry for it either.

This might help (3rd and 4th entries).

stoops
Jun 11, 2001
I'm working on wordpress, but I think this may be php related.

On the code below, I'm getting a Call to undefined function on line 3, "getItems($items)".
I googled and I found that I should be calling it like this "$this->getItems($items);", but that still gives me the same error. Any help is appreciated.

code:
<?php

$items = $cartquantity;
$packets = array();
getItems($items);


function getItems($items) {

    global $packets;

    $large_packets = 12;
    $medium_packets = 8;
    $small_packets = 4;

    $remainderGetItems = $items % $large_packets;

    if ($remainderGetItems == $items) {
        $remainderGetItems = $items % $medium_packets;
        if ($remainderGetItems == $items) {
            if ($items > 0 && $items <= $small_packets) {
                $packets['small'] = 1;
            } else {
                $packets['medium'] = 1;
            }
        } else {
            $packets['medium'] = ($items - $remainderGetItems) / $medium_packets;
            if ($remainderGetItems != 0) {
                if ($remainderGetItems < $small_packets) {
                    $packets['small'] = 1;
                } else {
					getItems($remainderGetItems);
                }
            }
        }
    } else {
        $packets['large'] = ($items - $remainderGetItems) / $large_packets;
        if ($remainderGetItems != 0) {
            if ($remainderGetItems < $small_packets) {
                $packets['small'] = 1;
            } else {
				getItems($remainderGetItems);
            }
        }
    }
}
?>

spacebard
Jan 1, 2007

Football~

stoops posted:

I'm working on wordpress, but I think this may be php related.

On the code below, I'm getting a Call to undefined function on line 3, "getItems($items)".
I googled and I found that I should be calling it like this "$this->getItems($items);", but that still gives me the same error. Any help is appreciated.

No, you do not use $this.

http://www.php.net/manual/en/language.oop5.basic.php posted:

The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).

The code works fine when run via PHP so perhaps Wordpress is doing something weird with including that code?

xtal
Jan 9, 2011

by Fluffdaddy
e:f,b

stoops
Jun 11, 2001

spacebard posted:

No, you do not use $this.
The code works fine when run via PHP so perhaps Wordpress is doing something weird with including that code?

Yeah, something weird was happening in wordpress.

I ended up putting the function in a class php file and it worked fine.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
I'm writing a book on building advanced web applications using Symfony, Doctrine, Postgres, and Redis: https://advancedwebappsbook.com/

Essentially the book will talk about how to properly layout a complex Symfony project, how to test it (using unit and functional testing), and how to deploy it. The book will go through a single project (building a REST API with admin panel) from scratch.

I have a pre-sale for the book now. If you're interested or have any questions, please let me know.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

musclecoder posted:

I'm writing a book on building advanced web applications using Symfony, Doctrine, Postgres, and Redis: https://advancedwebappsbook.com/

Essentially the book will talk about how to properly layout a complex Symfony project, how to test it (using unit and functional testing), and how to deploy it. The book will go through a single project (building a REST API with admin panel) from scratch.

I have a pre-sale for the book now. If you're interested or have any questions, please let me know.

quote:

When the book is published, what exactly will I receive?
- DRM free PDF — share it with your friends!
We're all friends here right? Seriously though, this is very cool. I may bite, I've wanted to learn Symfony and some of the online tutorials are not so great.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

DarkLotus posted:

We're all friends here right? Seriously though, this is very cool. I may bite, I've wanted to learn Symfony and some of the online tutorials are not so great.

Cool! Yeah I'm excited/nervous/anxious about it, but I know it will be a really great product.

And I've spent countless hours going through Stackoverflow posts and blog posts from 2011 trying to figure stuff out only to have to dig down into the Symfony internals to finally get it. The Symfony docs themselves are decent and will get you a good understanding of the framework. But, when it comes to obscure configuration settings or knowing how to set up a project properly, they're pretty lacking.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace

musclecoder posted:

Cool! Yeah I'm excited/nervous/anxious about it, but I know it will be a really great product.

And I've spent countless hours going through Stackoverflow posts and blog posts from 2011 trying to figure stuff out only to have to dig down into the Symfony internals to finally get it. The Symfony docs themselves are decent and will get you a good understanding of the framework. But, when it comes to obscure configuration settings or knowing how to set up a project properly, they're pretty lacking.

Symfony gets a lot of love for big projects, but the steep learning curve has kept me away from it. If your book can make it easier to get something started in Symfony then it's something that I am looking forward to.

Of course, my boss hates all 3rd party libraries, so it might have to be just for personal projects for a while...

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

PlesantDilemma posted:

Symfony gets a lot of love for big projects, but the steep learning curve has kept me away from it. If your book can make it easier to get something started in Symfony then it's something that I am looking forward to.

Of course, my boss hates all 3rd party libraries, so it might have to be just for personal projects for a while...

Well, if you're a Symfony beginner I recommend you follow the online documentation. It does a good enough job of getting you to build a basic app.

Getting started with Symfony is easy enough.

1) Install Composer - http://getcomposer.org/download/
2) Install Symfony
code:
php composer.phar create-project symfony/framework-standard-edition my-symfony-app 2.3.3
3) Run built in PHP 5.4 server
code:
php app/console server:run
4) Go to http://localhost:8000/ and start playing around with it.

My book is more aimed at people who have some Symfony experience or people who want to become better web application developers. I'll discuss testing, deploying, and queuing, which can be applied to any application regardless of framework.

roybot9000
Aug 27, 2003

revmoo posted:

Does anybody know a way to get PHP Codesniffer to care about php doc blocks? I tried some squizz sniffs but they were way too strict or something. phpcs works great for PSR-2 but doesn't care how you write comments.

In my ruleset.xml I have the following:

code:
<rule ref="PEAR.Commenting.ClassComment"/>
<rule ref="PEAR.Commenting.FileComment">
<rule ref="Squiz.Commenting.VariableComment">
Works fine for me, but it is a bit strict in that it requires specific phpdoc attributes to be present in the comments. If you just want to check that a phpdoc comment exists for classes and functions, I have no idea. But I would be interested in learning how to do that.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
A few updates regarding my book post from above.

1) I've lowered the pre-sale price to $19.00 to spur sales. The final price will be $39.00. There are some chapters of this book I could see charging $19 for them alone, so I think the pre-sale price is definitely worth it.
2) I've added the table of contents.

If you have any questions, let me know. I won't bug the thread much more until the book is actually released. Thanks!

Edit: Released the first 2 chapters and TOC of the book - TOC, Chapter 1, Chapter 2

musclecoder fucked around with this message at 20:02 on Aug 29, 2013

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
Anyone know of a way to flush session data to the session file without waiting for the PHP script to end? I see session_write_close in the docs but that also closes the session. Anyone know of another function or maybe an extension that will do this? We are using the default session handler that just writes to files.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Because session data isn't actually just normal serialized data, the only 100% reliable way to get it is going to be through session_write_close. I mean you could fake it by hand but that would be a dangerous disaster in the making.

Have you tried opening the session back up after closing it? It could work. Could.

If you need to begin persisting session-ish data more frequently than once per request, you really probably want to do so manually on a case-by-case basis to a datastore that's intended for such a use case.

jony neuemonic
Nov 13, 2009

Has anyone worked with Laravel and seen the artisan tool just break? I've been working on a project for a couple hours and suddenly trying to run any artisan commands dumps an HTML error page to my terminal. Everything was working fine up to this point, and as far as I know I haven't touched anything that would cause that to happen. I've removed the bootstrap/compiled.php file and my vendor folder and re-run composer install --no-scripts (there are some hooks in my composer.json which run artisan commands, so running without --no-scripts gives me the same errors) which reinstalls everything, but doesn't fix the problem with artisan.

Depressing Box
Jun 27, 2010

Half-price sideshow.
Since Artisan runs through the Laravel core something that breaks your site will usually break Artisan too. I'd say check the error page and see what it's complaining about.

jony neuemonic
Nov 13, 2009

Turns out I broke routes.php. Badly. Really glad I threw this thing in version control. Thanks so much, didn't realize artisan was that tied-in.

BobFossil
Jun 17, 2005

Note to self: I hate whites.
I bought a script which is an 'SEO tool', and it's supposed to give a domain's page position on google based on a keyword.

However, it's broken and I don't think it's working because the URL format used for the google search query looks outdated.

Is anyone good with with how the google search url works?

check_search_position.php line 62
php:
<?
        if($_GET['search_engine'.$l]=="google")
                    {
                        $url_page="http://www.google.com/search?hl=en&q=".urlencode($_GET[keyword])."&num=100&hl=en&lr=".$_GET[lr].
                            "&as_qdr=all&start=".$start."&sa=N";
                            $count = 100;
                        //echo "<br>inlcude url:".$url_page;
?>
Yes I've tried emailing the website I bought it off but they have disappeared :(

the whole script can be found here https://dl.dropboxusercontent.com/u/40524/searchengine-position.rar

here's the 'demo' of the script of their site http://www.selfseo.com/store/demos/tools/searchengine-position/

BobFossil fucked around with this message at 23:40 on Sep 15, 2013

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace

McGlockenshire posted:

Because session data isn't actually just normal serialized data, the only 100% reliable way to get it is going to be through session_write_close. I mean you could fake it by hand but that would be a dangerous disaster in the making.

Have you tried opening the session back up after closing it? It could work. Could.

If you need to begin persisting session-ish data more frequently than once per request, you really probably want to do so manually on a case-by-case basis to a datastore that's intended for such a use case.

Yeah, ended up writing my own simple thing do use the cache extension we got. But what do you mean by "session data isn't actually just normal serialized data", I thought that it was just a file dump of serialize($_SESSION) and php uses cookies to keep track of who it belongs to. What else is in there?

duck monster
Dec 15, 2004

Depressing Box posted:

Since Artisan runs through the Laravel core something that breaks your site will usually break Artisan too. I'd say check the error page and see what it's complaining about.

I love laravel, but its error handling makes me want to break things. That loving error handler is the most broken thing in the laravel stack, and that worries me.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
I need to get a Windows/Apache/PHP website to auto-authenticate with an external ADS Web Services setup to use SOAP/XML over HTTP. I've never done this before, and never have any of the people I work with. I've read up a whole bunch on mod_auth_kerb etc prior to being told that the AD guys would set up ADS Web Services. My biggest stumbling block right now is that I just don't quite understand how the website requests the current user's information to SEND to ADS WS to confirm, even if the website has been added into Trusted Sites by Group Policy. I know this is an Apache problem, not a PHP one, but I can't find an Apache thread.

What should I be looking at? I have a bit of time before it needs to be set up but I'm just butting my head against this part of the process and not knowing where to look.

e: Found something that looks promising:

http://rc.quest.com/topics/mod_auth_vas/

Will research that soon.

Sulla Faex fucked around with this message at 16:46 on Sep 23, 2013

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
So, having just used PDO for the first time a couple of days ago, does setting PDO::ERRMODE_EXCEPTION mean that all those methods that might return FALSE will instead throw an exception?

Because gently caress "if ($result !== FALSE)", bring on "try {the universe} catch ($everything)"

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Yes, but to be clear that's just the constant.

php:
<?
PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Wheany posted:

So, having just used PDO for the first time a couple of days ago, does setting PDO::ERRMODE_EXCEPTION mean that all those methods that might return FALSE will instead throw an exception?

Only things that would return false on error would throw an exception.

Things that return false when there is no data but when there isn't an error will continue to return false.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

McGlockenshire posted:

Only things that would return false on error would throw an exception.

Things that return false when there is no data but when there isn't an error will continue to return false.

Well, from a quick look, PSO::prepare, beginTransaction, commit, rollBack and PDOStatement::execute, fetch and fetchAll all return false on failure, and that is good enough for now at least.

Impotence
Nov 8, 2010
Lipstick Apathy

BobFossil posted:

I bought a script which is an 'SEO tool', and it's supposed to give a domain's page position on google based on a keyword.

However, it's broken and I don't think it's working because the URL format used for the google search query looks outdated.

Is anyone good with with how the google search url works?

check_search_position.php line 62
php:
<?
ugh
?>
Yes I've tried emailing the website I bought it off but they have disappeared :(

the whole script can be found here https://dl.dropboxusercontent.com/u/40524/searchengine-position.rar

here's the 'demo' of the script of their site http://www.selfseo.com/store/demos/tools/searchengine-position/


This is both a ToS violation and you will get captcha'd or IP blocked. https://developers.google.com/custom-search/json-api/v1/overview

While we're at it, that thing is so horrendously bad (not to mention the "inlcude url" bullshit).

LP0 ON FIRE
Jan 25, 2006

beep boop
I'm looking for some kind of installer generator for Mac or PC, but preferably both that does the following:

With the click of a button on some php backend webpage, and installer will be created that packages all the files from a directory. When you download the installer and launch it, it will put all these files in a predefined or chosen directory on your computer. It's okay if this costs money or has some license fee.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
For Windows you can probably shell out to NSIS from PHP from either Windows or a *nix.

Mac installers are just disk images. It looks like you need to actually use a Mac to create them initially, but you might be able to mount and write to them under various Linuxes as well.

LP0 ON FIRE
Jan 25, 2006

beep boop
Thank you McGlockenshire I'll look into both of those!

Robot Arms
Sep 19, 2008

R!
I need some help getting started.

I'm using WordPress for lawyerist.com. It's my own, custom theme. Here's what I'm trying to do:

Loop 1:
* If the post was published on or after Monday, publish it in Loop 1.
* If the post is the most-recent post *and* it was published today, tag it with class="current".

Loop 2:
* If the post was published before Monday, publish it in Loop 2.

Thanks in advance for any help you can give me. I'm cool with doing multiple loops. Mostly, I'm trying to figure out how to say "if the post was published on or after Monday" and "if the post was published before Monday" in PHP.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
Sorry I don't have an answer for you samglover but the Wordpress Megathread might also offer some help.

Robot Arms
Sep 19, 2008

R!
Thanks. I didn't see that before. Between that thread and this one, maybe a PHP or WordPress genius can get me started.

IT BEGINS
Jan 15, 2009

I don't know how to make analogies
Perhaps not a PHP-specific question, but:

I've got a bunch of records in a database that contains shipping information. In another table, I have invoice records that I have to match to these shipment records. The tricky part is that the information I need to identify a shipment is in one of three different fields in the invoice record - and I don't know which one. Not only that, but they can match either of two different fields in the shipment record.

I have to do some work on the charge records, so I am pulling them into PHP as InvoiceEntities using an Invoice mapper class. However, to match them against their respective shipments, I'm currently doing something like:

php:
<?
$conditions = [];
$fieldOne = $invoice->getFieldOne();
if ($fieldOne) {
    $conditions[] = ['shipment.testFieldOne = ?' => $fieldOne];
    $conditions[] = ['shipment.testFieldTwo = ?' => $fieldOne];
}

...

foreach ($conditions as $condition) {
    $result = $this->adapter->select('shipment', $condition);
    if ($result)
        return $result;
}
?>
Is there a better way of doing this? I suppose I could do some large SQL with a bunch of ORs in it, but it seems an equally poor idea, though it does cut down on the number of database calls.

Mister Chief
Jun 6, 2011

Why not just use a foreign key?

Adbot
ADBOT LOVES YOU

a lovely poster
Aug 5, 2011

by Pipski

Vasja posted:

Perhaps not a PHP-specific question, but:

I've got a bunch of records in a database that contains shipping information. In another table, I have invoice records that I have to match to these shipment records. The tricky part is that the information I need to identify a shipment is in one of three different fields in the invoice record - and I don't know which one. Not only that, but they can match either of two different fields in the shipment record.

I have to do some work on the charge records, so I am pulling them into PHP as InvoiceEntities using an Invoice mapper class. However, to match them against their respective shipments, I'm currently doing something like:

php:
<?
$conditions = [];
$fieldOne = $invoice->getFieldOne();
if ($fieldOne) {
    $conditions[] = ['shipment.testFieldOne = ?' => $fieldOne];
    $conditions[] = ['shipment.testFieldTwo = ?' => $fieldOne];
}

...

foreach ($conditions as $condition) {
    $result = $this->adapter->select('shipment', $condition);
    if ($result)
        return $result;
}
?>
Is there a better way of doing this? I suppose I could do some large SQL with a bunch of ORs in it, but it seems an equally poor idea, though it does cut down on the number of database calls.

This sounds like something that should be taking place in the query/orm. You shouldn't be using PHP to meld multiple tables into one dataset unless you really have to.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply