Jump to content

wee493

Members
  • Posts

    87
  • Joined

  • Last visited

Everything posted by wee493

  1. I'm creating a quiz type application where there are hundreds of quetsions in a database and they are all tagged with chapter and sub chapters in my review material where they've come from. I have a page where users can select which chapters/sub chapters to answer questions from. I need help on the best way to save which questions the user will be doing and incrementing to the next question through them taking the quiz. With a normal quiz it's easy to increment id + 1 to the next question, but in this case I assume I need to store an array of what questions they're doing in a session? Or should I store it in the database with a pointer to a quiz session id? What would you recommend? Any ideas are appreciated, thank you!
  2. Sorry, I figured it out $date = date("z"); echo ($date - (4 * floor($date/4)));
  3. I have 4 links that I want to show a different one every 24 hours, I would just put the links in an array and chose a random one, but it needs to be a different one every day. I'm having trouble thinking of how to do this without a mysql db
  4. If you visit my site at http://joshoak.es/test you'll see that the URL changes to "http://joshoak.es/test/#/screens/d12245cc-1680-458d-89dd-4f0d7fb22724" I can see in the document where that comes from <script type="text/javascript">jQuery(document).ready(function(){jimMain.init("screens/d12245cc-1680-458d-89dd-4f0d7fb22724");});</script> If I remove that, the page doesn't load. This isn't my site, so I don't know a lot about the structure, but a friend asked me if I could fix this. Do you have any suggestions? Thanks!
  5. I'm wanting to download and entire clone of a webpage using php. Save the page, js, css, and images. If I use fopen() or file_get_contents() it only saves the main page and not the linked assets. Is there another method to doing this?
  6. It seems that the get_headers function is what I'm looking for. Here's a demo code for anyone interested function expand_url($url) { $h = get_headers($url); // if no redirect header then return the original url return isset($h['Location']) ? $h['Location'] : $url; }
  7. I'm using the Twitter streaming API and receiving a feed of recently tweeted links. I'm trying to create an index of popular links. I would like to expand all the shortened links. I'm using the bit.ly API to expand the bitly links as that accounts for almost exactly 1/3 of the links, but I still have 2/3 of other links that could be expanded. I have over 600,000 links in the database and about 200,000 are bit.ly links. So, this means I still have 400,000 links to expand, though not all links can be expanded. For example twitpic links are usually not shortened. But anyways, I'm using the funciton below to expand URLs right now function untinyurl($tinyurl) { $url = parse_url($tinyurl); $host = $url['host']; $port = isset($url['port']) ? $url['port'] : 80; $query = isset($url['query']) ? '?'.$url['query'] : ''; $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : ''; if (empty($url['path'])) { return ''; } else { $path = $url['path']; } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, "http://$host:$port".$path.$query.$fragment); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // seconds curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); $response = curl_exec($ch); if ($response === false) { $tinyurl = ''; } curl_close($ch); $lines = explode("\r\n", $response); foreach ($lines as $line) { if (stripos($line, 'Location:') === 0) { list(, $location) = explode(':', $line, 2); return ltrim($location); } } if (strpos($response, 'HTTP/1.1 404 Not Found') === 0) { return ''; } return $tinyurl; } The only thing is it can take a second or more for this to work. I was wondering if there is any quicker way to do this? I know I'm going to have to ping the servers because there is not an index of shortened urls, so my speeds will depend on the remote servers.
  8. I need some help parsing this text file. I've tried a few things, but had trouble as it's not actually json data. I've tried various str_replaces and things along those lines, but I would like to be able to output this into a table with the Steam id, time, name, and reason. If someone can just point me in the right direction i'd be fine coding myself! Thanks! "STEAM_0:0:18130940" { "admin" "(Console)" "unban" "1274151724" "time" "1273546924" "name" "-=SAS=- Death Master511" "reason" "Gcombat on spawn/Server Crash Attempts 1 week appeal at halania.com" } "STEAM_0:1:6428933" { "time" 1273619777 "unban" 1273706177 "admin" "TornadoChas3r(STEAM_0:0:19768725)" "name" ".:T.¥:. TRÅÑŒ (CRYSTAL)" "reason" "RDM/ 1 day Ban \"You had Enough Warnings\" / :" } Here's basically what I have right now, which does not work too well $myFile = "bans.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); $rowsArr = explodeRows($theData); for($i=0;$i<count($rowsArr);$i++) { $lineDetails = explodeTabs($rowsArr[$i]); echo "<br>Steam ID: " . $lineDetails[0]; echo "<br>Surname : " . $lineDetails[1]; echo "<br>Tel Number : " . $lineDetails[2]; echo "<br><br>"; } function explodeRows($data) { $rowsArr = explode("\n", $data); return $rowsArr; } // Explode the columns according to tabs function explodeTabs($singleLine) { $tabsArr = explode("\t", $singleLine); return $tabsArr; }
  9. I've managed to get it working for the most part by doing $text = str_replace("\n", '<br>', $get); print($text);
  10. That did not help. I just cant echo php, plain text is fine. I've even tried base 64 encoding/decoding with no luck.
  11. I've found that my problem is <?PHP tags. When "<?PHP" or "?>" is saved in a database an d tried to echo it messes things up. How can I input and output PHP tags without it trying to run the code?
  12. even using that code returned nothing. It's like it's getting a result but having trouble echoing it
  13. Trying the following displays nothing include('includes/session.php'); $result = mysql_result(mysql_query("SELECT text FROM text WHERE id = '1'"), 0); echo $result; This is what is saved in that row on the DB <?PHP $name = \'Wee493\'; $string = \'Hello World this is \'.$name.\'!\'; echo $string; ?>
  14. I'm wanting to save snipets into an sql database and be able to display them later (Similar to pastebin and those types of sites). I've already setup a table with the type set to text and have syntax highlighting taken care of. On the way in I'm doing mysql_real_escape_string() on the text but when I try to echo it out I have minimal luck. Can anyone offer any suggestions/help?
  15. Thank you so much! I've made a few minor changes and adapted it to my need. The efficiency is not a really problem, I most likely will never go over four characters as (if my math is correct) this should give me almost 3,000,000 unique results. I'm getting better at PHP, just need to learn a little bit more about lines like this $string[$x] = $string[$x] === strtoupper($string[$x]) ? strtolower($string[$x]) : strtoupper($string[$x]);
  16. Currently I'm incrementing letters, for example aa, ab, ac ... az, ba. But I would like to make it so it goes aa, Aa, AA, aA, bb, Bb, BB... I'm halfway through making the code below, but I though I would ask if there is a better/easier way to do this? I would like to be able to support strings longer then 2 or three characters. Maybe a function or something? $prev = 'aa'; // Capitalize fist letter if not and second letter not if(!ctype_upper(substr($prev, 0, 1)) && !ctype_upper(substr($prev, 1, 2))){ $part_one = strtoupper(substr($prev, 0, 1)); $part_two = substr($prev, 1); $prev = $part_one.$part_two; } // Un-Capitalize first letter if first and second are if(ctype_upper(substr($prev, 0, 2))){ $part_one = strtolower(substr($prev, 0, 1)); $part_two = substr($prev, 1); $prev = $part_one.$part_two; } // Capaitalize second letter if first is already if(ctype_upper(substr($prev, 0, 1)) && !ctype_upper(substr($prev, 1, 2))){ $part_one = strtoupper(substr($prev, 0, 2)); $part_two = substr($prev, 2); $prev = $part_one.$part_two; } echo $prev;
  17. I'm working on a google chrome plugin for my url shortener. It use jquery + ajax to get the url of my api page. For example: site.com/api.php?d=http://google.com It's working fine, but I want users to be able to specify a custom url where the plugin gets user input from a text form, the gets a url like the following site.com/api.php?custom=test&d=http://google.com Here is the code, the function named redo is the one that's giving me trouble. It's running the function, but not querying the ajax call. <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script> window.addEventListener("load", windowLoaded, false); function windowLoaded() { chrome.tabs.getSelected(null, function(tab) { var url = tab.url; $('#result').load('http://twi.im/api/api.php?type=chrome&d=' + replace_multiple(tab.url)); }); } function redo(){ document.getElementById('body').style.backgroundColor = '#CCC'; //document.getElementById('url').innerHTML = 'Custom: ' + document.getElementById('custom-val').value; $('#short').load('http://twi.im/api/api.php?custom=' + document.getElementById('custom-val').value + '&d=' + replace_multiple(tab.url) + short.value); } </script> <style> body { width: 250px; overflow: hidden; } img { vertical-align:middle; } .result { width: 250px; height: 60px; } </style> </head> <body id="body"> <div class="header"> <img src="http://www.bigroncoleman.com/Pages/twitter-logo.gif" width="250px" border="0"> </div> <div id="result" class="result"> <center><strong>Loading...</strong></center> </div> <script> function custom(){ document.getElementById('custom-lable').style.display = 'inline'; document.getElementById('custom-input').style.display = 'inline'; document.getElementById('custom-submit').style.display = 'inline'; document.getElementById('cust').style.display = 'none'; } function replace_multiple(str){ var str = str; str = str.replace(/&/gi, "%26"); str = str.replace("?", "%3F"); return str; } </script> <script type="text/javascript"> function trackButton(name) { _gaq.push(['_trackEvent', name, 'clicked']); }; </script> </body> </html> You should not need this, but Here is the returned page from api.php <table border="0"> <tr> <td width="25%" align="right">URL:</td> <td><input type="text" value="http://twi.im/<?PHP echo $url; ?>" onClick="this.select();" id="short" readonly="readonly" /></td> </tr> <tr> <td colspan="2" align="center" id="cust"><a href="#custom" onClick="custom(); trackButton('Custom');">Custom URL?</a></td> <td id="custom-lable" style="display: none;">Custom:</td> <td id="custom-input" style="display: none;"><input type="text" name="custom" id="custom-val"></td> </tr> <tr> <td colspan="2" id="custom-submit" style="display: none;" align="center"><input type="submit" onclick="redo(); return false;" value="Update" /></td> </tr> </table> <script> var short = document.getElementById('short').select(); document.execCommand('Copy'); window.getSelection().removeAllRanges(); </script>
  18. I just tried the script on another we server with the same problem. Why could the code be working fine on a local install of php, but not on my webserver?
  19. This is because the variables are not being posted to your script. Are u meaning to use $_GET ?
  20. Login Form <td>Username:</td> <form action="login.php" method="post"> <td><input type="text" name="user" size="15" maxlength="25"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="pass" size="15" maxlength="25"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Login" style="width: 50px; height: 30px; "></form></td> session.php <?PHP // Start Session session_start(); // Require database connection script require('db.php'); include('include/errors.php'); // If user dose not have a session variable set for username... if(!isset($_SESSION['user']) or $_SESSION['user'] == ''){ // Keep user logged in from previous cookie? if(isset($_COOKIE['user_hash']) && $_COOKIE['user_hash'] != ''){ $hash = $_COOKIE['user_hash']; $check = mysql_query("SELECT username FROM user WHERE hash = '$hash' LIMIT 1"); if(mysql_num_rows($check) != 0){ $_SESSION['user'] = mysql_result($check, 0); } } else { // No cookie so user is a guest $_SESSION['user'] = 'guest'; } } $user = $_SESSION['user']; ?>
  21. I recently created a login script on my website to log a user in using a form. I coded the script locally using wamp and it works fine there, but when I uploaded it to my server it logs the user in ever time regardless of the password used. I can post a link to my site with it not working if that would help. Any suggestions? <?PHP include('include/session.php'); if(isset($_GET['out']) && $_GET['out'] == 1){ $_SESSION['user'] = 'guest'; header("Location: index.php"); } if($_POST['user'] != '' && $_POST['pass'] != ''){ $user = $_POST['user']; $pass = md5($_POST['pass']); // Dose user exist $check = mysql_query("SELECT password FROM user WHERE username = '$user'"); if(mysql_num_rows($check) == 0){ //error(4); $error = 4; } else { // Check Password if(mysql_result($check, 0) == $pass){ $_SESSION['user'] = $user; header("Location: index.php"); } else { $error = 5; } } if(isset($error) && !is_array($error)){ header("Location: index.php?error=".$error); } } // end if post function error($code){ header("Location: index.php?error=".$code); die(); } ?>
  22. On my site I have a span with a loading image in it. By default it's hidden, but every 10 seconds my page is set to check with the server for changes. The image displays perfectly in Firefox, but not in chrome/safari (I guess it's a problem with webkit). I am using the ajax from the pinned beginners ajax guide, I've used it many times before as I'm a noobie with ajax and I have not gotten around to learning it yet, just hacking it together. You can see my site here... http://wee493.com/lastfm/homepage/index.php?user=josho493 (I'm using the last.fm api to get a users info, feel free to plug in your last.fm username if if you have one ) I made a few modifications to his code, I added this.... // handle the httprequest MyHttpRequest.onreadystatechange = function () { if(MyHttpRequest.readyState == 4) // done and responded { document.getElementById(target_div).innerHTML = MyHttpRequest.responseText; // display result document.getElementById('recent-loading').style.display = 'none'; // Hides loading image } else { document.getElementById('recent-loading').style.display = 'inline'; // Shows loading image //document.getElementById(target_div).innerHTML = MyHttpLoading; // Commented out so the data is still displayed while loading } } MyHttpRequest.send(null); } else { document.getElementById(target_div).innerHTML = ErrorMSG; // the browser was unable to create a httprequest } } Thanks for any help, It's greatly appreciated.
  23. Sorry, forgot to put that this is the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''lfmuser', 'artist', 'artistmbid', 'name', 'album', 'albummbid', 'trackurl', 'pl' at line 1
  24. I keep getting an error with this query, what could be wrong with it? Here is my database http://grab.by/grabs/e2245fe272af915a98f186b9e9966ee1.png $query = mysql_query("INSERT INTO scrobble ('lfmuser', 'artist', 'artistmbid', 'name', 'album', 'albummbid', 'trackurl', 'playdate', 'nicedate') VALUES ('$user', '$artist', '$artist_mbid', '$name', '$album', '$album_mbid', '$url', '$date', '$nicedate')") or die(mysql_error());
  25. I'm creating a stat-type page for last.fm. Using a foreach loop I'm returning the data from the last.fm api. I'm linking artist names to the appropriate artist page and so on with songs & albums. The only problem is that in two of the three loops only the links from the first result are working. The <a hef is displayed when viewing the html source, I'm stumped. You can see for yourself here... http://wee493.com/lastfm/?user=josho493 (Feel free to plugin your own last.fm username here if you would like ) Here's one of the loops that is having the problem. <?PHP $top_tracks = $lastfm->user_getTopTracks("user=".$user); foreach ($top_tracks['lfm']['toptracks']['track'] as $trk){ $rank = $trk['attr']['rank']; $name = $trk['name']['value']; $playcount = $trk['playcount']['value']; $url = $trk['url']['value']; $artist = $trk['artist']['name']['value']; $artist_link = $trk['artist']['url']['value']; if($rank <= '10'){ ?> <div class="top"> <div class="rank"> <?PHP echo $rank; ?> </div> <div class="top-song-info"> <div class="title"> <a href="<?PHP echo $url; ?>" target="_blank"><?PHP echo $name; ?></a> </div> <div class="artist-info"> <span class="artist"><a href="<?PHP echo $artist_link; ?>" target="_blank"><?PHP echo $artist; ?></a></span> <span class="date"><?PHP echo $playcount; ?> Plays</span> </div> </div> </div> <?PHP } /* end if */ } // end foreach Any help is appreciated! Thanks
×
×
  • 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.