Jump to content

joel24

Members
  • Content Count

    760
  • Joined

  • Last visited

Everything posted by joel24

  1. well if it's only calling it once and you're receiving a 403, either you've been manually blocked or the IP of your shared host has hit it too many times. Can you run that script successfully from another IP? i.e. your local machine? that way you can debug - or contact geoplugin enquiring as to why you're receiving the 403 from your IP.
  2. "Unless otherwise indicated, all photographs on photo.net are copyrighted by the photographers, whose permission is required for any usage."
  3. your jsfiddle works fine though the css has the following declaration which is hiding the radio button. [type=radio]{display:none} if you change that to [type=radio]{display:block;} and then wrap each image and the associated radio button in a div and float to the left you can group them and play with the css.
  4. ahh sorry, as the substr counts the first char as 0, it needs to go from 0-3 Also, my loop was removing the $i position character rather than a random one... I've put in a method which will return a random number which has not been removed from the string as yet. I've done some tests and it's working - let me know if you've any queries about the code function getRandomCharToRemove(array $alreadyRemoved, $strLength) { $random = rand(0,$strLength-1); //substr starts from char 0 so we need to subtract 1 from strlen return (!isset($alreadyRemoved[$random])) ? $random : getRandomCharToRemove($alreadyRemoved,$strLength); } $maxCharsToRemove = 2; $word = 'bees'; $strLength = strlen($word); $charsGettingRemoved = rand(1,$maxCharsToRemove+1); $charsRemoved=array(); for ($i=0;$i<$charsGettingRemoved;$i++){ $randomCharToRemove = getRandomCharToRemove($charsRemoved,$strLength); $charsRemoved[$randomCharToRemove]=substr($word,$randomCharToRemove,1); $word = substr_replace($word,'*',$randomCharToRemove,1); } echo "Your word is: $word<br/>The letters missing are: " . print_r($charsRemoved,1)."<br/>Len: $strLength<br/>Chars removed [position => letter]: $charsGettingRemoved";
  5. Can you post the full trace? And can you check that your APP_ENV param is set in your /.env file and let us know what it is?
  6. session_start(); $_SESSION['currentWord'] = 'bees'; $word = $_SESSION['currentWord']; $length = strlen($word); $maxCharsToRemove = 2; //you could swap this for a algorithm based on the strlen (i.e. ceil($length/3)) -- lets round up incase the division is less than 0 $charsGettingRemoved = rand(1,$maxCharsToRemove); $charsRemoved=array(); for ($i=1;$i<=$charsGettingRemoved;$i++){ $charsRemoved[$i]=substr($word,$i,1); $word = substr_replace($word,'*',$i,1); } echo "Your word is: $word<br/>The letters missing are: " . print_r($charsRemoved,1)."<br/>Len: $length<br/>Chars: $charsGettingRemoved"; //and when teh users posts the form, concatenate all of the posted characters and see if it equals to $_SESSION['currentWord'] and then for the html <input type="text" name="question_1_letters[]" class="inputs" maxlength="1" value="" /> <input type="text" name="question_1_letters[]" class="inputs" maxlength="1" value="" /> <input type="text" name="question_1_letters[]" class="inputs" maxlength="1" value="" /> <input type="text" name="question_1_letters[]" class="inputs" maxlength="1" value="" /> the above html will be accessible in an array of $_POST['question_1_letters'] and will automatically receive indexes... so you can implode and see that it equals to the question 1 word if (implode('',$_POST['question_1_letters'])==$_SESSION['currentWord']) //they got it right else //they got it wrong apologies for rewriting your code, i started out fixing yours though thought it easier to understand written this way... and easier to scale
  7. what is your pollsession function? it's calling another api so shouldn't be initiating another request to geoplugin. Could you show us the pollsession() function and also put the following line on your script after $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".$ip); // put after the above line which is already in your code $_SESSION['geoplugin']=(isset($_SESSION['geoplugin'])) ? $_SESSION['geoplugin']+1 : 1; echo "<p>Calling geoplugin {$_SESSION['geoplugin']} times</p>";
  8. is your min/max being set in the sql query? add in a var_dump($min,$max,$_POST); exit; and let us know the response
  9. not entirely sure what you're after - you want the previous/next buttons to trigger the same ajax method and update the href of the previous/next?
  10. You should be using ID instead of class if the element is unique? i.e. you're not updating multiple elements? you can add a class also if you've got some css <a class="link></a> (works correctly running ajax request with url of wordpress post) <a id="next" href="#"></a> (should run ajax request with url data.next_url) <a id="previous" href="#"></a> (should run ajax request with url data.previous_url) and then use your javascript to assign the href value when the ajax is returned <script> $(document).ready(function(){ $('.link').click(function(){ if($('#content').css('display') == 'none'){$('#content').toggle();} id = $(this).children('span.title').attr('data-id'); $.ajax({ url: "http://localhost:8888/projects/superfreerespo/" + id, method: "GET", data: {json: 1}, dataType: "JSON"}).done(function( data ) { $("#game-name").html(data.post.title); $("#game-reels").html(data.post.custom_fields.reels); $("#game-paylines").html(data.post.custom_fields.paylines); $("#game-minBet").html(data.post.custom_fields.min_bet); $("#game-maxBet").html(data.post.custom_fields.max_bet); $("#game-jackpot").html(data.post.custom_fields.jackpot); $("#game-info").html(data.post.custom_fields.game_info); // -------------- // You can see below I can log the prev/next values to console //console.log(data.next_url); //console.log(data.previous_url); $('#next').attr('href', data.next_url); $('#previous').attr('href', data.previous_url); // The above json values should be attributed to the next & previous links accordingly and run the ajax request with those url's }) })
  11. which of your six posts would you like replied to? http://forums.phpfreaks.com/topic/295862-rerun-ajax-request-with-variable-url/ http://forums.phpfreaks.com/topic/295861-rerun-ajax-request-with-variable-url/ http://forums.phpfreaks.com/topic/295860-rerun-ajax-request-with-variable-url/ http://forums.phpfreaks.com/topic/295859-rerun-ajax-request-with-variable-url/ http://forums.phpfreaks.com/topic/295858-rerun-ajax-request-with-variable-url/ http://forums.phpfreaks.com/topic/295857-rerun-ajax-request-with-variable-url/
  12. is it a shared webserver? I attempted loading the geoplugin from my local host and repeated a large number of times and now i'm getting a 403 forbidden also. You'll need to either buy a licence for geoplugin as if you're on a shared host, any other users on the same box will have the same IP address and if they happen to be using geoplugin it will impact on your usage... though you'll want to get a unique IP address also, otherwise you buying a licence will entail that other users on your shared host will be able to use your licence.
  13. just use javascript to update the theme when the dom loads, you don't need to know these values in your php script. screen.width; screen.height;
  14. oh i see, I think you'd be best off using a basic relational database and storing the ID rather than having fields with names of 1,2,3 and sending back multiple form fields and expecting to match up the numeric form element name values rather than human readable values... I would create a form table, have that as an incremental ID in that table. Then join each form element (id,type,name,value etc) to that so add an extra row in there of formId And when you submit the form to update, send across a hidden form element with formId... that way you know when you're doing the update you can update where formId = x and name = y since a form shouldn't have the same form element name twice. In your case, you can maintain your current code (which I'd advise against) and simply change the form element name to be myinput[$id] so it passes back an array of the form elements to the server and can loop through those to process.... i.e. //lets echo out the form elements foreach ($formElements as $row){ echo "<input type='{$row['type']}' name='myinput[{$row['id']}]' value='{$row['value']}' />" } now to update the form elements, foreach ($_POST['myinput'] AS $k=>$e) { $sql = "UPDATE yourtablename SET value="{$e}" WHERE id='$k'"; mysql_query($sql); }
  15. could you please post your db schema? tad confused what you're trying to do... as ginerjm said, if you're updating a row you should just be passing back the id of the row in question using a hidden form field and the user accessible form fields would have names which pertain to their respective database column.
  16. I would send the json string with the error message and the 422 header so you can inform the user and separate the logic... otherwise you'll end up with the if/else conditions cluttering the success method. Here's a simplified example though you can play with it - this is a very opinionated topic, end of the day it's the method which will render the cleanest most reusable code for your application. function jsonResponse($httpCode,$message) { http_response_code($httpCode); return(json_encode(array('message'=>$message'))); } $.ajax({ url: "test.html", global: false, success: function() { //handle the 200 success }, error: function() { //catch the 422 and display the message } });
  17. 422 is the most applicable, twitter API also uses this when a request does not pass validation... ** Edit - removing my query asking confirmation of what you're trying to achieve, then I reread your above statement regarding firebug and confirmed you're doing an ajax request **
  18. **edit - I'm assuming you're talking about using a 400 header for an ajax response in validating a form post? Yes I think it's great to use an erroneous http header to separate the success and failure functions within the ajax query and then display the error message to the user whilst maintaining clean code.. i.e. sending a 422 ( or other ) http header response... this way you can handle your ajax as such/ $.ajax({ url: "test.html", global: false, success: function() { //handle the 200 success }, error: function() { //catch the 422 or other and show the message to the user } });
  19. what is the code on checkout.php ? use the code tag when you post PHP - when you're posting it's the little blue icon that looks like this: < >
  20. you need to use javascript to get the the resolution... you'd have to get it, send it via ajax and all kinds of messy code scenarios. Do you need to know it before the template loads?
  21. the function you're referring to is in Muddy_Funster's signature, not directed at this topic. as Muddy said, you're not authorised to access that page. Geoplugin has a usage limit for free access - i've tested your code and it's working fine from my IP. are you running this code on your local machine or a web server?
  22. that would use less server resources and be faster for the user, so yes if you can directly output it, do it
  23. depends on the application you're building. Retrieving the json via ajax will entail an extra connection from each client, though useful if this information will be updated regularly via polling. Having the json in the original php script will use less resources and will ensure the data is available to your javascripts when the page loads... though as above if you're updating the results via ajax anyway you may want to just retrieve via ajax... which would be be most logical for your application?
  24. ... yes, you're echoing two <li> tags - did you want to just echo one or by doubling up do you mean the two tags are appearing twice, i.e. 4 <li> tags? (2 x alpha, 2 not). As as NotionCommotion said - you should use either PDO or mysqli as the mysql function is deprecated as of php 5.5. Read up here for information - the mysqli and mysql functions are very similar... http://php.net/manual/en/mysqli.quickstart.php
  25. function read_log() { global $path; // Declare Array for holding data read from log file $name = array(); // array for file name $count = array(); // array for file count $file_list = array(); $logPath = "$path/Includes/log"; $file = fopen($logPath,"r"); //i've removed your file() command here as fscanf requires a resource handle from fopen() and file() would return an array. if(!$file) { exit("COULD NOT FIND FILE AT $logPath - currently in " . getcwd()); return null; } // Read the entire contents of the log file into the arrays while ($data = fscanf($file,"%[ -~]\t%d\n")) { list ($name, $count) = $data; $file_list[] = array('name'=>$name, 'count'=>$count); } fclose($file); // $file_list contains data read from the log file as an array (filename => count) krsort($file_list); //we need to reverse the array as the log items are added in chronological order (first to last), could use array_reverse here also. exit("returning <pre>".print_r($file_list,true)); return $file_list; } hmmm, might be a path issue. could you try the above - it should exit and show some text. Please copy / paste that text in a reply so I can see it.
×
×
  • 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.