Jump to content

wavez

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by wavez

  1. Thanks kicken. How do sessions function if the user disables cookies?
  2. On second thought, maybe it is easier and more expedient for me to store a hash key in the DB for each user account and just compare that against a matching cookie upon every page load. That means querying my DB on every request though.
  3. When is the session destroyed? Does it have a timeout feature? How do I know, upon page request, if the user HAD an active session but it timed out (versus the situation where the user requested my page but didn't have an active session yet that day)?
  4. I'm also trying to figure out if session_name() does or does not do something that I need.
  5. I've taken and redesigned a whole bunch of example and tutorial code pieces for my small project. I have a MySQL database working now (I realized it's easier than using flat files) and I need to get user accounts working. I'm having a lot of trouble understanding how PHP sessions work. Assuming a user has logged in and is now clicking on links and browsing around, on each page load, don't I need to check the session variable to load his username, and also check that his session is current? How do I check that the session is current? None of the examples / tutorials that I'm finding online even mention how my code is to know which user the page is being served to. Does session_start() have a magic feature that makes this check unnecessary? I know I can use cookies, but I figured I would code it without since some articles seem to indicate that cookies don't have to be required to support typical user session functionality.
  6. I got it working, it seems. I found a couple more issues. For one thing, I didn't know the difference in how PHP handles double-quoted strings and single-quoted strings, which explained why the new-line characters I was trying to insert weren't working. I added code to split the incoming string on every new-line character, then trim the ends, and I needed to add new-line characters back in since my output in the textarea objects was one big long string. Another issue was that I didn't understand how forms work, so the submit button was causing text from ALL my textarea objects to be written to my file on the third page (which I haven't mentioned until now, it's just a page that gets the $_POST variable and writes to the file). To fix it I moved the <form> tag down so that only one textarea object and the submit button are inside it. Other than that, it was just a matter of doing explode("\n",$v); on $_POST['comments] before storing it in $oldImages, and then doing trim($v); on each resulting string. Only when writing the arrays to the textarea objects do I add a new-line character to the end. Thanks for your help Pikachu2000. I'll be sure to choose you in my next battle! I can't figure out how to add "[sOLVED]" to the beginning of the thread title.
  7. That looks like really stellar implementation. I'm trying to use it right now. $oldImages is still coming out as one long string and $newImages is totally empty. I'll try to figure out where it's going wrong.
  8. Ah ha... Sending the contents of the textarea object from the first page stores it all as one item of the $_POST array. I'm going to google it right now, but does anyone know how to have the form automatically breakup the contents of the textarea object into one array entry for each line?
  9. I changed the code to use trim(). <?php $file = file("image_list.txt") or exit("Unable to open file!"); $oldImages = array(); $newImages = array(); foreach($file as $key => $entry) { echo $entry.'<br>'; $oldImages[] = trim($entry); } echo '<br>'; foreach($_POST as $key => $entry) { echo $entry.'<br>'; $newImages[] = trim($entry); } $newAdditions = array_diff($newImages, $oldImages); $newList = array_merge($oldImages, $newAdditions); /* print_r($newImages); echo '<br><br>'; print_r($oldImages); */ echo ' <form method="post" action="save_images_list.php"> New Images<br> <textarea id="displayText" rows="5" cols="105" wrap="off" name="existing"> '; foreach($newImages as $key => $entry) echo $entry; //echo $newImages; echo ' </textarea> <br> Stored Images<br> <textarea id="newText" rows="5" cols="105" wrap="off" name="new"> '; foreach($oldImages as $key => $entry) echo $entry; //echo $oldImages; echo ' </textarea><br> New Additions<br> <textarea id="newText" rows="10" cols="105" wrap="off" name="new"> '; foreach($newAdditions as $key => $entry) echo $entry; echo ' </textarea><br> Newly Generated Image List<br> <textarea id="newText" rows="30" cols="105" wrap="off" name="new"> '; foreach($newList as $key => $entry) echo $entry; echo ' </textarea> <input type="submit" class="button" value="Submit"><br> </form> '; ?> Looking at the textarea objects, the data from $oldImages is just one big long string, while the data from $newImages is multiple strings. Also, and empty line from the $file input isn't being removed. I'm processing both of these arrays in exactly the same way, yet I'm getting different output. Obviously something is happening with new line characters and who-knows-what other possible invisible characters.
  10. No, it's still working totally wrong. I'll post actual array results later when I have time. Thanks for reading.
  11. I've kind of lost the erroneous result after getting a new list of images. I'll leave this posted in case anyone has some advice to share on the issue though.
  12. I have two arrays of strings, one is read in from a file, the other is collected on a previous page using js and passed with a form through $_POST. The array from the file I label $oldImages and the array from the previous page I label $newImages (each is a list of image URLs). I need to compare the two and add them together so that there are no duplicate entries. I'm using array_diff() on them and the result I'm getting includes one entry that is in both arrays. I've tried different ways of reading the file, none of them seem to make any difference in the results. I've been printing the arrays with print_r() to have a look at the contents of the arrays and I decided to use implode() and explode(), and str_replace() to try to remove any irregularities that might be in the objects somehow which I'm not seeing. I'm not a PHP programmer, BTW. Here is some code. I've also attached a screenshot for you--link at the bottom. <body> <?php $file = file("image_list.txt") or exit("Unable to open file!"); $oldImages = implode($file); $oldImages = str_replace(" ", "", $oldImages); $oldImages = explode("\n", $oldImages); $newImages = implode($_POST); $newImages = str_replace(" ", "", $newImages); $newImages = explode("\n", $newImages); $newAdditions = array_diff($newImages, $oldImages); print_r($newImages); echo '<br><br>'; print_r($oldImages); echo ' <form method="post" action="#"> New Images<br> <textarea id="displayText" rows="5" cols="105" wrap="off" name="existing"> '; foreach($newImages as $key => $entry) echo $entry; //echo $newImages; echo ' </textarea> <br> Stored Images<br> <textarea id="newText" rows="5" cols="105" wrap="off" name="new"> '; foreach($oldImages as $key => $entry) echo $entry; //echo $oldImages; echo ' </textarea> <input type="submit" class="button" value="Submit"><br> </form> Newly Generated Image List<br> <textarea id="newText" rows="30" cols="105" wrap="off" name="new"> '; foreach($newAdditions as $key => $entry) echo $entry; echo ' </textarea> '; ?> <div class="clear"></div> </body> Here is the code from the previous page which produces the array that is stored in $_POST. What you can't see in this code is the javascript functions toggleEntry() and displayList(). All they do is handle the addition and removal of image URL strings to/from the textarea object, which I do using document.getElementById('text').InnerHTML=$myList, where $myList has strings being added or removed to/from it. <script type="text/javascript" src="/js/user_selection_list_builder.js"></script> <script type="text/javascript"> function toggleAndDisplay(key) { toggleEntry(key); displayList(); } </script> </head> <body> <form method="post" action="add_images2.php"> Selected Images<br> <textarea id="displayText" rows="10" cols="90" wrap="off" name="comments"> </textarea> <input type="submit" class="button" value="Submit"> </form> <div class="clear"></div> <?php $i = 2; include 'simple_html_dom.php'; if($i===1) $html = file_get_html('lookbook-source.htm'); elseif($i===2) $html = file_get_html('http://lookbook.nu/preference/look-list-gender/girls'); elseif($i===3) $html = file_get_html('http://lookbook.nu/new'); // Match all div tags of the class 'look_photo'. foreach($html->find('div[class=look_photo]') as $key => $entry) { echo " <div class='imgBox'> <a href='javascript:toggleAndDisplay(".$key.")'><img id='".$key."' src='".$entry->last_child()->last_child()->src."'></a> </div> "; } ?> </body>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.