Jump to content

5kyy8lu3

Members
  • Posts

    257
  • Joined

  • Last visited

Everything posted by 5kyy8lu3

  1. Oh, I didn't think about having to check the source to see the output. I was just looking at the browser output and it was blank. This is the output of the bin2hex(): 342048616e64732053756761722026616d703b205370696365 My knowledge on character encodings are admittedly limited Scraping public data is not stealing lol Also, if you want to know more specifically what I'm doing, it's a website that my friends and I use to keep track of the beers we've had for flying saucer's "ufo club". It gets really difficult to know which beers we've had after you get past about 50, so I made this site. To avoid errors with data entry, instead of letting users add new beers that aren't found when they do a search, I scrape saucer's "beer menu" to get a full list of what's in stock. In fact, my "menu" ends up being more accurate than theirs because the printed menus are often a couple days old.
  2. This is what vardump shows: string(25) "4 Hands Sugar & Spice" strlen() shows this: 21 and I get nothing when I bin2hex the containing variable oh and I should mention that when I do the strlen, I'm copy/pasting output of browser back into script to do teh strlen. when I wrap strlen around the variable I get 25 just like vardump shows
  3. Hi. I've been banging my head against the wall with this stupid problem and I just figured out the problem. I scrape data from a website. I query my table to see if I already have everything in there. If no match is found, I insert it. Today, I noticed even after inserting, my script kept telling me there's a new entry I need to insert, despite it actually being there when I physically check the table. But when I echo the query out and run it in phpmyadmin, it finds the row. But not if I run the query directly in my script. Turns out, there are several invisible characters in my string. When I do var_dump(), it says length is 25. When I copy and paste the string into notepad, then back into a fresh php script and wrap it in quotes and echo out a strlen(), I get 21. There are apparently 4 invisible characters that I can't see. I trim() everything, so that apparently didn't catch it. So... is there a good way to "clean" my data before inserting or comparing it to avoid this in the future? This wasted a ton of time and I hope to find a way to clean this junk out of my data. Thanks! It just seems like I run into this sort of thing often when it's data scraped from the web. (breaks my regex! grr!)
  4. Well, I just did this: UPDATE beers SET brewery=TRIM(brewery); And it fixed my problems! I really appreciate the help!
  5. Oooooh, I see what you're asking now. A lot of it was scraped from a website. Some was copy/pasted, and the rest was typed manually. If it's the existing data that's not working correctly, I'm curious why using TRIM on the ORDER BY clause fixes the problem? NEVERMIND, duh, it's trimming the original data's whitespace or whatnot. That was a dumb question, sorry. I didn't realize until after I pushed the button to post. I think I'm going to write a quick script to go through each row and clean it
  6. The data was typed by hand into an HTML form. I even typed the data into phpmyadmin's insert page to insert a row and that did the same thing. When I do this, it doesn't sort correctly: SELECT brewery FROM beers ORDER BY brewery ASC; But when I do this, it sorts correctly: SELECT brewery FROM beers ORDER BY TRIM(brewery) ASC; So I'm fairly sure it's related to invisible characters, but I can't figure out where or how they're getting in there. (or how they're sneaking past php's trim() function)
  7. I just inserted a brand new row using phpmyadmin and that row isn't sorting correctly either. This is weird. The page is rather large with formatting so I cut all the fat out and left the actual function code. <?php session_start(); require("library.php"); $DBA = new DBA; if ( $_GET['post'] == 1 ) { $_SESSION['brewery'] = trim($_POST['brewery']); $q = 'UPDATE beers SET brewery="' . $_SESSION['brewery'] . '" WHERE ID="' . $_SESSION['ID'] . '"'; $results = $DBA->Query($q); $_SESSION['insert_success'] = 'New brewery successfully added!'; header("Location: addbrewery.php"); die(); } else { echo '<html> <head> <title>Add Brewery</title> </head> <body>'; if ( $_SESSION['insert_success'] != '' ) { echo $_SESSION['insert_success']; unset($_SESSION['insert_success']); } echo ' <form action="addbrewery.php?post=1" method="POST"> <input type="text" name="brewery"> <input type="submit" value="Add Brewery!"> </form> </body> </html>'; } ?> Here's a screenshot of the sorting not working for my test row in phpmyadmin (and I USED phpmyadmin to INSERT this specific row)
  8. Hi. Any time I have POST data, I wrap it with php's trim() function to strip whitespace to avoid sorting issues and such in the database. (mysql5 / php5) Despite using php's trim() function, I believe some special characters or spaces are ending up at the beginning of the string. Even editing that row with phpmyadmin doesn't fix the problem which is what's weird. (meaning I manually retype the value in the column in phpmyadmin, then save it, and it still won't sort correctly) Basically, every row sorts correctly except one row that ends up at the very end. If I use mysql's TRIM() in the order by clause like so: ORDER BY TRIM(name) ASC, it actually sorts correctly. So how is something sneaking past php's trim() that mysql's trim() is able to fix? Any ideas? That column is using latin1_swedish_ci collation
  9. you could do something like this: //this goes on your insert5.php page <?php session_start(); if ( $_POST['password'] != $_POST['checkpassword'] ) { $_SESSION['passfail'] = 1; header("Location: http://www.yoursite.com/formpage.php"); } ?> //this is your form page <?php session_start(); if ( $_SESSION['passfail'] != '' ) { echo 'Passwords don't match.'; unset($_SESSION['passfail']); } ?>
  10. not exactly, but like I said, you should echo out both the database values and the user entered credentials and stop the code from executing with die(); and you'll see exactly what's going on by viewing the contents of variables. it's the quickest way to pinpoint where your problem is coming from =) for example, if your login page POSTs to check.php then on THAT page you echo everything out and so after you try logging in you can see where and why things aren't matching up.
  11. hmm that's weird. you did clarify, thanks as far as the ip address showing up blank, i've never seen that. i've seen some weird ones like the one you intentionally masked for privacy reasons lol. not exactly but it was sorta like that. i would start by double checking string length vs your limit set in your table, and add trim() to your ip address to make sure it didn't come out with some hidden ascii white space character or something that's screwing things up. i honestly don't know what to suggest since i've never encountered this. i suppose you could generate a random hash and save it into a cookie and use that to identify your users as a second means so if ip doesn't get logged you can go by the cookie's hash value instead. not the best answer but it would work if you cant' figure out what's wrong lol good luck, mate!
  12. use server variables like $_SERVER['HTTP_REFERER'] to make sure it's coming from the exact page you're wanting it to.
  13. I would start out of echo'ing out variable contents and putting a die(); on the line after, and keep doing that to "debug" your code to see where exactly it's messing up. start with the page you check credentials against the database. echo the password from the database and echo the password from the user and stop the code with die(); and see if they match. check to see that your session variable saying they're "logged in" is set correctly. that's my typical method of debugging stuff. not the greatest method but for me it works.
  14. Hi. Is your problem because your script can't detect improper IP addresses like the one above? How I usually check is to explode the IP address after trimming white space with trim(), then make sure the array has 4 elements, and also check that each element is within the proper range for a IP4 ip address, and check to see that each element in that array is numeric (with something like ctype_digit()). As far as your script not logging them, is $_SERVER['REMOTE_ADDR'] not giving you their IP address? the only thing I can think of for it not logging the IP address correctly is if you have an issue with data type, or more importantly, data size for that column in your table. could you be a little more specific as to your problem?
  15. I use modulus for this problem =) <?php $RowNumber = 0; foreach( $A as $B ) { if ( $RowNumber % 2 ) { $Style='red'; } else { $Style='blue'; } echo '<span class="' . $Style . '">' . $B . '</span>'; $RowNumber++; }
  16. you could loop through each character if cpu usage isnt' a big deal <?php for ( $i = 0; $i < strlen($String), $i++ ) { $Byte = substr($String, $i, 1); //takes one character $NewString .= str_replace("%",randomchar(),$Byte); }
  17. just remember that since php ignores white space much like html, you only need to use semicolons at the end of a statement. (and need to remember that statements can be multiple lines, especially for when you do that to make it easier to read) if ($session->logged_in) { echo "<h1>Logged In</h1>"; echo "Welcome <b>$session->username</b>, you are logged in. <br><br>" . "[<a href=\"Index2.php\">Newsboard</a>] " . "[<a href=\"userinfo.php?user=$session->username\">My Account</a>] " . "[<a href=\"useredit.php\">Edit Account</a>] "; if ($session->isAdmin()) { echo "[<a href=\"admin.php\">Admin Center</a>] "; } echo "[<a href=\"process.php\">Logout</a>]"; } else { ?> <h1>Login</h1>
  18. the thing with php is that ALOT if not most php frameworks that are open source and free for you to download and look through are object oriented so if you aren't familiar with object oriented programming, make sure you specifically find one that's coded procedurally else you'll get a headache =)
  19. when you check the user's password against the one in the database, you should pull the entire row from the database and then populate some session variables to use <?php session start(); include("MySQL_Connection.php"); $Query = 'SELECT * FROM Members WHERE Username="' . $_POST['Username'] . '"'; $Result = mysqli_query($Connection, $Query); $Row = mysqli_fetch_array($Result); if ( /*passwords match*/ ) { $_SESSION['Authorization'] = 1; $_SESSION['FirstName'] = $Row['FirstName']; $_SESSION['AccountLevel'] = $Row['AccountLevel']; } ?> then check at the top of each page to see that $_SESSION['Authorization'] is set to 1, which you probably already do. then since you already have account level and first name saved into session variables upon login, you can do something like: echo 'Welcome, ' . $_SESSION['AccountLevel'] . ': ' . $_SESSION['FirstName'] . '.'; which would print something like "Welcome, Administrator Bob" i hope that makes sense. i didn't bother reading each post so this might not even be what you're asking lol
  20. I personally use: echo $PageContents = filegetcontents("http://www.thesite.com/thepage.php"); since the server parses the php, it just returns the html, which you can save into a variable or echo or whatever you wish
  21. Hi. I'd like a way to create a unique "Machine ID" of a client's machine. I'd like to be able to identify the machine regardless of the IP they appear behind. Is this possible using JS? I know a cookie can be set but the user can delete or disable cookies, or just use a proxy. If you'd like to know why, I'm basically creating a visitor log script, and wanted to have a way to keep track of machine id's to make tracking of malicious activity easier. Why JS? Since it's client-side, I figure I can get details of their machine, like screen resolution, local ip, user agent, etc and concatenate them and hash that to get a "machine ID". It sounds doable but I'm very very new to JS so I didn't know if this is a good method of doing so or if there's a better way of accomplishing this. Thanks ahead of time.
  22. Hi. I've been playing around with sending POST data with curl to my remote server, but I would like to know what I can do to add some security to the mix. Right now, anyone can post to the page using curl, right? So is there a way to make a secure connection? Require a password in the post data, or is there another method? Thanks much.
  23. you need javascript to do that, but it's simple. just do a google search for it =) http://www.davesite.com/webstation/js/theory1jump.shtml
  24. sounds more like a problem with your session settings in your php.ini. i used to get random logouts and it was related to the webhost's garbage collection process, which wiped my sessions out even if they weren't expired. also probably unrelated but good to know, sessions at www.yoursite.com and yoursite.com are NOT the same. i force the www to be there.
  25. Thanks but would you be able to give me the php too $Query = 'CREATE TABLE Notepad ( ID INT AUTO_INCREMENT PRIMARY KEY, Note TEXT );'; $Result = mysqli_query($Connection, $Query); if ( !$Result ) { die("Error running mysql query."); } $Query = 'INSERT INTO Notepad SET Note="This is an admin note"'; $Result = mysqli_query($Connection, $Query); if ( !$Result ) { die("Error running mysql query."); } $Query = 'SELECT Note FROM Notepad ORDER BY ID DESC LIMIT 1'; $Result = mysqli_query($Connection, $Query); if ( !$Result ) { die("Error running mysql query."); } $Row = mysqli_fetch_array($Result); echo 'Newest admin note: ' . $Row['Note']; that gives you an idea, but honestly you really need to go read some basic mysql and php tutorials.
×
×
  • 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.