vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help with plugin array and option settings (https://vborg.vbsupport.ru/showthread.php?t=264820)

kh99 06-08-2011 03:02 AM

Can you write files via php on your server? I like to debug stuff by printing things to a file then looking at it after loading the page. Like sometimes I just throw in a

Code:

fwrite(fopen("output.txt", "w"), print_r($var, true));

...I think that actually shouldn't work on a "live" server ( unless you put in a path to a different directory) because the web server user usually doesn't have write access. But anyway the point is that it will probably save time if you can figure out some way to see what's going on in there.

Simon Lloyd 06-08-2011 03:17 AM

I have dedicated so have all the access i need!, do i just use that line like that or does it need modifying to suit?

kh99 06-08-2011 03:20 AM

You'd want to replace $var with the variable you want to see (or any message you want to print out). And of course you could put a path on the file name if you need to. And if you want to print out in more than one place you can separate the fopen() from fwrite()s. (like $fp = fopen("output.txt", "w"); fwrite($fp, "Hello World"); etc)

That the kind of thing I've been using, but maybe someone else has a better idea.

Simon Lloyd 06-08-2011 03:24 AM

lol, now you've lost me!, firstly the line does work on a live server :), i've changed it to this (if its correct) fwrite(fopen("output.txt", "w"), print_r($bots[$i], true)); and put it ight after the redirect statement. Below is what it gave:
MOZILLA/5.0 (COMPATIBLE; BAIDUSPIDER/2.0; +HTTP://WWW.BAIDU.COM/SEARCH/SPIDER.HTML)


Does that mean the plugin is working?

kh99 06-08-2011 03:31 AM

At least you know that the plugin is running. I'm not sure exactly where you put the line.

The way that line is above, if you fopen with "w" it will truncate the file, so if you put it in a loop you're only seeing the last time through the loop. You can change it to "a" to append, but then it will add to the file every time you run it. (I guess the thing to do is to put one in at the beginning with "w" and if you put it in more than once, make the others "a").

Anyway, I'm sure you get the idea. You can see what code's executing and what the string values are and you should be able to figure out where it's failing (unless it's working and just not doing what you expect) :)

Simon Lloyd 06-08-2011 03:32 AM

Thanks very much for this help, thats really useful :)

kh99 06-08-2011 03:42 AM

Oh, I see now you said that you put the line right after the redirect (I guess its too late for me to be thinking). Do you mean after the call to banned_redirect()? Then I guess strstr() isn't matching or else it wouldn't get there.

Anyway, let us know how it goes.

Simon Lloyd 06-08-2011 03:50 AM

Right, i put the line like below and tried different variations:
PHP Code:

[I]if (stristr($user_agent,$bots[$i])) banned_redirect('www.google.com.cn/search?hl=zh-CN&q=crystal+light+centrum&meta=');
fwrite(fopen("output.txt""a"), print_r(stristr($user_agent,$bots[$i]),true));
} [/
I

If i used
PHP Code:

 fwrite(fopen("output.txt""a"), print_r(stristr($user_agent,$bots[$i]),true)); 

i get a very long string of repeating UA's, one thing of note is that when one finished another one started like this:
Quote:

MOZILLA/5.0 (COMPATIBLE; YANDEXBOT/3.0; +HTTP://YANDEX.COM/BOTS)MOZILLA/5.0 (COMPATIBLE; BAIDUSPIDER/2.0; +HTTP://WWW.BAIDU.COM/SEARCH/SPIDER.H...A/5.0......etc
so i guess it's seeing the UA like MOZILLA/5.0 (COMPATIBLE; YANDEXBOT/3.0; +HTTP://YANDEX.COM/BOTS)MOZILLA/5.0 does that sound feasible or am i missing something?, my other plugin's use the same explode....etc and deliver emails dependant on criteria, they also strstr the same string and they have no trouble?

--------------- Added [DATE]1307508696[/DATE] at [TIME]1307508696[/TIME] ---------------

It's 6am here and im off home to bed in a couple of hours, maybe i'll catch you later :)

kh99 06-08-2011 04:37 AM

Oh right, there's no newline in that fwrite so you're just getting multiple prints coming out on the same line. And I think what I said earlier wasn't exactly correct - if you want to print out a string you don't need the print_r. And I find when printing out strings it's a little less confusing if you put some quotes in there. So you'd probably want something like:

fwrite(fopen("output.txt", "a"), "'" . stristr($user_agent,$bots[$i]) . "'\n");

Simon Lloyd 06-08-2011 01:04 PM

For some reason all i get with that line is '' on many lines but no info?


All times are GMT. The time now is 04:36 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01010 seconds
  • Memory Usage 1,745KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete