captcha in smarty doesn't work - php

I have this problem with smarty, I tried to add a captcha in smarty but I can't see the way of make it work, basically the error comes when i try to show the captcha image, in a normal php file I could embed this php script:
<?php
$SampleCaptcha = new Captcha("SampleCaptcha");
$SampleCaptcha->UserInputID = "CaptchaCode";
echo $SampleCaptcha->Html();
?>
But for smarty I did this:
$SampleCaptcha = new Captcha("SampleCaptcha");
$SampleCaptcha->UserInputID = "CaptchaCode";
$captcha=$SampleCaptcha->Html();
$sy->assign('captcha', $captcha);
The think is that the variable captcha does print the whole html to show the captcha but when it prints the image attr src it does it in php still.
<img alt="CAPTCHA" src="botdetect.php?get=image&c=samplecaptcha&t=da491a96235a0d9f5fbeb0d7c0accc89" id="SampleCaptcha_CaptchaImage" class="LBD_CaptchaImage">
I tried to use a smarty plugin function but it does the same.
Any expert in smarty may know the answer.
Many thanks.

Try this.
It may help you as this site has good examples across different platforms.

Related

PHP variable in href in PHP

I'm struggling with the syntax of this:
echo '<strong>Datasheet</strong>';
The central PHP element gets a URL from a WooCommerce custom field (I know this works ok on its own). That needs to be turned into a viable link opening a new page, and the whole sits in a PHP wrapper on the page.
Where am I going wrong?
Try this hopefully, it will work.
echo '<strong>Datasheet</strong>';
Try adding more to / changing the href
something like this might work
echo '<strong>Datasheet</strong>';
You'll have to adjust a little bit, but should do the trick

I am trying to embed global session variables with url using iframe

I am trying to embed session variables to url that are set by another module in drupal 7.When i try to make an iframe the iframe works but my session variables are not embedded with url.
Any help will be much appreciated.i also checked sessions using devel modules session viewer they are shown there.
Here is the code that i am using in the iframe content type.
<iframe src="http://www.w3schools.com?"$_SESSION['name']""></iframe>
actully im not aware about drupal but i think this will work
<iframe src="http://www.w3schools.com?sname='"<?php echo $_SESSION['name']; ?>"'"></iframe>
please try this
$_SESSION['name'] shoud be
You need to add php code tag for php code.
Always use for dyanmic codde
i am not drupal developer but in this iframe php syntax is not proper. concatenation is missing .
<iframe src="http://www.w3schools.com?"<?php echo $_SESSION['name'];?>""></iframe>
please try this.

file_get_contents not returning entire webpage

I've been trying to retrieve the contents of a webpage (http://3sk.tv) using file_get_contents. Unfortunately, the resulting output is missing many elements (images, formating, styling, etc...), and just basically looks nothing like the original page I'm trying to retrieve.
This has never happened before with any other URLs I have tried retrieve using this same method, but for some reason, this particular URL (http://3sk.tv) refuses to work properly.
The code I'm using is:
<?php
$homepage = file_get_contents('http://3sk.tv');
echo $homepage;
?>
Am I missing anything? All suggestions on how to get this working properly would be greatly appreciated. Thank you all for your time and consideration.
Thats normal behaviour, as you are only grabbing the file, and not related images, stylesheets etc...
I have one quick workaround to fix relative paths
http://www.w3schools.com/tags/tag_base.asp
Just add to your code <base> tag.
<?php
$homepage = file_get_contents('http://3sk.tv');
echo str_replace(
'<head>',
'<head><base href="http://3sk.tv" target="_blank">',
$homepage
);
?>
It's should help.
This is to be expected. If you look at the source code, you'll notice many places which do not have a full URL (ex lib/dropdown/dropdown.css). This tells the browser to assume http://3sk.tv/lib/dropdown/dropdown.css. However, on your website, it will be YOURURL.COM/lib/dropdown/dropdown.css, which does not exist. This will be the case for much of the content.
So, you can't just print another website's source and expect it to work. It needs to be the same URL.
The best way to embed another website is usually to just use an iframe or some alternative.
The webpage is not completely generated server-side, but it relies heavily on JavaScript after the HTML part loads. If you are looking for rendering the page as it looks in browser, you may need a headless browser instead - see e.g. this binding to PhantomJS: http://jonnnnyw.github.io/php-phantomjs/

Trying php to reload page

I am trying to use an image as a button to refresh pages on a website. The footer (a php include) is currently using this code to refresh each page:
<img src="/images/refresh.png">
which of course works. BUT I would like to improve it. Essentially, it would be something like this:
onClick="javascript: window.location.href='abcd.html';"
BUT I need it to work dynamically because I'm using php pages. So I was thinking this would work:
<img src="/images/refresh.png">
But it doesn't work. Any ideas? I'm using <? php $_SERVER['REQUEST_URI'] ?> wrong (obviously), so, any ideas for assistance? Thank you for any help!
Problem noticed is you have a space between <? and php in the following line:
<img src="/images/refresh.png">
Also you want to echo out the value for $_SERVER['REQUEST_URI']. You are just calling $_SERVER['REQUEST_URI']. Also as #NickCoons pointed out when using the echo construct you need to add a semi-colon i.e. echo $_SERVER['REQUEST_URI'];.
Try the following:
<img src="/images/refresh.png">

PHP + Smarty: Parse PHP+HTML into a String?

I am using PHP in combination with Smarty Templates to generate pages serverside. Currently, I am loading a page as follows:
$smarty->assign('app', file_get_contents("some_content.php"));
Where some content contains HTML with PHP tags and code inside those tags.
I would like the PHP content inside this file within the current scope (That of the script reading the file), so that a particular function I've defined is available. How would I go about doing so? All the information I can find is regarding the eval(...) function, which doesn't seem to be able to cope with the HTML/PHP mixture: would I need to perform a find/eval/replace operation to achieve the desired result, or is there a more elegant way of doing this?
From my opinion, this short snippet of the code you posted shows that something is generally wrong there :)
But nevertheless you can achieve whatever you are trying to achieve by doing the following:
ob_start();
include("some_content.php");
$result = ob_get_clean();
$smarty->assign('app', $result);
Ich, I'm such a dummkopf. There is an answer right on the PHP manual for eval, right under my nose. Here is the answer I neglected to notice.
You can use {literal}...{/literal} smarty tags to display any content in smarty templates as is. It used to transfer java scripts and other specific content.

Categories