PDA

View Full Version : Problem with php-direct "hello world" reading arguments


janaf
09-30-2010, 08:43 AM
I have a php direct eval page but have problems after 4.0.7 update.

Functionally, the code depends on this line, which is not working:
$mystring=vB::$vbulletin->input->clean_gpc('r', 'mystring', TYPE_STR);
$output=$mystring;

The code should read URL arguments: <myurl>&mystring=Hello
Now, it returns nothing, $mystring is empty. Does anyone have a suggestion how to make this work? Workarounds?

I have also tried this syntax:
$mystring=$vbulletin->input->clean_gpc('r', 'mystring', TYPE_STR);
but get: Fatal error: Call to a member function clean_gpc() on a non-object in <url>

A slightly longer version with the cycle of what the page does is here; it has a form with a drop-down posting values to itself:

$mystring=vB::$vbulletin->input->clean_gpc('r', 'mystring', TYPE_STR);
$output=$mystring;
$output.='<br><form action="" method="POST">';
$output.='<input type="hidden" name="securitytoken" value="'.vb::$vbulletin->userinfo[securitytoken].'" />';
$output.='<select name="nominalsize"><option value="">[Say Hello]</option><option value="Hello World">Hello World</option></select><br>';
$output.='<input type="submit" value=" Submit " />';
$output.='</form>';

This page where I used this code used to have a few thousand pageviews daily, and is now at stand-still for more than a week :mad:

A long version with my full code is here;

https://vborg.vbsupport.ru/showthread.php?t=250920

But the key to the problem is the first line here, so the longer version may just be confusing...

Please help! My vb-coding experience is low, I'm depending on you guys.....

Deceptor
10-01-2010, 01:39 AM
This should do the trick
$vbulletin->input->clean_array_gpc('r', array(
'mystring' => TYPE_STR,
));

$mystring = $vbulletin->GPC['mystring'];

janaf
10-01-2010, 09:55 AM
Thanks deceptor,

I have found that the problem is a caching problem. All the time the cache refresh time has been set to zero but still old content is displayed, also even if the POST arguments are changed. I remember now that I had the caching problem when I originally wrote the first code, but it was solved by setting caching to zero for the vB content. But this seems to be back now. I can read the argument once, after saving the code, but then that result "sticks" enen after a page refresh. So if the page is read first time without arguments, then none are read until some time has passed. Can I codewise explicitly disable caching?

:confused:

With your syntax I am getting:

Fatal error: Call to a member function clean_array_gpc() on a non-object in <url>phpeval.php(97) : eval()'d code on line 1

Can you confirm this syntax works with a 4.0.7? Something wrong with my vb installation?

This also works, no error message, but with the caching problem:

vB::$vbulletin->input->clean_array_gpc('r', array('mystring' => TYPE_STR));
$mystring =vB::$vbulletin->GPC['mystring'];

Lynne
10-01-2010, 01:46 PM
Deceptor just forgot the vB:: , otherwise they are the same.

There is a bug with cache set to 0. The fix is posted in the bug report over in Jira.

janaf
10-01-2010, 08:59 PM
Thanks Lynne,

Before reading your post I made a bug report http://tracker.vbulletin.com/browse/VBIV-9336

I found your solution suggested here:
http://www.vbulletin.com/forum/showthread.php?362542-CMS-Widget-quot-Cache-refresh-time-quot-doesn-t-seem-to-work.&highlight=Cache+refresh+time
and the bug tracker here http://tracker.vbulletin.com/browse/VBIV-8082

However, it did not work for me. I tried the suggested code changes, flushed the CMS cache several times, even re-started Apache.

I also tried other more drastic code changes in execphp.php like:

if (!isset($config['cache_ttl']) )
{
$config['cache_ttl'] = 0;
}
and
if ($config['cache_ttl'] > 999999)......
But it seems that whatever I do, the php direct content was still cached. Maybe pending some site specific setting?

Also this does not work for me:

ACP => Options => Add No-Cache HTTP Headers => Help Cookies and HTTP Header Options = yes

This works perfectly but of course degrades the site performance:

ACP => Options => Server Settings and Optimization Options =>Disable Content Caching

I tested mostly with this one-line php direct evaluation code

$output=vB::$vbulletin->input->clean_gpc('r', 'mystring', TYPE_STR);

And calling the page with a browser call like <url>&mystring=xxxxxx

So any ideas on what I can do?

Lynne
10-01-2010, 09:25 PM
Actually, I was thinking about the wrong thing above. Your code isn't in a widget which is the bug report I was thinking of. So, changing the cache code in the widget isn't going to help you out at all.

janaf
10-01-2010, 10:56 PM
Ah, the "execphp.php" looked right to me.

I can see there is a /packages/vbcms/content/phpeval.php which has two suspect lines:

on line 60:
'cache_ttl' => '60',
and on line 67
protected $cache_ttl = 60;

So it caching is hardcoded to 60 minutes there?

I tried setting these to zero but that did not help :o

Lynne
10-01-2010, 11:02 PM
To be honest, I don't know. I really don't know much about the caching in the CMS.

janaf
10-01-2010, 11:21 PM
For now, I am running the site all un-cached, working acceptably. It's on a dedicated server and is not heavily loaded. I can keep it that way until I see what comes out of the bug report / Jira....

http://www.41hz.com/forums/content.php?253-TSdb

LizP
10-13-2010, 08:57 PM
This is just a hack, but I had to solve this problem ASAP and here's what I did... I basically turned off rendering a cached page for direct PHP eval pages, which honestly if I'm using the eval pages it's likely b/c the content is dynamically being created so I don't want to use a cached page anyway.

On line 60 of packages/vbcms/item/content/phpeval.php:

// if ($preview_only OR $this->rendered['rendered_text'])
if ($preview_only)

That's it. Keep in mind, this hack will be overwritten by future upgrades, but hopefully vb will have the issue resolved by then. Hope this helps get you running today though!

janaf
10-18-2010, 11:02 AM
Thanks LizP! This works for me too.

Just judging from the variable names, it seems like this is for the non-preview only but that if fine with me.