Jump to content

freeloader

Members
  • Posts

    175
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

freeloader's Achievements

Member

Member (2/5)

0

Reputation

  1. Interesting question. I've been thinking of a clear way of doing it without using a pre-coded platform for some time as well. Looking forward to hearing an answer on this too.
  2. Also, my escaping is a bit off, but putting the $ sign there blank between double quotation marks (") seems dangerous. Use single quotations (') for this, they also process slightly faster.
  3. You could use IP information as an added layer of security. First you need to find the IP address. $_SERVER["REMOTE_ADDR"] isn't always the most reliable. There are some great functions out there, just google for 'php find ip address' or something like that. Best way to store that info is on a database on your server in a field like 'LastIP' and then compare current with last IP and else: send them back to login page.
  4. I was worried about both of them sleeping 10 seconds each. Having only one of them sleep for 5 seconds is optimal. This seems like a great solution, thanks! I'm going to try it out Not sure if my crontab will handle the sleep part (it's a synology NAS, they use a custom sort of crontab).
  5. Hi guys, For a project I made sort of a custom cron database. Database has 4 columns: ID (auto increment), TaskID, DateTime, Locked. I'm running a 1 minute cron in the form of a php script. The script itself starts with a query that loads a task with 'Locked != 'Y' and DateTime < NOW( ). It then locks the task (by flagging the 'Locked' field in the db) and launches another script that finishes it. That last script deletes the task when finished from the cron database. Problem is, at certain peek hours, the system would get laggy, there'd be a bunch of tasks stacking up and it would get behind on the schedule. In order to combat that, I made an extra 1 minute cron, launching the same script. Now, my problem: mysql is too slow In principle, there shouldn't be any problem: all tasks picked up by either instance of the script would be locked so the other instance wouldn't be able to pick up the same task. The problem occurs when both instances are booted at the same time (well, one after the other but with a minuscule time difference between them) and they both at the same time run the query to get a 'free' task from the database: the system will give them both the same task before either of the script instances has the time to lock it up. I'm trying to think of some solutions but I'd like your feedback on what solution would be best. - Putting an exclusive lock on the php file is not an option for me since I still want to run the script, I just need it to pick up an exclusive task. - Other option: having the script open with a random sleep of (1, 10) seconds, it will have the script instances pick up a task at a different time, giving the other instance time to lock it up. Obvious disadvantage: I'm losing time. - Using a file as a flag. Set a directory and create a file in it. Check if this is the only file in the dir, if yes: start right away. Otherwise: go to sleep for 2 seconds (should be plenty of time to run 2 queries in the other instance). What is the fastest method of doing a directory scan though, glob()? My question: what's the fastest/best way to solve this? Thanks!
  6. Fixed it using preg_replace_callback() on the URL's, regex'ing them and base64 decoding them.
  7. Because these are pre-parsed pages and in some of them, the URLs have been parsed through a base64 encoder. Giving an output like this: <link href="Oigregregregrer/gergeggege==" media="screen" rel="stylesheet" type="text/css" /> (The above is not an actual link.)
  8. Hi guys, I'm parsing a bunch of html sources, some of them (a minority) contain base64 encoded URLs. At least 20-30 URLs per page. Some of the information I need is taken from the URLs. I'm looking for a way to parse these URLs without losing too much time (20-30 URLs per page and I need to parse about 10k pages daily). Should I regex each source individually for base64 encoded URLs and then decode them each time and isn't that going to take a lot of time/resources (especially considering it's only a minority that have the base64 URLs in them)? Or is there a better way to do it? Code snippets are absolutely welcome! Thank you in advance
  9. freeloader

    help!

    Just do it like this: <div id='textValue'><?php echo $text; ?></div> That should work if your div is stated before your dropdown box since it will just store the last text result it got from your dropdown. I see you need to fix a small bug in the first dropdown code I gave you though: $sql = "SELECT Distinct(names) FROM table"; should be: $sql = "SELECT Distinct(names), text FROM table"; Otherwise run a small query at the start: $sql = "SELECT text FROM table limit 1"; Get the result and set it as a variable. Then put that variable in the div by default.
  10. Sure this is possible. It would require an extensive database though, so it might slow down your site a bit. There should be plenty of examples on this on the web if you google it.
  11. You want that timer to run on one page and execute code every x seconds? This is how you can start a timer: $mtime = microtime(); $mtime = explode(' ', $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; Then every x seconds check: $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = round($endtime - $starttime); If total time >= 180, execute next piece of code. This would require you to keep the page open and output the results in it while it's loading (flushing). You'd need following parameters for that: ob_implicit_flush(); set_time_limit(0); That would make the script work like you want to. But it's terrible coding practice. A better way would be to have a static page that fully loads but with AJAX functionality. Store your stuff in the database and let ajax execute a php script that compares the timestamps and execute code when necessary then output back to the browser. There's plenty of tutorials about ajax, and I've written a simple ajax code for someone else yesterday as well so you might find some inspiration there: http://www.phpfreaks.com/forums/index.php/topic,309154.0.html
  12. freeloader

    help!

    I think I got it now. It's possible using php, mysql and ajax. This should put you on your way. The dropdown code: <select name="names" id="names" onchange="writeText(this.options[this.selectedIndex].value)"> <option value="">Select a name</option> <?php $sql = "SELECT Distinct(names) FROM table"; if (!$selecttabel = mysql_query($sql, $conn)) { echo mysql_error(); exit(); } $nrlines = mysql_num_rows($selecttabel); for ($i = 0; $i < $nrlines; $i++) { $stats = mysql_fetch_array($selecttabel); $names= $stats['names']; $text= $stats['text']; echo "<option value=\"$names\">$names</option>\n"; } ?> </select> Where you want the text to come in your document make a div or a span with id 'textValue'. Then make a javascript with this content and include it on your page: //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?"); } } //Our XmlHttpRequest object to get the auto suggest var searchReq = getXmlHttpRequestObject(); //Called from keyup on the search textbox. //Starts the AJAX request. function writeText(nameValue) { if (searchReq.readyState == 4 || searchReq.readyState == 0) { searchReq.open("GET", 'getText.php?name=' + nameValue, true); searchReq.onreadystatechange = handleResponse; searchReq.send(null); } } //Called when the AJAX response is returned. function handleResponse() { if (searchReq.readyState == 4) { var str = searchReq.responseText; document.getElementById('textValue').innerHTML = str; } } Then make a php file and name it getText.php. In that file you run a _GET to get the value called 'name' and run a query to return text. Output that to the browser without anything else. If you're running it on a host with ads, you'll have to output it in xml and xpath the response in javascript first.
  13. So you're looking for something like this? I still don't fully understand the second part of what you're trying to do though. $sql = "SELECT * FROM names"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $nrlines = mysql_num_rows($result); for ($i = 0; $i < $nrlines; $i++) { $stats = mysql_fetch_array($result); $name = $stats['name ']; $link = $stats['link']; echo $link; }
  14. <?php $CurlStart = curl_init(); curl_setopt ($CurlStart, CURLOPT_URL, "http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier"); curl_setopt ($CurlStart, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($CurlStart, CURLOPT_REFERER, $url); curl_setopt ($CurlStart, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11"); curl_setopt ($CurlStart, CURLOPT_HEADER, 1); curl_setopt ($CurlStart, CURLOPT_FOLLOWLOCATION, true); $source = curl_exec ($CurlStart); curl_close ($CurlStart); $a=preg_match("/>Level:.*.\n.*.>([0-9]*)</",$source,$b); $Level = $b[1]; echo "Level: $Level"; ?>
  15. The second way would be better coding practice. It reduces the html output, makes your page smaller and easier to load.
×
×
  • 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.