Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How PHP file gets executed from CSS

i have a simple question:
I am currently making a captcha validation form for my website and I followed a tutorial
where i see that to generate an image in the captcha format, style.css calls a php file like this:

.captcha-input {
    background: #FFF url(./../../captchaImageSource.php) repeat-y left center;
    padding-left: 80px;
}

When I take a look at the captchaImageSource.php file i see this

<?php
namespace MyNameSpace;
use MyNameSpace\Captcha;

session_start();

include("./Model/Captcha.php");
$captcha = new Captcha();

$captcha_code = $captcha->getCaptchaCode(6);

$captcha->setSession('captcha_code', $captcha_code);

$imageData = $captcha->createCaptchaImage($captcha_code);

$captcha->renderCaptchaImage($imageData);

?>

The captcha.php file has the related validation functions like createcaptchaImage etc.
So I see the php file kind of generates an image of the captcha, but I dont understand why it gets even executed. Does CSS trigger the php file? And then does the php call the related functions by itself?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, if you put a URL in the background rule in CSS it causes the browser to send a HTTP request to that URL – you could see it in the Network tool in your browser’s Developer Tools.

And in this case that means that the webserver will execute the php code found in the file at that URL.

The browser will then try to use the data output from the script as an image.

Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/background

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading