-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
That line is missing a comma.
-
You're sorting the variable $bookArray, but your looping over $_SESSION['book_array']. You need to sort the same variable you loop over.
-
Config database table - Query time vs Memory usage.
kicken replied to ttocskcaj's topic in Application Design
If your just talking about some config options, I'd say load them all at once. It probably won't take up that much memory (unless you have a ton of options) and having quick access too them would probably be best. You can setup a class for them which will load them all at what ever point the first option is required, so the loading is delayed until an option is needed. If you do have a lot of options too, you could perhaps break them up in to groups/categories and only load a particular group of options at a time. -
Load the document using the DOMDocument class, then you can manipulate it's contents using the DOM api by adding/removing/changing nodes. When your done you can save it out again.
-
serve dynamic content based only on url requested
kicken replied to webguy262's topic in PHP Coding Help
You'd have to configure your server to treat those 200 urls as being served by the same script. Most likely a RewriteRule would handle this the easiest. -
Create a comparison function and use usort. The function will take two arguments, which will be elements of the main array. Access each arguments 'botanicalName' key and compare them and return the result (as either -1, 0, or 1)
-
Congrats! So now we forward all tech problems to you right?
-
You would have to send the user to a page which displays the image (or whatever) and then that page will then re-direct them via meta tag or JS to another file which serves the download.
-
Order by your sticky column first. I assume this is just a 1/0 tinyint column. To get the sticky ones first you'd order them descending. After that you order by the lastpost column in descending order. That will make it so that you should get the newest posts at the top, even within the group of sticky posts. Each column in the order by clause needs to have it's order specified. if none is specified it defaults to ascending so you'd want: ORDER BY sticky DESC , lastpost DESC
-
There is no separation of stuff between tags. You can imagine that all the different blocks get squished together into one giant script, and anything that was outside the tags is just turned into an echo. Eg: <?php $db = mysql_connect(); //do stuff ?> <p>echo some <br> html here </p> <?php $q = mysql_query(); //do more stuff ?> is functionally equivilent to: <?php $db = mysql_connect(); //do stuff echo '<p>echo some <br> html here </p> '; $q = mysql_query(); //do more stuff ?>
-
PHP doesn't have any way to execute something in the background, which is what you need if you want to launch something then get the PID. In Linux/Unix you can do this using a simple shell script, such as: #!/bin/bash /usr/bin/php -r 'sleep(100);' >/dev/null >&1 & disown echo $! And run it: if (exec('./go.sh', $output, $ret)){ echo 'Launch successful. Pid='.$output[0]; } else { echo 'Launch failed'; } For windows, running in PHP would be essentially the same but you would have to find or create a program to use as an intermediary which will launch the program you want in the background, then output it's PID.
-
Use imagecopyresampled to do the resize, not imagecopyresized.
-
When you query for the post listing, just use the ORDER BY clause in your query to sort by your date field, in descending order.
-
"Better" or more proper way to select data on a page
kicken replied to spacepoet's topic in MySQL Help
Since your queries appear to be unrelated to each other, having them separate like that is pretty much what you'd want to do. Joining is when your trying to pull information from multiple tables, which is all related together via some other bit of information. In your case, there is no relation between your tables (that I saw) so there's no reason to join them. If you ever find yourself doing something like this: $res=mysql_query('SELECT ...'); while ($row=mysql_fetch_array($res)){ //Some other query that uses some information from $row $res2=mysql_query('SELECT ....'); while ($row2=mysql_fetch_array($res)){ } } Then chances are good you want to use a JOIN instead. Nested select queries like that is almost always a bad idea. -
Appears to work fine for me if I copy/paste to a test script. define('ENCKEY', 'asdf'); $txt = 'kicken'; $enctxt = encryptdata($txt, ENCKEY); $out = decryptdata($enctxt, ENCKEY); var_dump($txt, $enctxt, $out); /* string(6) "kicken" string(24) "k9+Jryul9CZ3Bi9GvnwEaw==" string(16) "kicken" */ Sure there isn't a small bug in your test code somewhere? edit: Just noticed the output is string(16) as it's padded with NUL bytes. A quick rtrim solved that.
-
Are you wanting to know about how to create a "remember me" feature so that they don't have to enter a login each time they visit? If that is what your after then upon successful login you would generate a random hash value and save that in a cookie and in the DB for that user. Whenever they visit your site you compare those and if they match go ahead and log them in (possibly with limited access). You can optionally re-generate the hash on each visit so as to invalidate it frequently. You could also invalidate it after a set period of time so if say they don't visit within 2 weeks, they have to login again. A remember me feature is inherently insecure so there's limited things you can do to try and prevent it's abuse. Anyone that is sniffing a connection/stealing cookies is going to have a good chance of being able to use it to login as someone else who's cookies they stole. That is why places with sensitive information typically either don't offer this option, or require you to enter your password anyway to do anything related to viewing/changing your account details.
-
Your relying on the indexes of workshop_id and participatqty being equal, but your code does not ensure that. Take for example if you have 5 courses listed and the user checks the box for only the first and last (and selects those quantities). $_POST['workshop_id'] will only contain two indexes: 0,1. Reason is that only boxes that are checked are sent, and [] just appends the value on the next available numeric index. So the first box becomes index 0, and the last becomes index 1. $_POST['participatqty'] on the other hand, will contain all indexes from 0 to 4, with 1-3 being the empty string, and 0 and 4 being the users chosen values. Empty select box values are sent so they use up the indexes as you'd expect. What you need to do is manually specify your indexes so they always match up between the two arrays. I great way to do this is to use the ID numbers for whatever the checkbox represents. In this case, the course ID. <input type="checkbox" name="workshop_id[]" value="<?= $c_row['workshop_id'] ?>" /> <?= $c_row['workshop_title'] ?> </td><td><?= $c_row['workshop_date'] ?></td><td><select name="participantqty[<?= $c_row['workshop_id'] ?>]" id="" class=""> <?php foreach ($_POST['workshop_id'] as $id){ $qty = $_POST['participatqty'][$id]; }
-
If your reason for not wanting to put it into a form element is so the end user can't change it, then you'll have to track it server side, perhaps using sessions and storing it in $_SESSION to carry it from page to page.
-
How many time can I call a query or invoke sqlsrv_fetch_array
kicken replied to sql-lover's topic in Microsoft SQL - MSSQL
You can call that function as many times as there are rows in your result set. I'm not sure what your issue is, you might try explaining again in another way. If you're just looking to show a comparison of two tables you'd pretty much go as follows: - Get all the columns for table A - Loop the result set and save the results into an array. - Get all the columns for table B - Loop the result set and save the results into an array. - Display the two array's to the screen. -
What driver are you using in PHP to connect to sql server? sqlsrv, mssql, odbc? Can you just create a sql server account and connect that way rather than with windows authentication? I've not attempted to connect via windows authentication using php before, not sure if it is possible. I host using apache rather than iis on my dev machine so I just have a sql server account setup and use that. Our production servers use IIS 7 but they also just use an sql server account rather than windows auth.
-
This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=353855.0
-
It looks at each extension because each extension can provide different information. For example you could do something like: index.php.html.en and apache would deduce from the extensions that: - It's a text/html mime type - It needs run through the PHP handler - It's in the english language. Multiple extensions aren't really all that useful when dealing with a dynamic page such as a php page though, so it's better to configure the server to only use php if the final extension is .php. Some servers are not configured in this manner though so it opens up issues. No, only the extensions. As I already said: No, getimagesize will ensure it is a valid image, and it will tell you what type it is (jpeg, gif, or png). What it won't do is prevent someone from inserting PHP into the image in such a way that the image remains valid. Such as in the meta-data fields. That is why you take the extra step of making sure the code wont execute if someone does put it in there. Unrelated Side note: you should use the preview option before posting and make sure you get all your quote's correct. It makes it harder to read and understand your posts when you have people's quoted text mixed in with your own because the tags are messed up.
-
There isn't really any single factor, however most software uses the extension as the determining factor. For instance when you upload your excel document that is named 'somefile.jpg' the browser will likely report it as a image/jpeg type. Some software will actually attempt to guess the mime type by examining the contents of the file. For example, IE does this I believe. PHP's getimagesize will do it to some extent and there is a library out there people can use to do this. It looks for special marks that exist only in certain formats in the contents of the file. This is because apache takes into account all the extensions when deciding what to do with a file. "test.php.jpg" has two extensions: .jpg which tells apache it is an image/jpg file (the mime type) and .php which tells apache it needs to be processed using the php handler. Most software is only concerned with the right-most extension, in this case .jpg, and would treat it as an image. It look ok so far. I would recommend not checking the $_FILES['userPhoto']['type'] key and instead check the results of calling getimagesize() on the file. The type set in that key is whatever the browser sent which could be a number of things. For instance, I've seen a JPEG image report as any of: image/jpeg image/jpg image/p-jpeg image/p-jpg getimagesize will provide a more reliable test because it actually checks the file's content not the extension.
-
Not that I am aware of. There probably are some pre-written ones out there you could use. You could also go to a site that functions similarly to yours and copy then modify theirs and that would probably be good enough, for now anyway.
-
I'm assuming you want to write to the file literally $config['MySQL']['hostname'] and not the value stored there. In that case, you need to escape the $ so PHP does not try and interpret that variable, or you could enclose your string in single-quotes.