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
First Time Caller
Nov 1, 2004

What's the recommended PHP book path to become job-candidate worthy?

I'm looking at:

PHP from Novice to Professional 3rd Ed (to learn the language)
Pro PHP Patterns, Frameworks, and Testing (to learn to use the language)
and then a CodeIgniter book and user guide readthrough (to make poo poo easy once i know the basics)

Adbot
ADBOT LOVES YOU

Cpt.Wacky
Apr 17, 2005
What are some good ways to create full-featured forms? I'm not talking about simple contact forms or "sign up for a stupid newletter" stuff. I want to do multiple pages, custom validation, conditional display of fields, real-time updates, etc.

I found HTML_QuickForm2 but there doesn't seem to be any documentation besides the autogenerated API docs.

I found some other Javascript stuff like fValidator and iMask, and I've worked a little with jQuery before. I'd like to avoid AJAX at this point if possible.

So what are the best ways to create high quality, complex forms with PHP and Javascript?

First Time Caller
Nov 1, 2004

I've always just used jQuery. It's plenty powerful enough to do all that. A multi-step form is really just a form with tabs. Conditional display is really just show/hide. Validation jquery plugin makes validation stupid easy if you know some regex. Not sure what "real-time updates" means, but you're not going to avoid ajax in that regard.

Cpt.Wacky
Apr 17, 2005

First Time Caller posted:

I've always just used jQuery. It's plenty powerful enough to do all that. A multi-step form is really just a form with tabs. Conditional display is really just show/hide. Validation jquery plugin makes validation stupid easy if you know some regex. Not sure what "real-time updates" means, but you're not going to avoid ajax in that regard.

Sorry, that wasn't very clear. I meant updating a field based on other fields when the user enters data in the form. Like updating a total as they check off boxes. I'm pretty sure Javascript can do that.

Thanks for the rest of the tips. I was hoping there was something out there to make it a little easier, but it seems like the right way to do it is using a framework that has form stuff already. Unfortunately that isn't option for me, so it looks like I'll just have to do these one-off forms manually.

Begby
Apr 7, 2005

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

Cpt.Wacky posted:

Sorry, that wasn't very clear. I meant updating a field based on other fields when the user enters data in the form. Like updating a total as they check off boxes. I'm pretty sure Javascript can do that.

Thanks for the rest of the tips. I was hoping there was something out there to make it a little easier, but it seems like the right way to do it is using a framework that has form stuff already. Unfortunately that isn't option for me, so it looks like I'll just have to do these one-off forms manually.

You can't use jquery? Its not a framework, just a kick rear end javascript library that you include in your page that lets your work with the DOM in a non sucky way. You can still be writing all your forms manually, however jquery will make it really easy to access form element values, add stuff up, put totals in fields, hide / unhide fields, etc.

Cpt.Wacky
Apr 17, 2005

Begby posted:

You can't use jquery? Its not a framework, just a kick rear end javascript library that you include in your page that lets your work with the DOM in a non sucky way. You can still be writing all your forms manually, however jquery will make it really easy to access form element values, add stuff up, put totals in fields, hide / unhide fields, etc.

Yeah, I ended up using jQuery. It works but it's less elegant than I'd like, which could because I've only done a few small things with it before.

Masked Pumpkin
May 10, 2008
I working on storing information in a text file rather than a database, and reading it into an array with file(). The information looks something like this (it's a very small array used to create a dropdown menu):
code:
ID - MenuLinkID - Name - Position - URL
0    1            Test   1          [url]http://someurl.com[/url]
1    1            Test2  2          [url]http://anotherurl.com[/url]
2    2            Test3  1          [url]http://goatse.cx[/url]
I'm sure there's a better way to do this, but I've effectively copied my code from the database driven one already done and fudged it together to do much the same with text files instead.

The problem is that if I want to change the position of the rows for a given MenuLinkID, a simple foreach loop will change the values, but file() will still read it in the order it gets fed, and I need to change that (hell, possibly doing away with the position field altogether). A glance at sorting options in PHP reveal a number of options, but I don't see any clear way to do an associative sort of the array by a given index, and ensuring that that sort only applies to rows with the same MenuLinkID

Of course I could use the same foreach loop mentioned earlier to just swap the values of the rows in question, which does the trick but seems unnecessarily wasteful - for such a small array it's probably not a huge concern, but I'd rather do it the right™ way - any ideas?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I don't understand why you need to do this with a text file rather than a database, but suppose for the sake of the problem there is a good reason.

What is the ID "column" for? Is it used for anything? If you got rid of it and stored the rows in the form
code:
MenuLinkID - Position - Name - URL
instead, that would mean they'd already be stored in a sensible order, right? This is just the image in the new problem domain of making (MenuLinkID, Position) the primary key of your database table of list entries, in place of an artificial ID column.

Alternatively, why don't you comma-separate the columns in the text file (or separate them using some delimiter you will never put into the names or URLs), then you can go through and explode() the entries in the array returned by file(), and sort() them more or less easily.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Masked Pumpkin posted:

I don't see any clear way to do an associative sort of the array by a given index, and ensuring that that sort only applies to rows with the same MenuLinkID

Do you need to ensure that? If you sort() by position then yes, within position-groups there will be a jumble of rows with different MenuLinkIDs, but I assume that at some point you have a loop that builds up the drop-down list, or echoes it item-by-item or something. You could just add an if statement to the loop to make sure only the appropriate rows are treated.

Masked Pumpkin
May 10, 2008

Hammerite posted:

I don't understand why you need to do this with a text file rather than a database, but suppose for the sake of the problem there is a good reason.

What is the ID "column" for? Is it used for anything? If you got rid of it and stored the rows in the form
code:
MenuLinkID - Position - Name - URL
instead, that would mean they'd already be stored in a sensible order, right? This is just the image in the new problem domain of making (MenuLinkID, Position) the primary key of your database table of list entries, in place of an artificial ID column.

Alternatively, why don't you comma-separate the columns in the text file (or separate them using some delimiter you will never put into the names or URLs), then you can go through and explode() the entries in the array returned by file(), and sort() them more or less easily.

Sadly I had the database system up and running, and due to some other random stuff I was doing working with files, I set it for myself as a cool little project to learn about an aspect of PHP I've never really used before.

Because the whole thing here is web based, handled with a combination of GET and POST requests for different options (like changing the position of an item), having an ID for each item is necessary so that I know which item I'm actually meant to be changing.

The code I gave you was just a representation of the array, the file itself has all the values separated by '||' and with a new line for each new row. file() and explode() then return the values in an array that I can work with.

Hammerite posted:

Do you need to ensure that? If you sort() by position then yes, within position-groups there will be a jumble of rows with different MenuLinkIDs, but I assume that at some point you have a loop that builds up the drop-down list, or echoes it item-by-item or something. You could just add an if statement to the loop to make sure only the appropriate rows are treated.

This is a drat good idea - I hadn't thought of that at all. The question then is how I can sort by the position field instead of the normal index - I'm not seeing anything standing out in the documentation.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Masked Pumpkin posted:

The question then is how I can sort by the position field instead of the normal index - I'm not seeing anything standing out in the documentation.

The only thing that immediately occurs to me is to use array_multisort, as in

code:
$IDs         = array();
$MenuLinkIDs = array();
$Positions   = array();
$Names       = array();
$URLs        = array();

foreach ( $myarray as $key => $value ) {
    $explodedarray = explode($value, $delimiter);
    $IDs[]         = (int)$explodedarray[0];
    $MenuLinkIDs[] = (int)$explodedarray[1];
    $Names[]       = $explodedarray[2];
    $Positions[]   = (int)$explodedarray[3];
    $URLs[]        = $explodedarray[4];
}

array_multisort($MenuLinkIDs, $Positions, $IDs, $Names, $URLs);

Masked Pumpkin
May 10, 2008
Of course, now I understand how that sort works - the manual and examples given left me a bit confused. Thank you, kind sir!

I'm still a much bigger fan of databases - they're there exactly so I don't have to fiddle through text files, and ORDER BY clears up sorting problems, but I can see myself finding this useful at some point, I guess.

spiritual bypass
Feb 19, 2008

Grimey Drawer
It looks like you already have a working solution in place, but I suggest you take a look at
  • serializing
  • var_export
  • SQLite
  • XML, yaml, or even a CSV

Using a well known tactic next time could save you some headaches.

Masked Pumpkin
May 10, 2008

rt4 posted:

It looks like you already have a working solution in place, but I suggest you take a look at
[*]SQLite

There is not a big enough :doh: to describe this - it's enabled by default in PHP, so it's pretty much available on any server I might have to work on! I considered a small single file database, since I've used it before with great success, but I couldn't remember the name, and thought it might have been tinydb (it wasn't) but this... :doh:

I've still learned a lot about file management, which was the goal, and XML does seem like a great idea for the next step, so I'll do that, thanks.

Still... :doh: :doh: :doh:!

Mega Shark
Oct 4, 2004
I built a website for a Goon with some very basic PHP. As part of it he has a form that gets e-mailed to him, using the email() function.

It was working fine until last night when all of a sudden it started sending multiple duplicate e-mails. Has anyone seen this?

pre:
if($from == '')
	{
		print "You have not entered an email, please go back and try again";
	} 
	else 
	{ 
		$send = mail($to, $subject, $body, $headers); 
		$send2 = mail($from, $subject2, $autoreply, $headers2); 
 			
		if($send) 
 		{
			header( "Location: http://www." );
		} 
 		else 
 		{
			print "We encountered an error sending your mail, please notify membership@_______.com";
		} 

	}

gwar3k1
Jan 10, 2005

Someday soon

ODC posted:

I built a website for a Goon with some very basic PHP. As part of it he has a form that gets e-mailed to him, using the email() function.

It was working fine until last night when all of a sudden it started sending multiple duplicate e-mails. Has anyone seen this?

Is it doing it for all e-mail or just from one person? If it's just for one email address, I'd guess the user's not seeing the page load fast enough and are refreshing or they're refreshing on the "We encountered an error" page and you're getting the send request multiple times.

---

I'm starting to use templates and after googling, Smarty is my engine of choice. I understand the core principles of binding variables and including files from within template files themselves but I want to check something before going down an awkward path.

I have a body.tpl which is the main layout for my page. In it I have a title and pagecontent placeholders. I want to include another template in my pagecontent placeholder, it's a form and will be included conditionally from my business logic.

Doing the following doesn't work:
php:
<?
$smarty->assign('pagecontent', "{include file='form_newclient.tpl'}");  ?>
Am I looking at this problem the wrong way? Can I read template files into a variable to bind to placeholders using Smarty / should I do it myself?

Masked Pumpkin
May 10, 2008

ODC posted:

It was working fine until last night when all of a sudden it started sending multiple duplicate e-mails. Has anyone seen this?

My guess could be either, as gwar3k1 said, a user refreshing the page too quickly, or possibly some problem on the mail side with that server.

However, it seems as though that your mail function so far seems to be trying to send two messages - one ($send) with To, Subject, Body and Headers, and then another ($send2) with From, Subject, Autoreply and Headers. Mail should always at least have a From specified, though this can be set by default in php.ini, and so it's possible that the mail is being sent twice, albeit with slightly different information in each message.

I'd recommend something like the following:
php:
<?
if(!filter_var($from, FILTER_VALIDATE_EMAIL)) {
    print "You have not entered a valid email address, please go back and try again";
} 
else 
{ 
    $headers = "From: ".$from."\r\nReply-To: ".$autoreply;
    //I'm not sure if you have extra header information to insert here
    $send = mail($to, $subject, $body, $headers); 
    if($send) {
        header( "Location: [url]http://www.[/url]" );
    } 
     else {
        print "We encountered an error sending your mail, please notify membership@_______.com";
    } 

}
?>
I've also had great success with GETs on the redirected page, so you could enter the page to go to on success as index.php?email=1 for success or index.php?email=0 for failure, and have the page check for the existence of $_GET['email'] and echo an 'email sent' or 'email failed' as appropriate.

Of course, if you're going down that route, since you're getting the important information (perhaps just the email address), or whatever else POSTed to you anyway, you could redirect them back to the page with the email form on failure, and fill in the information they have already tried to submit to save them the hassle of doing it again.

Edited to fix a missing bracket

Masked Pumpkin fucked around with this message at 15:02 on May 16, 2010

SPACE CARBS
Jan 15, 2010

by Ozma
I am going to be coding a browser MMO sort of game, however long it takes, as a personal project.

I have programmed, I can do HTML/CSS/Flash|AS3 etc. so the thinking around coding is comfortable for me. I have not ever used PHP or SQL, though.

There are a few rough logistics things that I don't quite get, to start:

1) This is probably more an SQL question, but each player's account is going to include a pretty massive amount of data, much of which will be in constant flux. Am I just going to be making a single database here, with one row per player, and a poo poo-ton of columns for everything, or is it easier to divide it up by category (stats, wealth, location, etc) into separate databases? I'm thinking for scale here, should I ever actually develop a player-base.

2) The game will likely use a time-scale of some form, so that you can build something, and it would take 4 hours to complete. What on my server would run the hourly "tick"? Can I do this in PHP/SQL or am I going to need to add other things? I'm not adverse to bringing in other tech if I need it. Ideally while I'm developing I'd like to have manual control over the tick, as well.

Any other tips from people who've coded web games about problems they encountered and such are also appreciated.

Yay
Aug 4, 2007

SPACE WEED posted:

1) This is probably more an SQL question, but each player's account is going to include a pretty massive amount of data, much of which will be in constant flux. Am I just going to be making a single database here, with one row per player, and a poo poo-ton of columns for everything, or is it easier to divide it up by category (stats, wealth, location, etc) into separate databases? I'm thinking for scale here, should I ever actually develop a player-base.
Whilst I'll attempt to avoid sounding douchey here, you need to get your terminology right. Mostly, you will want it in one database, spread across multiple tables, into logic groups (eg: 'user', 'user_ally', 'resource_type', and so on). Worry about normalisation when scaling becomes an issue.

SPACE WEED posted:

2) The game will likely use a time-scale of some form, so that you can build something, and it would take 4 hours to complete. What on my server would run the hourly "tick"? Can I do this in PHP/SQL or am I going to need to add other things? I'm not adverse to bringing in other tech if I need it. Ideally while I'm developing I'd like to have manual control over the tick, as well.
I've never written any sort of browser based game, but cron seems a perfect candidate for hourly ticks.

SPACE CARBS
Jan 15, 2010

by Ozma

Yay posted:

Whilst I'll attempt to avoid sounding douchey here, you need to get your terminology right. Mostly, you will want it in one database, spread across multiple tables, into logic groups (eg: 'user', 'user_ally', 'resource_type', and so on). Worry about normalisation when scaling becomes an issue.

I've never written any sort of browser based game, but cron seems a perfect candidate for hourly ticks.

Well, my test server is a windows machine, so I wouldn't be using cron. I figured it would be done by a scheduler rather than PHP, which is what I needed to confirm

and yes, I have no actual experience with SQL terminology yet, just a basic understanding. I meant tables.

gwar3k1
Jan 10, 2005

Someday soon

SPACE WEED posted:

I am going to be coding a browser MMO sort of game, however long it takes, as a personal project.

I have programmed, I can do HTML/CSS/Flash|AS3 etc. so the thinking around coding is comfortable for me. I have not ever used PHP or SQL, though.

There are a few rough logistics things that I don't quite get, to start:

1) This is probably more an SQL question, but each player's account is going to include a pretty massive amount of data, much of which will be in constant flux. Am I just going to be making a single database here, with one row per player, and a poo poo-ton of columns for everything, or is it easier to divide it up by category (stats, wealth, location, etc) into separate databases? I'm thinking for scale here, should I ever actually develop a player-base.

2) The game will likely use a time-scale of some form, so that you can build something, and it would take 4 hours to complete. What on my server would run the hourly "tick"? Can I do this in PHP/SQL or am I going to need to add other things? I'm not adverse to bringing in other tech if I need it. Ideally while I'm developing I'd like to have manual control over the tick, as well.

Any other tips from people who've coded web games about problems they encountered and such are also appreciated.

1) Separate related data into individual tables: user accounts in one table, game data in others etc. You don't need individual databases to do this, just multiple tables. If that's something that is alien to you, its worth reading up on first rather than delving right into it.

2) Cron scripts can automate tasks at specified time intervals, but if you're not desparate for 100% realtime accuracy, just record the time the unit was created and compare to the current time every time the page loads. If its been x+ unitsoftime then set the unit to complete.

SPACE CARBS
Jan 15, 2010

by Ozma
Things are starting to come together in my head, thanks for clearing things up!

I picked up a PHP/SQL textbook, the sort that guides the reader through coding various little games and diversions to learn the various functions. Going to work through it end to end before I even think about actually making this browser game.

If CyberNations can take off and get poo poo-tons of users, I can definitely succeed, so long as I complete the project... so I'll take my time and do it right.

Is there anything I need to watch out for as far as migrating my stuff goes? I'm currently using a beat up old HP with XPSP3 and XAMPP to do my testing, but I will be putting some of my PHP/SQL work online (my own portfolio site, for one).

Moving the files over isn't a problem, but is there some "correct" way to get the database structure over other than rebuilding the tables by hand on my DreamHost?

Meshak
Apr 14, 2010
Complete beginner with hashing here, have a few questions. I work in PHP + MySQL so that's why I am posting here, though these aren't PHP-specific questions I suppose. Didn't really know where to post.



It seems, based on what I've read, that md5, sha1 and apparently more of the sha-family of hashing functions are more or less compromised. I've been unable to read my way to which hashing function I should use instead. Does it even matter that md5 and sha1 are compromised if I salt the hash with randomly generated numbers and letters (and symbols?)?

How should I store the key to the salt if it is randomly generated? If it's stored in the database with the hash of the password doesn't that make it simple to account for the salt if someone should get a hold of the database to try and steal the passwords?

Going further with the above thought, is storing the key to the salt in the database with the password more of a "You may get a few passwords, but it'll take you a billion billion years to get all of them" way of doing it than "complete security :airquote:"?

On the other hand, if I use 1 key to generate the salt for all the hashed passwords and the key is hardcoded in php, will that be safer?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
There has been a bit of discussion on encryption and hashing. I found a nice class I thought I would share.
http://www.tonymarston.co.uk/php-mysql/encryption.html

Meshak
Apr 14, 2010

drcru posted:

As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though.

Just for the sake of clarity, where should I store the salt for every person, optimally? In the database seems an obvious answer, but isn't it a bad solution? Should I just store the salts in a separate database?

I have read that the salts should be stored seperately, but I'm not entirely sure in which way. I am still a complete beginner with this.

Meshak fucked around with this message at 01:48 on May 17, 2010

DarkLotus
Sep 30, 2001

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

Meshak posted:

Just for the sake of clarity, where should I store the salt for every person, optimally? In the database seems an obvious answer, but isn't it a bad solution? Should I just store the salts in a separate database?

I have read that the salts should be stored seperately, but I'm not entirely sure in which way. I am still a complete beginner with this.

You could store information that is used to generate a salt.

For example, create a unique string from the name of the user and the date. Then take every other character and that is your salt. You can even limit the length.

Something like this:

User:
Jonathan Doe
$saltstring = md5('jonathan doe' . time());

Store $saltstring in the database and then you have a unique string for each and every user created. You then create a function to take a certain number of characters from the MD5 hash.

The following example will create a unique string which can be used to generate a unique SALT for each user. You get an MD5 of the user's name and current time, then remove every other character from that string and strip to 8 characters and you have a unique SALT. This is just an example and an idea. I just made it up and haven't used it so I can't say for sure how well it works :)

php:
<?
$name = "Jonathan Doe";
$saltstring = md5($name . time());

$userSalt = generate_salt($saltstring);

function generate_salt($string) {
  $new = "";
  for($i = 1; $i < len($string); $i += 2) {
    $new .= $string[$i];
  }
  $new = substr($new, 0, 8);
  return $new;
}
?>

DarkLotus fucked around with this message at 02:08 on May 17, 2010

Standish
May 21, 2001

drcru posted:

As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though.
You are correct that the MD5/SHA1 weaknesses are not (yet) a realistic way to crack hashed passwords, however why wouldn't you use SHA-256 when desigining a new system? It's one line of code to change and the attacks on MD5/SHA1 are only going to get better.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Meshak posted:

Just for the sake of clarity, where should I store the salt for every person, optimally? In the database seems an obvious answer, but isn't it a bad solution? Should I just store the salts in a separate database?

I have read that the salts should be stored seperately, but I'm not entirely sure in which way. I am still a complete beginner with this.

There's no point to storing them separately - if they have access to your database, they probably have access to the whole thing.

You can make a second salt that sits in a configuration file somewhere that is also added to the hash with the per-user salt for a little extra piece of mind. That would only help if they were somehow only able to see the contents of the database and not the code files as well.

Having said that, you should be using crypt() with blowfish if it supports blowfish on your server:
php:
<?
echo 'Does crypt() on this machine support the only useful cryptographic hashing ';
echo 'standard PHP has seen fit to include? ',CRYPT_BLOWFISH ? 'YES!':'Hah hah -No.';
?>
My install of wamp doesn't and neither do any of my company's servers or my cheapo shared hosting (last I checked), so I've been using SHA256, which is fine for now, but this all leads me to believe it's not very portable. It could be that we just never update PHP, though.

Munkeymon fucked around with this message at 20:53 on May 17, 2010

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



SPACE WEED posted:

Moving the files over isn't a problem, but is there some "correct" way to get the database structure over other than rebuilding the tables by hand on my DreamHost?

code:
mysqldump -d [-h host] -u root -p[password] databasename > dumpfile.sql
Create the database on the server
code:
mysql [-h host] -u user -p[password] databasename < dumpfile.sql
If you don't want to type your database passwords into a command line (you don't - command history is searchable on most shells) you just leave the part after -p blank and it prompts you for it.

Meshak
Apr 14, 2010
Munkeymon: Apparently my host supports it. I'll look into it. Thanks to everyone for the responses, I think I've managed to wrap my mind around this hashing business for now. :downs:

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Meshak posted:

Munkeymon: Apparently my host supports it. I'll look into it. Thanks to everyone for the responses, I think I've managed to wrap my mind around this hashing business for now. :downs:

I was looking for this earlier but couldn't find it: http://www.dereleased.com/2010/02/09/lets-talk-about-your-password-model/

corgski
Feb 6, 2007

Silly goose, you're here forever.

I've got a monolithic data source abstraction class that's shared between several applications, and I'm trying to trim it down by, ideally, making it load only the methods that are needed for that application, without running into any code duplication issues.

The obvious way of doing this would be something along the lines of "class foo extends foo" so I could then have foo.base.class.php, foo.writes.class.php, foo.othersource.class.php, foo.somemethod.class.php and foo.othermethods.class.php... and manage what's loaded by the includes but something seems so :downs: about that, and while I haven't tried it, I'm pretty sure PHP doesn't allow that anyway.

I'm sure I'm approaching this the wrong way, but I'm not sure what the right way is.

SPACE CARBS
Jan 15, 2010

by Ozma
edit: Thought this might be a server config issue but TankAuth works fine.

I am having a very strange problem with CodeIgniter.

I'm following a tutorial for building a login system and crud, and so far it's gone perfectly except for one thing.

I write to the session with

php:
<?
    function Login($options = array())
    {
        // required values
         if(!$this->_required(
             array ('userEmail', 'userPassword'),
            $options)
          ) return false;
         
        $user = $this->GetUsers(array('userEmail' => $options['userEmail'], 'userPassword' => md5($options['userPassword'])));
        if(!$user) return false;

        $this->session->set_userdata('userEmail', $user->userEmail);
        $this->session->set_userdata('userID', $user->userID);

        return true;
    }
?>
On the "dashboard", I have it set to read from the session with

php:
<?
echo "welcome to the dashboard " . $this->session->userdata('userEmail');
?>
The problem is that while it can properly check my email/pass against the database and send me to the dashboard (or deny me if the info is wrong), the dashboard looks like this:

quote:

welcome to the dashboard

Everything seems to be right to me, and I've autoloaded the session library and set up the ci_sessions database, but it just won't work.

The cookie does not appear to contain any userdata:

quote:

a:4:{s:10:"session_id";s:32:"36f76ae7550a825c27b86b264380ef8b";s:10:"ip_address";s:12:"192.168.1.42";s:10:"user_agent";s:50:"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv";s:13:"last_activity";s:10:"1274129699";}d29fdc27625bf7b8b1077b1b563d62ba

Neither does the (successfully saved) database entry:

quote:

session_id: 36f76ae7550a825c27b86b264380ef8b
ip_address: 192.168.1.42
user_agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv
last_activity: 1274129699
user_data:


wat i do rong :(

edit: and to clarify re: the IP, I have a test-server on my LAN at 192.168.1.145, and my main computer is 192.168.1.42 - the domain stuff in CI is set up properly, and everything else works so far except for the session's user_data.

SPACE CARBS fucked around with this message at 22:58 on May 17, 2010

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

I don't see anything MySQL related in your code. Did you forget to paste something?

SPACE CARBS
Jan 15, 2010

by Ozma

drcru posted:

I don't see anything MySQL related in your code. Did you forget to paste something?
I didn't paste everything because there's a lot.

Either way, I've abandoned the tutorial and I'm just working off TankAuth now, which is much more secure than anything I could make.

josh04
Oct 19, 2008


"THE FLASH IS THE REASON
TO RACE TO THE THEATRES"

This title contains sponsored content.

Hey Space Weed, a friend and I got a long way through writing a browser MMORPG a few months ago, but it sort of ran out of steam when exams came. Either way, the code design might give you a few ideas: http://github.com/josh04/quest/

We never really got round to game mechanics though.

SPACE CARBS
Jan 15, 2010

by Ozma

josh04 posted:

Hey Space Weed, a friend and I got a long way through writing a browser MMORPG a few months ago, but it sort of ran out of steam when exams came. Either way, the code design might give you a few ideas: http://github.com/josh04/quest/

We never really got round to game mechanics though.

Thanks, I'll take a look.

I've been hacking away at this thing since my first post, and I now have the auth system up and running. It can read various player data from a player-data table that is separate from the primary "player info" table, and the registration process creates an empty row in each table.

That was the part I was most uneasy about, so onto game-building!

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Loosely PHP-related.

I have a bunch of scripts (like, 7 or 8) that run as cron jobs. One of them runs every 15 minutes; the rest run anywhere from once a day to once a month.

I want to change the way I do things a bit. I want to split one of the things the once-every-15-minutes script does into its own cron job that runs every minute. At the same time, I'm happy for the other things done by that script to happen less frequently than they do at present.

This is straightforward so far but I also want some control over in what order things happen, when the job that is to be once-per-minute runs at the same time as another job. So I came up with the idea of having just one job that runs every minute and that looks at the time it is run (down to the minute) in order to determine what it does and in what order. To make sure it's not too intensive on the server when it is to do more than one thing, I'd chain jobs for it to do together with commands like sleep(2). All of my cron jobs are run with the nice -n 19 prefix.

Is this a reasonable approach to take to this? As in it's not likely to be too intensive on my host's server? Does anybody here do something like this themselves?

Adbot
ADBOT LOVES YOU

Fluue
Jan 2, 2008
I'm a bit perplexed by this scenario. I have a registerUser function that validates data and then inserts it into the database, but I want to be able to have error breaks. I also want to be able to load the page's HTML (including the footer, such as closing HTML tags) and still have the error displayed. The only way I can see exiting out of a function is by using:

php:
<?
function registerUser()
{
//some code here
if($var == false)
{
error = "This variable is false";
return die($error);
}
}
?>
But this causes the script to stop completely. How would I escape from a function and then still be able to finish creating the HTML page?

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