remove background color using pure php - php

I want to remove this background color after 10 seconds using php. I don't want to use js, css. Is it possible to remove background color using pure php code?
<?php $running_location = '<p style="background:#E1FEE0;"></p>' ?>;

PHP runs on the server. All the work it does is finished before the browser receives the page.
Server side code cannot alter the page on the client after the page has been delivered.
You have to use a client side technology for this. Sensible approaches would be CSS animations or JavaScript. (NB: I'm assuming CSS animations can do this, I haven't used them enough to be sure).
Less sensible options would be to use a refresh either via HTML meta or HTTP to load an entirely new page from the server (which is identical but without the background colour).

Related

PHP If statement on browser width w/bootstrap

Ok So I am making a 2.0 version of a my website and completely re-designing the layout I have brought in bootstrap because what I mainly want to do is make the website mobile friendly so basically what I'm trying to do is something along the lines of this and done in php
if(browser-width < 600px && browser-width > 100px) {
<div class="mobileHeader">stuff here</div>;
}elseif(browser-width > 700px) {
<div class="sidebar">stuff here</div>;
};
I hope this makes sense I have been trying to figure this out for awhile to no avail.
You can't access browser width (or any other user properties) with PHP. The only thing possible would be to set the width in a cookie (with JS) and then read it with PHP. However, this works only on the second request, as PHP gets executed before JS.
I do suggest you read something about responsive webdesign and you might find out you don't actually need this.
You cannot know the browser-width in php. You have to do this with javascript. Also even if php had this result, it is static, so what if you resized the window? Php wouldn't detect that. In my opinion you are choosing the wrong tools for your task.
Source to prove my point
The browsers don't report chrome width on the request. So PHP will never know that. You will need to do that with CSS media queries or with JavaScript.

Save HTML Canvas as an image without client browser

I generate an image on a few overlapping canvases when a page is loaded (without user-interaction), but that does take ~3 seconds to fully draw. I want to flatten these canvases, and convert this image to a PNG on the server, for use in thumbnail previews.
Flattening to a single canvas (using ctx.drawImage(other_canvas,0,0)) and then ctx.toDataUrl() looks like exactly what I need. Is there a way do this on the server side without requiring a user's browser? Some kind of command-line javascript / canvas parser perhaps, which can load the page, wait for the canvas to finish rendering, then inject some javascript to flatten, call toDataUrl, resize and save the resulting image.
AJAX solutions which render and send the thumbnail back to the server won't work as I need the thumbnail before the first person has viewed the page. It also needs to be fast (hopefully only slightly longer than the time the canvas takes to render, 3 seconds). I can't wait for an external service like browsershots.
I looked at CutyCapt, but that renders the entire webpage, not just the canvas (and also doesn't seem to draw everything on my canvas for some reason).
You might want to take a look at Phantomjs:
https://github.com/ariya/phantomjs/wiki/Screen-Capture
This does a good job of rendering html content to a PNG, although this will also do the entire page. Perhaps you can wrap the canvas contents you are interested in in a separate page and then use phantomjs to turn it into a png.
PHP has various libraries for server-sided image generation which offer functionality which is similar to the HTML5 canvas.
Look into PhantomJS which is a command line version of the webkit browser and you can do cool things such as save the output of a rendered page in an image etc. AFAIK you can also inject javascript code which can give you more control when to take a screenshot with it.
http://phantomjs.org/

CSS and browser compatibility

There are many ways we can deal with CSS browser compatibility issue.
Such as using Box model design or developing different style sheets for different browsers or using Dynamic CSS techniques (writing PHP script in CSS file).
Is there any way that we can know that Style which is being executed in the browser is supported by that browser or not?
Can we write code something like below in dynamic CSS using PHP code. I mean is there any function or way to achieve this functionality.
FILENAME: styles.css.php
<?php
header("content-type: text/css");
// isStyleSupported() function will return true or false with respect to the browser it is being executed
if (isStyleSupported('min-width')) {
// styles here
} else {
// alternative style here
}
?>
I know it might be difficult to keep the record of different version of browsers with respect to its CSS support. But still curious, if anyone know any solution or alternative method?
You can't determine the browser of the client with a purely server side solution like PHP, since the server only sends information out and receives no feedback from the browser.
This sounds like a job for Javascript, where you'd check if a particular CSS style is supported by the client's browser..
Once you determine what styles the requesting browser supports, you can use AJAX and PHP to serve the correct styles. On the other hand, you could also use pure Javascript to serve the correct styles.
The advantage of using a Javascript function vs an AJAX triggered PHP function, to test for CSS style support, is that you can actually test the individual browser CSS support with JS instead of relying on some documentation of what styles are supported by what browsers, which you would have to do with a PHP function.
At any rate, you need Javascript to determine the browser being used.
I Googled for IE hack and found pages like CSS hacks which are relevent to your question: how to embed conditional processing within the CSS (not using PHP).

Create an image of a div?

I was wondering if it's possible to create an image of a div inside a page in php, jquery or javascript? Or even just a screenshot of the entire page (on my own server - not external)..
What I want to do is create an image of a graph (drawn in via jQuery) and pass it onto a PDF, as I can't seem to get the jQuery to display in the pdf..
Because of the security risks, it is not possible to get Javascript to make a screenshot of a web page. This would allow you to steal credit card info, etc... You can use an active X control or something like that, but the client has to knowingly install it in order for things to work.
In PHP, you can create an image and place it on a web page, but again, you cannot see what is on the client's screen. It has to be done on the server before it is sent to the client.
Here is an example of a library you can use to draw a graph in PHP. http://www.aditus.nu/jpgraph/
You might be able to mimic what jQuery is doing in your script but it will take a shift in your applications design.
Take a look at this article:
http://www.developerfusion.com/code/181/capture-screenshot/
It's not client-side code, but you mentioned PHP so maybe server-side code is an option. I don't think you can do it client-side...
How about using a server side graph generator, for example for PHP? Maybe the transition hurts but you'd get a really stable and simple solution.
If you describe what kind of charts you exactly generate and what server side options you have, I'm sure you'll get some specific hints.
Your best bet is to use the GD library on the server to generate the graph as needed. There's no practical way to screencap the browser canvas. Check out this PHP graphing library, it may be what you're looking for:
http://graphpite.sourceforge.net/
If you run into problems where you're doing processing on the client-side that don't exist on the server (i.e.: summing up rows or taking in user settings from cookies), maybe you need to consider passing that data back to the server and letting your hosting handle it (after all, that's why you run a server with lots of RAM and a big CPU, to crunch numbers).
If your javascript draws the graph on a canvas, you can serialize the canvas and then send it to the server using POST.
I don't know if jquery can draw the graph on a canvas, but if the graph is a simple one you could probably code it yourself as canvas has drawing tools already.
Obviously, this only works with browsers supporting canvas.

Is there a way to adjust a web pages height with PHP to adjust with a browser?

Is there a way that you can use PHP to automatically fit a web page into the size of the browsers window?
Not with PHP, but with Javascript or CSS you can.
PHP is server-side technology.
JavaScript and CSS are client-side technologies.
Even with javascript it's often buggy. It's very difficult to take thinks like horizontal taskbars into account. Javascript may find the window to be 500px in height and with the stuff that the user is running it's only 300 or so. Additionally, if someone has Javascript or css turned off, it ruins everything. Best bet is to design in a way that all browsers can deal with it. Make clean compliant designs and let users mess with it if they want to.
Using PHP or server-code more or less to change HTML/CSS elements wouldn't be optimal. You would want to use HTML and CSS directly. If that doesn't work, your absolute last option might be JavaScript but that's not best practice.

Categories