How do I activate stages of php, for example the user opens the php file. And before starting the script they are asked "are you sure you want to continue". With a button below staying activate.
I have already looked around and I'm sure there is a way to do it but I don't know what it is called. Could someone help me out?
.Short way to do that:
if($_GET['execute'] == 'yeah') {
// your php-file-content goes here....
// ....
} else {
echo 'Are you sure you want to execute this file?'.PHP_EOL;
}
Just put your filecontent between the IF part. It wont be executed untill the request ist yourfilename.php?execute=yeah
Related
Can anyone tell me the right way to do this. I want a pop up first, then the script to stop, but when I run this, the exit just overrides the pop up?
if (HandOverNotesModifiedTime > $datetime_from)
{
echo "<script type='text/javascript'>alert('WARNING: Notes have not been updated!');<script>";
exit(header('Location:/handoverTESTING.html');
}
I tried without the exit, just to make sure the pop up works, and it does.
You can use like this :
if (HandOverNotesModifiedTime > $datetime_from)
{
echo "<script type='text/javascript'>alert('WARNING: Notes have not been updated!');</script>";
echo "<script>window.location.assign('/handoverTESTING.html');</script>";
}
Page redirection reason :
Popups are created on the client side, and the header redirection takes place on the server side.
PHP is executed at the server side. It renders HTML,Styles and sends it to the browser then browser execute the javascript codes
i have a problem using glass button callback query in telegram bot.that is that user can click more than one time and program failed because my program is step by step running and when click another time program goes to next step.
even when i delete callback message user can click more than one time
can you help me solve it?
how can i disable that?
<?php
else if(isset($arrayMessage['callback_query'])){
.
.
do some thing
.
.
.
}
?>
When you receive the callback_query, simply use editMessageReplyMarkup method and don't pass or pass blank string to reply_markup parameter
Simply set a flag that allows the user to click by default, and then craft a conditional that checks against this flag. Inside of the conditional, run the intended click behaviour, and then set the flag to false.
This can be seen in the following:
<?php
$can_click = true;
if ($can_click) {
// Do stuff
$can_click = false;
}
However, note that clicking is done client-side, so in order to disable clicking on an element, you're probably looking to make use of JavaScript instead of PHP (unless you're using something like AJAX to call the PHP script).
This would be done by crafting a function that is called on button click, and checking against a global flag, as can be seen in the following:
var button = document.getElementById('click');
var can_click = true;
function clicked() {
if (can_click) {
console.log('This will only trigger once');
can_click = false;
}
}
<button id="click" onclick="clicked()">Click</button>
Hope this helps! :)
I have no idea how this is happening and have never seen it happen before.
In the code below, the code prints out 'oops --- ' yet it runs the function somehow. I dont get how both the if and the else run, genuinely confused. I can provide the code in the classes if needed.
if($functions->checkDBstats($_GET['name'])) {
$functions->update($_GET['name'],$functions->getPlayerInfo($_GET['name']));
echo "Your account has been updated! Visit your page <a href='/osrstracker/name/". $_GET['name'] ."'>here</a>";
} else {
echo "Oops, either you havess already updated your account within the past 12 hours or we have messed something up!";
}
Another thing I tested was adding a print_r to the $functions->update to debug it yet it doesnt print but the update function runs!! I have no idea whats going on =/ Anyone that can help ?
I want to update a page when my database is modified. I want to use jquery for doing this. Question not clear? Then have a look at this, Suppose this is my page:
<?php
$query=mysql_query("select * from tbl1 where user='admin'");
if(mysql_num_rows?($query)!=0)
{
echo 'Table 1 has values';
} else {
echo 'Table1 is empty';
}
?>
This action should be performed whenever any new entry is added to the database. Now suppose I add an entry to the database manually then the page should automatically show the result as "Table1 has values". I know it can be used by using refresh page periodically but I don't want to use it. Instead I want to try something other, like ajax polling? Can someone give me a demo?
You can use long polling, but do a lot of research first. Your server may kill the request that appears to be open for a long amount of time.
In PHP, your code will look something like...
set_time_limit(0);
while (TRUE) {
// Query database here
if ($results) {
echo json_encode($results);
exit;
}
sleep(1);
}
You can use Ajax jQuery Framework with Ajax:
http://www.w3schools.com/Ajax/default.asp
http://api.jquery.com/jQuery.ajax/
It will call the server side script Asynchronously and update your page accordingly. You can use jQuery to specify the format of the update also.
You are looking for Ajax-Push/Comet solutions. These aren't trivial.
You also mentioned ajax pooling.
Well, on the server side you need to loop until you have a timeout (that you defined yourself or the server did, make sure you return the HTTP status code for Timeout Occured) or the request can be satisfied.
And on the client side whenever you complete the operation successfully just handle it and than make the same ajax call again, if you timed out just make the same ajax request again until it's satisfied.
I have a javascript setInterval that checks an external page every 5 seconds for mail, I am finding sometimes that if I login or click a form submit at the same time as the request goes out, I sometimes find myself looking at a Y or a N (what my JS was to intercept) instead of the real link I wanted to go to.
How does one debug this? I am using firefox with firebug, my app is using PHP with javascript.
EDIT: it's almost as if the onComplete is being missed by java, and it just dumps it as the user is signing in.... it only happens when someone is changing pages and the java is running at the same time.
EDIT 2: If you want to see this for yourself, you'll need visit my site and create an account and go through the signup process (2-3 mins to do tops), the website is http://mikesandmegs.com and the beta password is goldfish. What you want to do is login just as the check mail sends its request off. Its like I need to cancel something or tell java to throw the callback out or something. You should see the requests every 5 seconds, (well it adds 5 seconds each request) but you'll see. It may take a couple try's or some luck, but it is reproducible.
This is the javascript that is running (i think I have it all posted) If I seem to be missing anything, let me know. I also posted an htnl input html that the javascript checks...
<input id="hasMail" type="hidden" value="y">
<script type='text/javascript'>
mailTimer = setInterval("checkMail();", 10000);
function checkMail()
{
// should we check the mail now?
if ($('hasMail').value == "y")
{
// remove mail new mail alert (mail-check.php returns y or n
new Ajax.Request('mail-check.php',
{
method: 'post',
postBody: '',
onComplete: checkMailNotify
});
}
}
function checkMailNotify(req)
{
if (req.responseText.length > 5)
{
$('hasMail').value = "n";
clearInterval (mailTimer);
return;
}
if (req.responseText == "y")
{
$('hasMail').value = "n";
$('topMessage').update('You have new mail...');
$('alertBox').appear();
clearInterval (mailTimer);
}
else
{
clearInterval (mailTimer);
mailInterval = mailInterval + 5000;
mailTimer = setInterval("checkMail();", mailInterval);
}
}
</script>
I know this is nowhere near a solution, but it WILL help to increase the 5 second interval, even to something like 30 seconds. I've done work with mailservers before, and we often came across problems where people would have e.g their iphone as well as their desktop mail client ping the server at very short intervals. This would result in confusing (to them) failures because of locks.
So yeah, 5 seconds for messages is very quick (it doesn't look like chat but rather just messages, is that right?). At best if you do that then the problem will happen a lot less if it all. You will however have the horrible knowledge that it can happen.
Please don't take this as an attempt at a solution to your problem. just a suggestion.
I think what's happening is that while changing pages, the data from the mail-check.php is clashing with the new request that is coming back from the network at the same time. I think a possible solution is to disable the setInterval whenever you change a page or submit a form, then re-enable it after loading the new data.
Something like:
<input type="button" onClick="clearInterval('mailTimer'); this.submit()" />
...