Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a function to show current date and time using date() function in php.
I used
meta http-equiv="refresh" content="30" to refresh the whole page.
But i want to refresh only that specific function part as i want to change the time every minute. Is it possible?
In short, no it is not possible with just PHP and HTML.
Once your page has been generated by your PHP script, it is sent to the client and cannot be modified anymore. HTML is made to build "static" web pages, that mean they won't produce fancy moving things and therefore they won't update content once the page is loaded.
But even if you cannot send the page a second time once it has been generated by PHP, you're not bound to HTML in the page. You can set up script in the page that will for example make the client browser perform a request to your server to update part of the page. That's called AJAX, and to do it you have to learn Javascript.
You should use client-side magic for this, so I'd use AJAX techniques.
setInterval(function(){
$("#time").load("page.php #time");
}, 30000);
Justin E asks, you can actually load a specific element from a page. Yes you can.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to know if it is possible with PHP to make action only happen once.
I have a script where users click an image and gain points for clicking it, but I would like to make it so that if they click again it won't add points anymore for a certain amount of time, or an advertisement would disappear from the site for that particular user.
Is this possible?
Store it in the database.
When they click on the image, run a query that changes the is_clicked column (for instance) to clicked or 1 or whatever you like.
Retrieve the image in such a way that, if the is_clicked column is changed to clicked for a particular user, then don't allow any clicks.
For example :
if($row['is_clicked'] != 'clicked']){
echo '<img>....</img>';
}
It is possible but with PHP, it can get pretty messy. I would suggest you use JS (Javascript). Create a simple function in JS and then use the onclick attribute in the the button element to execute. Like this:-
<script>
document.getElementById('id of the button').onclick='myFunc';
function myfunc(){
document.getElementById('id of the button').style.display="block";
}
</script>
Front end, html:
<button id="id of the button">Click here!</button>
Now if you want to make sure a person who clicks button from a computer shouldn't be able to click it again, then you should set up a cookie using php which will retrieve data about its computer and prevent the computer from using this button
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any way to add php code for updating automatically the seconds in time format without using javascript.
Thanks
Do you mean you want to update a time value in rendered HTML that was produced by PHP?
The only way is to continually reload the page using some HTML reloading tag that I can't (and don't want to) remember every second to show the updated time. Don't do it please, it's annoying to users. Use JavaScript or just don't do it.
Try meta tag in html
<meta http-equiv="refresh" content="1;url=your_url">
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
here is an example, say every item in each list was clicked on http://katproxy.com/the-big-bang-theory-tv8511/, how would you proceed to get the source code of the modified web page using php considering the fact that the url has not changed (file_get_contents is probably out of the question).
Thank you!
Using PHP? You can't, not without fetching the page source and evaluating its JavaScript, which is obviously quite impractical.
The "page" hasn't change, only your in-browser representation of the DOM has been modified. You would need PHP to talk to your browser, and ask for the state of its DOM, not the remote server, which cannot possibly serve up the HTML representation of your browser's current DOM.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want $counter=$counter +1, when this link on my website is clicked:
<img src="images/old.jpg" width="190" height="32" />
I've tried $counter++; in several creative ways, none of which seem to have worked.
PHP is a server-side language.
This means that PHP is (most often) only responsible from
When the server receives a request
until
The PHP program outputs the page.
So if you want something to happen in response to your action AFTER the page is loaded (e.g. clicking a link), PHP cannot handle that.
Now, you should choose your implementation in either Javascript or PHP depending on what you want to achieve.
If you want to store the counter value in your server, and increment it:
Set the destination of the link to the exactly same page as the one you are viewing now. Use $_SESSION to store a value, and it will be stored across multiple requests.
If you want to see the value of the counter go up as you click on the link:
Use Javascript to store the counter as an variable, and increment it on each click. This will be reset if you refresh the page.
Note: You cannot achieve neither of this if your link takes you to another page. That becomes a whole new story.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the problem this code:
$window_width= '<script>screen.availWidth</script>';
$window_height= '<script>screen.availHeight</script>';
any idea?
Nothing wrong in your code, but you can't get any values in PHP variable, because PHP is Server side scripting language.
You need JavaScript, not PHP.
var screenWidth = window.screen.width,
var screenHeight = window.screen.height;
You can then send it to the server via Ajax (with an XmlHttpRequest).
You seem to be misunderstanding the basic concepts of how PHP and HTML/JavaScript works together. PHP is a server-side language and JavaScript is a client-side language.
PHP generates the output first and then it's transferred to the client where it's being executed. You're trying to do it the other way around.
What you need to do is first, generate a page using PHP, have it sent to the client for client-side execution, and from there have JavaScript perform a call that sends the information back to PHP using a GET/POST request.