Jump to content

physaux

Members
  • Posts

    208
  • Joined

  • Last visited

    Never

Everything posted by physaux

  1. Hey guys, I am making a site where certain content will be limited to "members only", where membership is free. Now I want the google bot or whatever bot to be able to see and index this content, but when a user visits it, I want to hide it from them unless they are a member (I already do that). So basically I want to have a function that I can call that will return true or false if the current page is being requested by a search engine spider. I know it's possible because I regularly see forums doing that; posts are hidden unless you register but if you look through the google cached version, the posts are visible. How can I do that? so far all I have is the following, so that the rest of my code works. function is_spider(){ return true; } I read a http://iarematt.com/how-to-detect-a-search-engine-spidercrawler-with-php/ which talks about this, but I don't really trust it... What do you guys think, How can this be done?
  2. So I have been printing out some debug information, and now I am trying to instead save it to a string, which I will print out at the end of the page. Here is some specific problematic code: $myplugin_debug_test.= "\n[GETTING COOKIES...\n"; $myplugin_debug_test.= print_r($myplugin_all_cookies);//THIS IS LINE 38 $myplugin_debug_test.= "\n... DONE]<br/>\n"; However, when I do this I get the following error: So my question is how can I output the array data into a string, so that I can print it out later. Like what am I doing wrong? Is there a better way to do this? Thanks!
  3. Ah, thank you for being blunt. I'll try and ask the question better this time. I'm writing a plugin for wordpress. Through the "found_posts_query" filter hook, I am able to add some custom MYSQL code inplace of WP's "SELECT FOUND_ROWS()" From the site: http://codex.wordpress.org/Plugin_API/Filter_Reference#Advanced_WordPress_Filters That is the background information. I need help in formatting a MYSQL statement that will do the following objectives inplace of the original "SELECT FOUND_ROWS()": -return the same rows that the original SELECT FOUND_ROWS() statement would have, except... --I want to remove all rows but 1 that have a value of "7" for their category, and leave other rows that don't have "7" for category in their original order I have no idea how to create this MYSQL query.. Thanks!
  4. Ok so, I'm in the process of struggling to create a WP plugin. I've narrowed down what I need to do to a few MYSQL commands. Basically, WP created a massively insane query for fetching posts to display on a certain page. WP would normally get this data now with the following MYSQL command: SELECT FOUND_ROWS() I am at the point in my code where I can replace this code, to manipulate the rows to my liking. (Through WP's "found_posts_query" filter hook; http://codex.wordpress.org/Plugin_API/Filter_Reference#Advanced_WordPress_Filters) What I want to do: -remove all rows CATEGORY = X except the first row that is CATEGORY = X -properly finish this operation with Select found_rows() (?i think?) *By the way I'm only very minutely experienced with MYSQL, so please bear with me. And so my question is... :confused:how the heck do i do this? Which mysql commands would I use? I'm totally lost. Thanks!
  5. Hey guys so I'm trying to write a wordpress plugin. But nothing I do is working!! I'm not sure even how I should approach this problem, which filter hooks to use and how. I've been searching everywhere for help, but to no avail. /whining Anyways, here is what I want to do: Create a plugin for Wordpress that does the following: -prevents posts from category [some X] from being displayed- EXCEPT if the post ID is [some Y] Any idea how to do this? I'm thinking of editing the WP query but I'm not sure how to do that...
  6. Ok so, I am trying to replace all instances of "%" with a random character. I first tried this: $realoutput = str_replace("%",randomchar(),$realoutput); randomchar() is a custom function I have. My problem is that it replaces the % with only 1 result of "random char()". So with 12%12%12% I get 12R12R12R or 12P12P12P instead of something like 12O12Y12N. Any suggestions how I can get the result that I want? I can't seem to figure it out! :confused:
  7. yipee :D Thanks, it works perfectly now!
  8. Thanks for the corrections, and the very detailed explanation. It is no longer telling me about an error, but it is still not printing out the data that I wanted. Just to be safe, I printed out the contents of $page on the screen, as well as printed out the contents of $regex, as well as the resulting array. RELEVANT $page DATA COPIED FROM "view source" of the output of my code(This is all on one line. I only added new lines to make it easier for you to see): <p> 1 <a href="/browse/letter/a?page=2">2</a> <a href="/browse/letter/a?page=3">3</a> <a href="/browse/letter/a?page=4">4</a> <a href="/browse/letter/a?page=5">5</a> <a href="/browse/letter/a?page=6">6</a> <a href="/browse/letter/a?page=7">7</a> <a href="/browse/letter/a?page=8">8</a> <a href="/browse/letter/a?page=9">9</a> <a href="/browse/letter/a?page=10">10</a> <a href="/browse/letter/a?page=11">11</a> <a href="/browse/letter/a?page=12">12</a> <a href="/browse/letter/a?page=13">13</a> <a href="/browse/letter/a?page=14">14</a> <a href="/browse/letter/a?page=15">15</a> <a href="/browse/letter/a?page=2">next»</a> </p> Here is the printed out $regex ~browse/letter/a\?page=([0-9]+)"~ And here is the printed out $matches result Array ( [0] => browse/letter/a?page=2" [1] => 2 ) And once again, here is all my code: echo $page; echo "AFTERPAGE\n\n\n<br/><br/>\n\n"; //$regex = "~browse~/letter~/".$letter."?page=.*\">(.*)<~/a>~Us"; $regex = "~browse/letter/$letter\?page=([0-9]+)\"~"; echo $regex."\n\n"; preg_match($regex,$page,$matches); print_r($matches); -Oh and if it matters, $page is gotten by using 'curl'. But I'm sure that it works fine because of the outputed values, they are the same as when I view the URL i'm scraping using 'curl' Soo, does anyone still see a problem? I want the resulting array to contain 2,3,4,...,14,15. But it's not!
  9. OK thanks, that one is working now. Now I am trying a second part, which I will now (try to) describe below. second part second part second part need a new regex. Please ignore previous posts, they were for the first regex. I now have a second one that is causing me problems. This boldness is just to prevent confusion second part second part second part So here is the raw text that this script will be chewing through: <a href="/browse/letter/a?page=2">2</a> <a href="/browse/letter/a?page=3">3</a> <a href="/browse/letter/a?page=4">4</a> <a href="/browse/letter/a?page=5">5</a> <a href="/browse/letter/a?page=6">6</a> <a href="/browse/letter/a?page=7">7</a> <a href="/browse/letter/a?page=8">8</a> <a href="/browse/letter/a?page=9">9</a> <a href="/browse/letter/a?page=10">10</a> <a href="/browse/letter/a?page=11">11</a> <a href="/browse/letter/a?page=12">12</a> <a href="/browse/letter/a?page=13">13</a> <a href="/browse/letter/a?page=14">14</a> <a href="/browse/letter/a?page=15">15</a> (there are no newline characters, I added them just so that the code above does not get squished into a single line) I want to extract how many pages there are. So I would want the result array to be 2,3,4,...,15 So from my understanding, I am looking for something that starts with browse/letter/a?page= and ends with " ..right? I now tried to change my delimiter to "~", here is what I have so far: $regex = "~browse~/letter~/$letter?page=(.*)\"~Us"; echo $regex."\n\n"; preg_match($regex,$page,$matches); print_r($matches); But I am getting an error Unknown modifier '/' Thanks for the help before! How about this one?
  10. Ok so here is my preg match so far, but I am getting an error that says something to do with a delimiter. preg_match('/somedomain.com/name-meaning/(^)">/',$pagedata,$matches); print_r($matches); I really have no clue what I am doing. Could anyone please fix that regex expression for me please (and tell me what is wrong)? Thanks!
  11. Here is a sample line of what I would have to find: somedomain.com/name-meaning/XXXXX"> I want to make a preg_match expression to find for me the XXXXX (which is a name, so 1-~20(?) characters) Could someone help me please!
  12. Hey guys I have a table about my users. One of the entries is "last_login", which is as so: http://img340.imageshack.us/img340/3986/picture2hb.png I regularly get data from this. I would like to update the timestamp thought. I'm not sure exactly how to do this. It is my understanding that it will update itself if I edit the record. But I don't want to edit the record, I mainly just read it. So is there any 'command' that I could run to update to the current time at the time of running this command? There's probably a simply mysql line to MODIFY the timestamp, but I've been searching for hours now and I can't find how to do it :'( :'( Hope that makes sense. Thanks!
  13. OK nevermind I got it now. This part of the sql query was bad: user_id=test123 Changed to user_id='test123'
  14. Ok so I cleaned out all the errors, but the edit command is still not working. Here is the function now: function updateid($edit_id,$edit_name,$edit_email,$edit_verified){ $sqlquery = "UPDATE users SET name='$edit_name',email='$edit_email',verified='$edit_verified' WHERE user_id=$edit_id"; echo "[$sqlquery]"; $results = mysql_query($sqlquery); } It prints out [uPDATE users SET name='TESTNAME',email='test@email.com',verified='1' WHERE user_id=test123] (Just so I can be sure of the query). Here is a picture of the MYSQL table entry called 'users', right after I run this command. Notice the 'verified' doesn't get changed to 1. http://img193.imageshack.us/img193/4632/picture1mgh.png *I run other commands that work already, so I know the database connection works fine. Here is a copy of WORKING function: function doesidexist($user_id){ $user_id = mysql_real_escape_string($user_id); if(mysql_num_rows(mysql_query("SELECT * FROM users WHERE user_id = '$user_id'"))){ return true; }else{ return false; } } So does anyone see a problem? If it matters 'verified' data type is boolean. Thanks
  15. Wow thanks for all the help guys. I changed the variable name, thanks I didn't notice that mistake. I also added ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); To the top of my code. It spit out ~10 errors, give me a second to sift through them to see if it worked
  16. Hey guys I am trying to edit a row, with a function that I have. Here is the function: function updateid($edit_id,$edit_name,$edit_email,$edit_verified){ $mysql_query = "UPDATE users SET name='$edit_name',email='$edit_email',verified='$edit_verified' WHERE user_id=$edit_id"; $results = mysql_query($sqlquery); echo "RAN UPDATE ID FUNCTION"; } The problem is that when I check in PHPMYADMIN if the changes happened, they don't. But my screen echos "RAN UPDATE ID FUNCTION". So I know the function is running but there is something wrong. So my questions are: -do you see any obvious problems? -how can I 'see' the MYSQL 'response'? I'm sure it throws an error, but IDK how to see that error. THanks!
  17. Ok so, can I run an SQL query inside of a function? For example, look at my code below. Can I do that? function dosomething(){ $sqlquery = "SELECT * FROM $table WHERE ip_address = '$ip' LIMIT 1;"; $results = mysql_query($sqlquery); $rowoutput = mysql_fetch_assoc($results); $chosenurl = $rowoutput['url']; return $chosenurl; } mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); //... $url = dosomething(); //... I know that for variables, I have to say 'global'. Do I need to do something like that for this mysql query as well?
  18. Hey guys, I want to 'encrypt' a string. The string will only be a short, 20 character length MAX. I want a function that could 'encrypt' the string, giving me OUTPUT. I then want to process OUTPUT to give me the original string. Important thing is that the OUTPUT be as short as possible. Any advice? I'm not really concerned with security, I just want the OUTPUT to not reveal what the original string is to a basic person. No sensitive information. Thanks!
  19. Ok my error now is Unknown column 'date_created' in 'where clause' Hmm I'm really confused. Could it be the settings of my table? idk
  20. Yes, I am doing date_add temporarily because I only had recent results, and I wanted to make it delete the records. As you say it should delete them all, but it doesn't. I'm about to add the echo mysql_error(); to the code, and see what happens. I'll edit this message when I return EDIT: ok it gave this 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 '2 days)' at line 1 any ideas??
  21. so was my echo a proper MYSQL syntax? I still haven't found the problem :'(
  22. Ok I echo'd the value. Here is the output: DELETE FROM splittest WHERE date_created < date_add(CURRENT_DATE, 2 days) Here is the exact code copy pasted so you can see where echo was: $sqlquery = "DELETE FROM $table WHERE date_created < date_add(CURRENT_DATE, $numdays days)"; echo $sqlquery; $result = mysql_query($sqlquery); mysql_close();
  23. Ok my sql query is now $sqlquery = "DELETE FROM $table WHERE date_created < date_add(CURRENT_DATE, $numdays days)"; But it is still not deleting any of the entries in my table. Anyone see how I can fix?
×
×
  • 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.