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
Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.
Well I wanted it to change on the fly just by selecting one of the options, a submit button just for that select statement looks ugly on my page. Maybe I should approach this problem a different way altogether??

Adbot
ADBOT LOVES YOU

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

mewse posted:

how are you submitting the form without a button?
You can use document.forms['formID'].submit() in Javascript to submit the form without a button - just assign that function to an element's onClick, onFocus, etc...

Mindisgone posted:

Well I wanted it to change on the fly just by selecting one of the options, a submit button just for that select statement looks ugly on my page. Maybe I should approach this problem a different way altogether??
If you're talking about submitting a form after selecting an item in a dropdown, you can assign the above submit function to onChange on a <select> element - so long as the <select> element has a name, it'll get passed along to the server within the $_POST variable.

mewse
May 2, 2006

Mindisgone posted:

Well I wanted it to change on the fly just by selecting one of the options, a submit button just for that select statement looks ugly on my page. Maybe I should approach this problem a different way altogether??

I think you are a bit unclear on how HTTP works. PHP's $_POST variable is populated with the data from a submitted form, that implies an html <form> tag and a submit button. If you want to skip the button you can probably find javascript that will submit the form when the value of your combobox (or whatever you're using) changes.

If you want the page to alter content dynamically based on what the user is doing, you will have to start looking into AJAX which is the go-to tool for dynamic content, but requires a decent understanding of HTML, Javascript, AND the PHP backend.

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.
well even this way

code:
$countryresult = $_POST;
print_r($countryresult);

if ($countryresult["country"] == "United States of America") {
$file_handle = fopen("states.txt", "r");
} else {
$file_handle = fopen("canuck.txt", "r");	
}

$states = array();
while (!feof($file_handle) ) {
    $stateline = fgets($file_handle);
    $statesfin = explode('\n', $stateline);
    $states[] = $statesfin[0];
}
fclose($file_handle);
code:
<form id="countrys" name="countrys" onChange="setStyle(country.id,states.id,towns.id)" method="post" action="">
  <span id="spryselect1">
  <select name="country" id="country">
    <option value="nothing">Country</option>
    <option value="usa">United States of America</option>
    <option value="canada">Canada</option>
  </select>
  <input name="submit" type="button" />
  </span>
    </form>
I'm not getting the desired outcome, I am a noob at this.

Impotence
Nov 8, 2010
Lipstick Apathy
edit:n evermind

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.

Biowarfare posted:

edit:n evermind

well were you suggesting I use JS for the whole thing cause I'm leaning in that direction now

Impotence
Nov 8, 2010
Lipstick Apathy

Mindisgone posted:

well were you suggesting I use JS for the whole thing cause I'm leaning in that direction now

It's only a few items and they're not really going to change, I don't see why bother with an additional HTTP request for what is essentially static data - toss everything into a JS array and populate a select box onchange?

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.
well let me finish painting this picture anyway so there is a full understanding and yes my variable names suck but I'm not to creative

code:
function createDropdown($arr) {
	foreach ($arr as $key => $value) {
		echo '<option value="'.$value.'">'.$value.'</option>';
		print $countryresult;
	}
}
that works if I say something like $file_handle = fopen("states.txt",'r');
and the reason I want the value to beable to change on the fly is so the next boxes values relate to which country you pick

code:
<form id="states" style="visibility:hidden" name="states" method="post" action="">
  <span id="spryselect2">
 	<select name="statesnprov" id="statesprov" onChange="setStyle(statesprov.id,towns.id)">
    	<option value="nothing">StateTerritoryProvince</option>
<?php createDropdown($states); ?>
	</select>
    </span>
</form>

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
If you're looking to automatically populate a dropdown with a list of states in either the US or Canada based on a user's selection, the cleanest way will be to submit a call to a PHP page via AJAX after the user has selected their country. Your PHP code would be great for generating a list of states via PHP - now you just have to work in some AJAX that will submit the value of your "country" dropdown, and then use Javascript to manipulate the $states[] array into another dropdown below the "country" one.

Mindisgone posted:

code:
<form id="countrys" name="countrys" onChange="setStyle(country.id,states.id,towns.id)" method="post" action="">
  <select name="country" id="country">
    <option value="">Country</option>
    <option value="usa">United States of America</option>
    <option value="canada">Canada</option>
  </select>
  <input name="submit" type="button" />
    </form>

I've also made some changes to your markup - <span> is an inline element, so you should replace it with a <div> or get rid of it. Also, I set the value of your default Country <option> to "" because it'll be easier to check for no value than a specific "there's no information here" value.

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.
found a mistake in my code that now makes the submit button work they way I want

code:
if ($countryresult["country"] == "usa") {
and
code:
 <input name="submit" type="submit" value="Submit" />
but consider this, when I select usa and hit submit the states select choices change but now the page refreshes and the countries box has "Country" selected again instead of showing usa, and it's annoying for the user to have to resubmit everytime they need the states box values to reflect the country they're from

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Mindisgone posted:

but consider this, when I select usa and hit submit the states select choices change but now the page refreshes and the countries box has "Country" selected again instead of showing usa, and it's annoying for the user to have to resubmit everytime they need the states box values to reflect the country they're from
To combat that, try the following:

code:
<option <?php if(isset($_POST['country']) && $_POST['country'] == "usa" { echo "selected=\"selected\" ";} ?> value="usa">United States of America</option>
Then do the same for Canada, only replace "usa" with "canada". That will preserve the user's selected country when the page refreshes.

EDIT: I used isset() because it should avoid any error messages about $_POST['country'] not being set (as the case would be when a user accesses your page for the first time).

IAmKale fucked around with this message at 18:12 on Nov 16, 2011

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.
that works great but it looks like Ihave to get on this ajax cause I have even more going on with this form anyway and it won't work as is (also I want to get rid of the button and ajax seems to be the only way)

code:
<script type="text/javascript">
function setStyle(x, y, z){
if (document.getElementById(x).selectedIndex != 0){
document.getElementById(y).style.visibility="visible";
} else
{ document.getElementById(y).style.visibility="hidden";
	document.getElementById(z).style.visibility="hidden"; }
}
</script>
so while now the selction in country stays selected it doesnt keep the next dropdown unhidden i have to submit the button then select "Country" and then my choice again to unhide the states field, I'm a little back to the drawing board on this one till I get some ajax under my belt (by today :doh:)

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Mindisgone posted:

so while now the selction in country stays selected it doesnt keep the next dropdown unhidden i have to submit the button then select "Country" and then my choice again to unhide the states field, I'm a little back to the drawing board on this one till I get some ajax under my belt (by today :doh:)
If time is of the essence, pick up JQuery and read up on its AJAX functionality, specifically JQuery.Post. There's still a learning curve with it, but it's a lot easier than trying to develop an AJAX solution from scratch on your own. Good luck.

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.

Karthe posted:

If time is of the essence, pick up JQuery and read up on its AJAX functionality, specifically JQuery.Post. There's still a learning curve with it, but it's a lot easier than trying to develop an AJAX solution from scratch on your own. Good luck.

thank you very much for your help :tipshat:

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is a totally newb question, but I'm getting my feet wet with this stuff and decided to grab Eclipse 3.7 Classic w/ PDT. This seems ok, and I've used Eclipse in the past for other stuff.

So I try to install the Zend debugger from Help > Install Software and enter the URL suggested 'http://downloads.zend.com/pdt' and it seems to work, but then errors out after the EULA step. I've been reading and apparently the Zend url/site is messed up in regards to Indigo. Have you guys encountered this problem and figured out an easy way around it?

revmoo
May 25, 2006

#basta
I'm building a 'forgot password' system and I need to generate a hash for the user to click on in the email. I'm using a hash string of their password hash + time(). Is this a pretty secure solution?

McGlockenshire
Dec 16, 2005

GOLLOCKS!

quote:

I'm building a 'forgot password' system and I need to generate a hash for the user to click on in the email. I'm using a hash string of their password hash + time(). Is this a pretty secure solution?

So, this?
php:
<?php
$clicky sha1sha1($password) . time() );
The thing you care about here isn't making it secure as much as making it reasonably unique. Under this specific system, if I knew the password of the user (remember, users tend to reuse passwords), I could guess the time on your server and simply brute-force the correct link. (Then again, if I knew the user's password, I wouldn't need the link...)

Use a hash of actual random data, not something that could be either derived or guessed. Consider reading from /dev/urandom. If you're using 5.3, consider using openssl_random_pseudo_bytes. I've become a fan of ircmaxell's PHP-CryptLib, which contains pure-PHP implementations of some useful crypto routines including a secure random generator.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

revmoo posted:

I'm building a 'forgot password' system and I need to generate a hash for the user to click on in the email. I'm using a hash string of their password hash + time(). Is this a pretty secure solution?

I would say it's not worth hashing their password. I mean, they've forgotten it, and passwords aren't necessarily unique. If you're doing any hashing like this, part of your hash should be the unique user identifier, which is usually the userid, not the password (or possibly even the username).

DarkLotus
Sep 30, 2001

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

revmoo posted:

I'm building a 'forgot password' system and I need to generate a hash for the user to click on in the email. I'm using a hash string of their password hash + time(). Is this a pretty secure solution?

$hash = sha1(session_id() . "something else");

very simple, unique and impossible to guess.

revmoo
May 25, 2006

#basta
To clarify, I'm creating a sha1 hash based on the existing sha256 salted password hash plus the output of date(). I feel this is more secure because if someone was able to (theoretically) get ahold of a session id of another user they could potentially predict what the hash string would be to reset a password. With my method, there's no chance of that.

Also to further clarify, this hash I'm creating is ONLY used to send the user an email to click on to reset their password. It's deleted from the db once the reset has been performed.

mewse
May 2, 2006

What's the best/simplest lib to implement server-side generation of PDFs? Is there a built-in one I could use? TCPDF's license looks obnoxious.

e: going to try fpdf i think

mewse fucked around with this message at 19:24 on Nov 17, 2011

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

mewse posted:

What's the best/simplest lib to implement server-side generation of PDFs? Is there a built-in one I could use? TCPDF's license looks obnoxious.

e: going to try fpdf i think
It's been a while since I've worked with PDF's in PHP, but the last time I did I used EZPDF. It looks like development ceased around 2006, but it continues to work fine with PHP 5.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

revmoo posted:

To clarify, I'm creating a sha1 hash based on the existing sha256 salted password hash plus the output of date().

Ah, that should be fine then... though consider microtime(true) instead.



mewse posted:

What's the best/simplest lib to implement server-side generation of PDFs?
If you're allowed to call binaries, wkhtmlktopdf is pretty much the best you're going to find. It uses the Webkit rendering engine, as used in Chrome, Safari, the iPhone, etc, to process HTML and generate PDFs. There are precompiled versions for Linux that you can simply drop somewhere and execute, no need to actually install anything on the server.

mewse
May 2, 2006

McGlockenshire posted:

If you're allowed to call binaries, wkhtmlktopdf is pretty much the best you're going to find. It uses the Webkit rendering engine, as used in Chrome, Safari, the iPhone, etc, to process HTML and generate PDFs. There are precompiled versions for Linux that you can simply drop somewhere and execute, no need to actually install anything on the server.

That's pretty cool, but implementing my idea in FPDF turned out to be really painless.

One of the reasons I wanted to export to PDF is that one of the database fields is free-form and the user is entering a bunch of text that might not all display inside the textarea. I guess I could've written a view-only version of the HTML but writing the PDF code was just as easy.

Spasms
Jun 11, 2003

I'm gettin' heartburn. Tony, do something terrible.
I have a mobile web page that is listing 8 categories, each one containing about 50-100 divs listed one after another, each div containing an image, and a bunch of text. The data is all stored in a database and pulled into the model and the controller passes the appropriate data to view when the page loads based on the user's filters and some other information.

The page is currently taking a long time to load because of the abundance of information being pulled from the database. The plan is to initially show 5 items in each category with a link at the bottom of the category to view the total list of items in that category.

The idea is that when the link is clicked, the additional items will be pulled from the database and appended to the current 5 items using a jQuery post or get call without reloading the page. I was considering showing the first entire category/items and loading the next category when the user scrolls to the bottom of the page Twitter style but I'm not sure if this is the best idea for a mobile website.

I am having trouble wrapping my head around what needs to happen between the "display all" link being clicked, the data being appended in the view and the most efficient way to do it. I am open to other methods of achieving the same initial load speed improvement. Any suggestions, resources, examples would be appreciated.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Spasms posted:

I have a mobile web page that is listing 8 categories, each one containing about 50-100 divs listed one after another, each div containing an image, and a bunch of text. The data is all stored in a database and pulled into the model and the controller passes the appropriate data to view when the page loads based on the user's filters and some other information.

The page is currently taking a long time to load because of the abundance of information being pulled from the database. The plan is to initially show 5 items in each category with a link at the bottom of the category to view the total list of items in that category.

The idea is that when the link is clicked, the additional items will be pulled from the database and appended to the current 5 items using a jQuery post or get call without reloading the page. I was considering showing the first entire category/items and loading the next category when the user scrolls to the bottom of the page Twitter style but I'm not sure if this is the best idea for a mobile website.

I am having trouble wrapping my head around what needs to happen between the "display all" link being clicked, the data being appended in the view and the most efficient way to do it. I am open to other methods of achieving the same initial load speed improvement. Any suggestions, resources, examples would be appreciated.


code:
jQuery('#getNextButton').click( function() {

jQuery.get('nextFive.php?startIndex=5', function (data){
  jQuery('#someDiv').append( parseDataIfNeeded(data) );
});

});
Obviously that's not best practice jQuery, but that's how you do it given one list and one button.


The "load some, then let the user request the rest" is a good way of doing the UX here. Gives enough data up front to be snappy, and enough for the user to see if the do want more in a category without loading tons of data they might not want. I'd go with loading more than five at a time, but that will depend mor on user testing / use cases than actual data size (unless each thing in the list is huuuuuuuge)

Lumpy fucked around with this message at 16:46 on Nov 19, 2011

klem_johansen
Jul 11, 2002

[be my e-friend]
I'm sending out confirmation emails from a site using PHPMailer and for most folks it works fine. However, a few people aren't receiving the messages (not even in spam) because they're getting killed by SpamAssasin, etc. even though the site hasn't sent out unsolicited mail at all. Is there anything I can do?

Impotence
Nov 8, 2010
Lipstick Apathy

klem_johansen posted:

I'm sending out confirmation emails from a site using PHPMailer and for most folks it works fine. However, a few people aren't receiving the messages (not even in spam) because they're getting killed by SpamAssasin, etc. even though the site hasn't sent out unsolicited mail at all. Is there anything I can do?
Use a legitimate-mail-enforcing service like sailthru.com or something, instead of trying to run it yourself.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

klem_johansen posted:

I'm sending out confirmation emails from a site using PHPMailer and for most folks it works fine. However, a few people aren't receiving the messages (not even in spam) because they're getting killed by SpamAssasin, etc. even though the site hasn't sent out unsolicited mail at all. Is there anything I can do?

You should check the status of your IP regardless. Some of the lists (SURBLS) will automatically list your IP because it might be in a dynamic range for example (e.g. a home connection). This is a good way to check:
http://www.robtex.com/ip/x.y.z.a.html

klem_johansen
Jul 11, 2002

[be my e-friend]

Scaramouche posted:

You should check the status of your IP regardless. Some of the lists (SURBLS) will automatically list your IP because it might be in a dynamic range for example (e.g. a home connection). This is a good way to check:
http://www.robtex.com/ip/x.y.z.a.html

There are two possibilities: 1) the server is on a shared account so somebody could have done something stupid and burned the IP and/or 2) the client sent out an email blast without my knowledge a while back and if they used a purchased list (which I advised against) they could have been blacklisted. I didn't see any blacklist items when I checked, though.

mewse
May 2, 2006

klem_johansen posted:

Is there anything I can do?

i was gonna suggest you have users forward you the spamassassin results to investigate how you're scoring as spam (spamassassin will list which tests you failed), but reading your problem again it sounds like the messages aren't even arriving.

maybe you can try sending with a From: that says noreply@your.domain.com, then actually set up the noreply address and see if you are getting bounce messages. those might indicate why you're getting shut out

supernothing
May 18, 2004
Buy me a custom title
I am trying to pull the contents of a text file and display it as the default text in a text field, but for some reason, every time I do there is a space at the front of it. Here is the code...

code:
<form action="inc/mptext.php" method="post">
Text: <textarea type="text" name="pdetail" rows="12" class="textboxwidth">
<?PHP echo $theData;?>
</textarea>
<input type="submit" />
</form>
Earlier in the script, I define theData using

code:
$theData = file_get_contents("inc/pricefile.txt");
Any help? When I open the file, the blank space isn't there, just in this text box.

mewse
May 2, 2006

i'd try removing the newline before your <?php> block, ie.

code:
Text: <textarea type="text" name="pdetail" rows="12" class="textboxwidth"><?PHP echo $theData;?></textarea>

supernothing
May 18, 2004
Buy me a custom title
Well by god, that did it. Thank you, sir!

Such hell....for nothing!

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

supernothing posted:

Well by god, that did it. Thank you, sir!

Such hell....for nothing!
<pre> tags will do the same thing, so if you ever work with them in the future just keep that in mind. :)

indulgenthipster
Mar 16, 2004
Make that a pour over
I'm trying to make an automated installer / configuration utility for a framework and I've hit a snag. The configuration file is one giant array. Creating the array is no problem, however creating a file in it's place (using something like fwrite) with that array in a usable form has be stuck. Any ideas? Serialization is unfortunately not an option.

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

VerySolidSnake posted:

I'm trying to make an automated installer / configuration utility for a framework and I've hit a snag. The configuration file is one giant array. Creating the array is no problem, however creating a file in it's place (using something like fwrite) with that array in a usable form has be stuck. Any ideas? Serialization is unfortunately not an option.

Are you looking for something like var_export()?

indulgenthipster
Mar 16, 2004
Make that a pour over

Tiny Bug Child posted:

Are you looking for something like var_export()?

I always thought var_export() was just a representation of the array, but can it be used as a usable, working array if written to a file?

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

the php manual posted:

var_export() gets structured information about the given variable. It is similar to var_dump() with one exception: the returned representation is valid PHP code.

Adbot
ADBOT LOVES YOU

indulgenthipster
Mar 16, 2004
Make that a pour over
I was thinking of var_dump() that entire time, thank you!

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