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
Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD

Agrikk posted:

if I do a print_r($SystemArray) I get:

code:
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => xx
                    [1] => xx
                )

            [1] => Array
                (
                    [0] => xx
                    [1] => xx
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => xx
                    [1] => xx
                )

            [1] => Array
                (
                    [0] => xx
                    [1] => Hello
                )

        )

)
Which is expected. "Hello" is in there. What's the best way to verify that is actually is in there?
Like fletcher said, "Hello" is not a value in $SystemArray. The values are all other arrays, so array_search is returning correctly. If you did arraysearch($str,$SystemArray[1][1]) it will return a key of 1.

If what you're looking to do is have an array search that probes down values that are arrays themselves, you'll probably have create one.

Here's one I quickly found in the comment section of php.net's array_search docs:
code:
<?php
function recursive_array_search($needle,$haystack) {
    foreach($haystack as $key=>$value) {
        $current_key=$key;
        if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) {
            return $current_key;
        }
    }
    return false;
}
?>
It looks like you'll only get the top level key though. I could see a use in modifying this to build back an array of keys.

Adbot
ADBOT LOVES YOU

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
So clearly I am doing something wrong and don't understand arrays :argh:

Why doesn't this work?

php:
<?php

//load up multidimensional array with "xx"
    for ($aa=0$aa 2;$aa++)
    {
        for ($bb=0$bb 2;$bb++)
        {
            for ($cc=0$cc 2;$cc++)
            {
                $SystemArray[$aa][$bb][$cc]="xx";
            }
        }
    }
    
//change one element to "Hello"
$SystemArray[1][1][1]="Hello";

//print array to be sure it's there
print_r($SystemArray);

//find "hello"
$IsThere="no";
for ($aa=0$aa 2;$aa++)
{
    for ($bb=0$bb 2;$bb++)
    {
        for ($cc=0$cc 2;$cc++)
        {
            if ($SystemArray[$aa][$bb][$cc]==="Hello"$IsThere="yes";
        }
    }
}

if ($IsThere="no") 
{
    echo "not found\n";
} else {
    echo "found\n";
}


?>
It returns "not found".

Standish
May 21, 2001

Agrikk posted:

if ($IsThere=="no")
Also using strings "yes" and "no" instead of booleans is just shameful.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Standish posted:

Also using strings "yes" and "no" instead of booleans is just shameful.

Getting off topic for a second, what does it matter if I use strings or booleans? Is it a performance issue or something?

Agrikk fucked around with this message at 19:43 on Oct 1, 2009

Standish
May 21, 2001

Agrikk posted:

Getting off topic for a second, what does it matter if I use strings or booleans? Is it a performance issue or something?
It's slower to use strings, yes, but the main thing is style and avoiding horrible bugs like
code:
$a = "no";
...
if ($a) // the string "no" converts to the boolean value true!

quote:

Oh motherfucker. Using booleans instead of strings actually made it all work.
No, it didn't, the problem was that you had a single '=' instead of a '==' in that line I quoted, so you were assigning $IsThere to "no" instead of checking its value. The reason it started working when you changed to booleans is because the assignment "$IsThere=false" itself evaluates to boolean false, so the if condition failed.

Standish fucked around with this message at 20:04 on Oct 1, 2009

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Standish posted:

It's slower to use strings, yes, but the main thing is style and avoiding horrible bugs like [php]$a = "no";
...
if ($a) // the string "no" converts to the boolean value true![/code]
No, it didn't, the problem was that you had a single '=' instead of a '==' in that line I quoted, so you were assigning $IsThere to "no" instead of checking its value. The reason it started working when you changed to booleans is because the assignment "$IsThere=false" itself evaluates to boolean false, so the if condition failed.

Thanks for your help Standish. I just realized that that was my error. I always get tripped up between =, == and ===. Meh.

playground tough
Oct 29, 2007
So lets say I more or less wanted a user to be able to set a date that they will receive an email and then have my script send it at that date. The thing is it needs to be accurate down to a few minutes. What would the best method to go about doing this? Cron job + mysql is what I was thinking through research but I havnt necessarily worked with these before but it wont be too hard for me to pick up on.

Hanpan
Dec 5, 2004

I'm upgrading my PHP framework, and I was thinking about URL routing / management. One thing I really liked about Django was urls.py (which is weird because that is normally what everyone hates about Django) and I was wondering if a similar system would lend itself to PHP, and whether or not it is a good way to do things. At the moment, I am taking the first segment of the URL and querying a database table of "apps" to match the slug and load the relevant controller. A url router array would probably be a nicer way of doing it as it means I can cut out the database query and use regex for more flexible urls strings.

Does anyone have a particularly nice way in which they handle url management with their apps? Are there any downsides or performance issues to using the system mentioned above?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Hanpan posted:

I'm upgrading my PHP framework, and I was thinking about URL routing / management. One thing I really liked about Django was urls.py (which is weird because that is normally what everyone hates about Django) and I was wondering if a similar system would lend itself to PHP, and whether or not it is a good way to do things. At the moment, I am taking the first segment of the URL and querying a database table of "apps" to match the slug and load the relevant controller. A url router array would probably be a nicer way of doing it as it means I can cut out the database query and use regex for more flexible urls strings.

Does anyone have a particularly nice way in which they handle url management with their apps? Are there any downsides or performance issues to using the system mentioned above?

I use something similar, only I don't define the list of valid objects in a database, I just do it in my main controller that handles the URL parsing. I set it up to handle plural/singular and route it to the same object controller (ie domain.com/users/browse or domain.com/user/profile). The only downside I see to the way you are doing it is that it's querying the database every time. For something that doesn't hardly changes, either just hard code it in or use memcache. Other than that my url routing isn't very fancy, it's basically a bunch of poo poo slapped around an explode("/", $url).

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

Hanpan posted:

Does anyone have a particularly nice way in which they handle url management with their apps? Are there any downsides or performance issues to using the system mentioned above?
Take a look at Kohana's source: http://dev.kohanaphp.com/projects/kohana2/repository/entry/trunk/system/libraries/Router.php
Look at routed_uri().

Hanpan
Dec 5, 2004

Funnily enough, I have just been rooking through Kohana's source. It's pretty well coded by drat they love singletons.

cLin
Apr 21, 2003
lat3nt.net
Is there a retard's guide to regular expressions or a book on it? I'm trying to do something with an xml file that has tags like
code:
<tag>
   <tag2>data</tag2>
   <tag3>more data</tag3>
</tag>

<tag>
   <tag2>data</tag2>
   <tag3>more data</tag3>
</tag>

And try to make it so I can grab the <tag> tags and allow me to manipulate the data inside or delete/add more but when I use preg_match_all ("/<tag>(.*?)<\/tag>/") on my file it never returns anything. Is there some hidden characters I am not aware of since I assumed . grabs all characters whether it's whitespace or not.

I've always found myself frustrated finding the correct expression to match the pattern I need so I just wanted to buy a book or something that starts off easy but gets into examples and what not.

cLin fucked around with this message at 03:54 on Oct 3, 2009

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Don't use regexps to parse xml.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

cLin posted:

Is there a retard's guide to regular expressions or a book on it? I'm trying to do something with an xml file that has tags like

I don't understand why you would even attempt to use regular expressions. Did you even try searching "php xml" in Google?

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Plorkyeran posted:

Don't use regexps to parse xml.

Aw, c'mon. I do it all the time. Granted, I'm usually checking for the existence of "AuthSuccess" in the document and I don't care about the rest of it.

But yeah, if you want to keep the structure and all you might need to use an XML parser.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
I'd recommend trying SimpleXMLElement first. It's easy to use and works great for most situations where you need to read XML.

cLin
Apr 21, 2003
lat3nt.net
Ok, sorry guys. I'll look into XML parsers now..still, I'd like to learn regular expressions since it looks scary but powerful. I'd still like some recommended reading.

jasonbar
Apr 30, 2005
Apr 29, 2005

cLin posted:

Ok, sorry guys. I'll look into XML parsers now..still, I'd like to learn regular expressions since it looks scary but powerful. I'd still like some recommended reading.

http://regular-expressions.info

wmbest2
Sep 25, 2009

cLin posted:

Ok, sorry guys. I'll look into XML parsers now..still, I'd like to learn regular expressions since it looks scary but powerful. I'd still like some recommended reading.

Not really a reading resource but this site was priceless when I was learning regular expressions.

http://gskinner.com/RegExr/

insidius
Jul 21, 2009

What a guy!
I am new at this so please forgive. I had another post in here and I finished that up well.

Ive decided I want to implement a stats system and I planned ahead for this, well I thought I did at least.

I have a date_submitted and a date_completed field. Both are INT fields using unix timestamps, I have a 3rd field that contains the task of which there are 3 types and a 4th field that says completed or not.

I already figured out how to use count to get the number of records to match them by type and spit out the results but I cant figure out exactly how to get records ONLY from the last 7 days that are marked completed. I can get completed and narrow it down to type but not to time.

This might belong in an SQL thread I guess now I think about it? Can anyone point me in the right direction for this? Im happy with just a mysql link.

Standish
May 21, 2001

insidius posted:

I already figured out how to use count to get the number of records to match them by type and spit out the results but I cant figure out exactly how to get records ONLY from the last 7 days that are marked completed. I can get completed and narrow it down to type but not to time.
code:
select * from records where taskstatus='completed' and date_submitted > (unix_timestamp() - (60 * 60 * 24  * 7))
But really, just use the MySQL DATETIME data type...

insidius
Jul 21, 2009

What a guy!

Standish posted:

code:
select * from records where taskstatus='completed' and date_submitted > (unix_timestamp() - (60 * 60 * 24  * 7))
But really, just use the MySQL DATETIME data type...

Thank you! I figured that was but my problem was never being good at maths or programming was that I was not sure how to structure the last part of the query.

There was a reason I did not use the mysql DATETIME but I cant remember for the life of me why now...

eHacked
Sep 30, 2003

CONGRATULATIONS!!! YOU ARE THE 6,127,436,218TH PERSON TO VIEW THIS USELESS POST. CLICK TO CLAIM YOUR PRIZE!!!
Hello friends :)

I am trying to pass some variables via exec.

Here is my code:

code:
exec("/usr/local/bin/php -q galleryHandling.php --task=50 > log.log &");
from my understanding,
code:
$argv[1];
should contain the passed information, right? It should have "task=50"... right?

Well obviously I'm missing something because no variables seem to be passed!

Standish
May 21, 2001

eHacked posted:

Hello friends :)

I am trying to pass some variables via exec.

Here is my code:

code:
exec("/usr/local/bin/php -q galleryHandling.php --task=50 > log.log &");
from my understanding,
code:
$argv[1];
should contain the passed information, right? It should have "task=50"... right?

Well obviously I'm missing something because no variables seem to be passed!

Are you using the CGI php binary instead of the CLI PHP binary?

http://www.php.net/manual/en/features.commandline.php

eHacked
Sep 30, 2003

CONGRATULATIONS!!! YOU ARE THE 6,127,436,218TH PERSON TO VIEW THIS USELESS POST. CLICK TO CLAIM YOUR PRIZE!!!

Standish posted:

Are you using the CGI php binary instead of the CLI PHP binary?

http://www.php.net/manual/en/features.commandline.php

PHP 5.2.5 (cli) (built: Feb 4 2008 17:09:00)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with the ionCube PHP Loader v3.1.34, Copyright (c) 2002-2009, by ionCube Ltd., and
with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
with Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies

Showing cli. I can't figure out what the problem is >=[

cka
May 3, 2004
Is this enabled in your php.ini file?

code:
; This directive tells PHP whether to declare the argv&argc variables (that
; would contain the GET information).  If you don't use these variables, you
; should turn it off for increased performance.
register_argc_argv = On
I tested your argv thing on a server here and it works just fine, so this is probably your issue if the $argv array isn't being set on a cli script...

Sirotan
Oct 17, 2006

Sirotan is a seal.


Let me preface this post by saying I know almost nothing about PHP.

I am building this website for an academic workshop and the professor wants me to have an interactive form that students will fill out, which will then be emailed to him. After much tinkering and research I guess my best bet is to use PHPMailer. The first step to using it seems to be modifying the php.ini file(?). I don't think I have access to this since our webspace is just virtual hosting through my school's (lovely) IT department. Is this step absolutely necessary? If so is there any work around?

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Sirotan posted:

Let me preface this post by saying I know almost nothing about PHP.

I am building this website for an academic workshop and the professor wants me to have an interactive form that students will fill out, which will then be emailed to him. After much tinkering and research I guess my best bet is to use PHPMailer. The first step to using it seems to be modifying the php.ini file(?). I don't think I have access to this since our webspace is just virtual hosting through my school's (lovely) IT department. Is this step absolutely necessary? If so is there any work around?

You are opening a can of worms, especially if you are new to programming. If all you want to do with PHP ever is to create this form, do it a different way.

You could create a free google apps account and create a form online through there.

I haven't messed around with wordpress, but you could probably create a free blog and set it up to send out forms.

There has got to be online services that do this for a low cost if not free.


However, if you are experienced with programming, just create a simple test.php page with something like <?php echo 'taco' ?> in it and load it up and see if it works. If it does then try out the mail() command - http://us.php.net/manual/en/function.mail.php

If the mail command works then you aren't going to need to modify the php.ini, and if you are just sending some text it should work just fine without you needing to mess with php mailer.

crabrock
Aug 2, 2002

I

AM

MAGNIFICENT






hopefully somebody can tell me what the gently caress i'm doing wrong. I've tried googling this, trying all sorts of things, and nothing seems to work and it's frustrating. It looks like i'm doing the same things everybody else is doing but i'm obviously loving something up.

I cannot get my sessions to last for more than a few days. I want to stay logged in indefinitely or until i destroy the session. unfortunately randomly every few days I'm logged out, even though the cookie says 5 years or something crazy, the session id in the cookie is still in my tmp folder. :cry: help

this is basically what i have

php:
<?
session_name("PHPSESSID");
session_set_cookie_params(155520000,"/");
session_start();

print $_COOKIE['PHPSESSID'];

if (isset($_SESSION['userid'])) {
    // Do poo poo
} else {
    // Display Login
}

?>
where the session variables are set on login. This is where i'm totally lost. Everything works perfectly for 1-2 days, then it prompts me to login again.

Included the screenshot of the cookie, the printed cookie, and the tmp folder session in case any of that is relevant

Only registered members can see post attachments!

Sirotan
Oct 17, 2006

Sirotan is a seal.


Begby posted:

You are opening a can of worms, especially if you are new to programming. If all you want to do with PHP ever is to create this form, do it a different way.

You could create a free google apps account and create a form online through there.

I haven't messed around with wordpress, but you could probably create a free blog and set it up to send out forms.

There has got to be online services that do this for a low cost if not free.


However, if you are experienced with programming, just create a simple test.php page with something like <?php echo 'taco' ?> in it and load it up and see if it works. If it does then try out the mail() command - http://us.php.net/manual/en/function.mail.php

If the mail command works then you aren't going to need to modify the php.ini, and if you are just sending some text it should work just fine without you needing to mess with php mailer.

Yeah after several hours of frustration I was able to just put up a simple form mailer using mail() that worked, its just that it isn't very elegant and I don't know if I can use that send attachments. Also reading a few guides it seems that isn't a very secure way of handling it.

I will definitely check out google aps, we are actually planning on putting in a wordpress blog in the future but he wants this form up like now so I don't think I will have time to mess around with that.

Basically, the guy I'm making this site for is totally computer illiterate, he initially wanted me to create something like cTools, U of M's online coursework management system, an application my university uses for its 50,000+ study body, just so that the MAYBE 150 students that will apply to this workshop could check on the status of their applications online. His expectations are completely unrealistic, so he is gonna have to be happy with what I give him or he can hire a bunch of dedicated coders and spend up the wazoo to get what he really wants.

Standish
May 21, 2001

crabrock posted:

http://uk3.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime?

crabrock
Aug 2, 2002

I

AM

MAGNIFICENT







I already tried that :\

edit: would session auto start do anything?

Only registered members can see post attachments!

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.

crabrock posted:

I already tried that :\

edit: would session auto start do anything?

From vague memory, auto_start just specifies whether to create a session on every request, rather than just those that call session_start()

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Murodese posted:

From vague memory, auto_start just specifies whether to create a session on every request, rather than just those that call session_start()

Why wouldn't that be a php.ini setting?

Anveo
Mar 23, 2002

fletcher posted:

Why wouldn't that be a php.ini setting?

Do you mean why wouldn't that be on by default? Overhead in various areas. If you are doing disk based storage that's an extra filesystem read/write *every* request, even if it's not needed. If your session save path isn't partitioned and you have a fairly busy site you might be stressing your file system with too many files in a directory. If you have db based storage that's an extra db read/write every request. Plus that is extra data in the HTTP header the client has send each time.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Anveo posted:

Do you mean why wouldn't that be on by default? Overhead in various areas. If you are doing disk based storage that's an extra filesystem read/write *every* request, even if it's not needed. If your session save path isn't partitioned and you have a fairly busy site you might be stressing your file system with too many files in a directory. If you have db based storage that's an extra db read/write every request. Plus that is extra data in the HTTP header the client has send each time.

It was meant as a joke.

crabrock
Aug 2, 2002

I

AM

MAGNIFICENT






So does nobody know why my sessions aren't keeping? is it something i should bring up to my host? I wanted to see if there was anything wrong with my code, but nobody has said anything either way. :(

DarkLotus
Sep 30, 2001

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

crabrock posted:

So does nobody know why my sessions aren't keeping? is it something i should bring up to my host? I wanted to see if there was anything wrong with my code, but nobody has said anything either way. :(
If you want to look at a simple example that works, checkout the following class. It is simple, works and can easily be modified for whatever you are trying to accomplish. It gives you the option to save a cookie for staying logged in, or just logging in everytime. It seems to work pretty well for a project I am working on. If this doesn't work, then it might be something with your host.
http://phpuserclass.com

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

crabrock posted:

So does nobody know why my sessions aren't keeping? is it something i should bring up to my host? I wanted to see if there was anything wrong with my code, but nobody has said anything either way. :(

Is your host erasing the contents of /tmp on the server every couple of days? Or is there a cron job that goes in there and deletes everyting that is x days old?

The session ID cookie is used by PHP to find and restore the session server side. If you are saving a logged in value on the server, and its gone, then PHP will makre the user as logged out.

You might want to create your own session handler that saves the session data to a db if you can, that would fix this problem.

Adbot
ADBOT LOVES YOU

DarkLotus
Sep 30, 2001

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

Begby posted:

Is your host erasing the contents of /tmp on the server every couple of days? Or is there a cron job that goes in there and deletes everyting that is x days old?

The session ID cookie is used by PHP to find and restore the session server side. If you are saving a logged in value on the server, and its gone, then PHP will makre the user as logged out.

You might want to create your own session handler that saves the session data to a db if you can, that would fix this problem.

Zebra Framework has a good Sessions class.
http://stefangabos.blogspot.com/search/label/Sessions%20Management%20PHP%20Class%20Download

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