PHP - Flag file
PHP - Flag file
I am trying to set a file on the server that will serve as a toggle for a certain function. The code below used to work, but no it does not.
The Pop up message comes up OK from Confirm(), upon clicking OK, it gets into the if(r) but the PHP code is not executed.
Hope somebody can see what is wrong here...
Thanks
<script type= text/javascript>
function renameFile()
{
var r = confirm("Are you sure you want to do this?");
if(r)
{
<?php
$disable = "notyet.txt";
if (is_file($disable))
{
rename("notyet.txt","allowed.txt");
}
else
{
rename("allowed.txt","notyet.txt");
}
?>
}
}
</script>
The Pop up message comes up OK from Confirm(), upon clicking OK, it gets into the if(r) but the PHP code is not executed.
Hope somebody can see what is wrong here...
Thanks
<script type= text/javascript>
function renameFile()
{
var r = confirm("Are you sure you want to do this?");
if(r)
{
<?php
$disable = "notyet.txt";
if (is_file($disable))
{
rename("notyet.txt","allowed.txt");
}
else
{
rename("allowed.txt","notyet.txt");
}
?>
}
}
</script>
Re: PHP - Flag file
I'm not an expert in Javascript nor PHP but I can't see how this would work.
I thought the PHP processor on the server processes the php code before passing it to the browser.
The browser would then process the Javascript.
So the php code testing if the file exists or not would be done irrespective of the javascript Confirm code.
I could be wrong here!
The other thing is that as it stands this idea only works if only one person uses the website as there is only one txt file.
Presumably you have taken this into account.
I thought the PHP processor on the server processes the php code before passing it to the browser.
The browser would then process the Javascript.
So the php code testing if the file exists or not would be done irrespective of the javascript Confirm code.
I could be wrong here!
The other thing is that as it stands this idea only works if only one person uses the website as there is only one txt file.
Presumably you have taken this into account.
Re: PHP - Flag file
I can see your point here.
The php code is executed irrespective...
This flag file is intended to allow or prevent members from a certain function.
The flag file is renamed by the administrator.
Any suggestion hkw else i can do that?
Is there a way to check for a file existance using javascript instead?
Thanks
The php code is executed irrespective...
This flag file is intended to allow or prevent members from a certain function.
The flag file is renamed by the administrator.
Any suggestion hkw else i can do that?
Is there a way to check for a file existance using javascript instead?
Thanks
- BaconFries
-
- Posts: 5365
- Joined: Thu Aug 16, 2007 7:32 pm
Re: PHP - Flag file
Just one result from "Google"
http://stackoverflow.com/questions/3646 ... javascript
Results
https://www.google.co.uk/search?q=check ... F-8#xxri=4
http://stackoverflow.com/questions/3646 ... javascript
Results
https://www.google.co.uk/search?q=check ... F-8#xxri=4
Re: PHP - Flag file
I suppose another thing to take into account is that some users may disable Javascript!
Re: PHP - Flag file
Thanks guys, I see that I need to explain again what I need to do here:
The Administrator is in charge to allow or deny a certain function (membership renewal) for members during the year. That function checks for a file "notyet.txt".
The function below is intended at providing the Admin to toggle this file to another name, or back when the time comes.
It is not only that it needs to check for file existence, but also to rename it when required. Below is my latest attempt at it, the Confirm() action is ignored and the function is executed irrespective.
Any other way to do this?
Cheers
<script type= text/javascript>
function reneameFile()
{
if(confirm("Are you sure you want to do this?"))
{
<?php
if (file_exists("notyet1.txt"))
{
rename("notyet1.txt","allowed.txt");
echo "<script type='text/javascript'>alert('Restriction Removed!');</script>";
}
else
{
rename("allowed.txt","notyet1.txt");
echo "<script type='text/javascript'>alert('Restriction Applied!');</script>";
}
?>
}
}
</script>
The Administrator is in charge to allow or deny a certain function (membership renewal) for members during the year. That function checks for a file "notyet.txt".
The function below is intended at providing the Admin to toggle this file to another name, or back when the time comes.
It is not only that it needs to check for file existence, but also to rename it when required. Below is my latest attempt at it, the Confirm() action is ignored and the function is executed irrespective.
Any other way to do this?
Cheers
<script type= text/javascript>
function reneameFile()
{
if(confirm("Are you sure you want to do this?"))
{
<?php
if (file_exists("notyet1.txt"))
{
rename("notyet1.txt","allowed.txt");
echo "<script type='text/javascript'>alert('Restriction Removed!');</script>";
}
else
{
rename("allowed.txt","notyet1.txt");
echo "<script type='text/javascript'>alert('Restriction Applied!');</script>";
}
?>
}
}
</script>
Re: PHP - Flag file
As I said I don't think you can mix php and javascript this way.
Did you look at BaconFries' suggested websites for Ajax etc.?
BTW it should be <script type="text/javascript"> with double quotes.
Did you look at BaconFries' suggested websites for Ajax etc.?
BTW it should be <script type="text/javascript"> with double quotes.
Re: PHP - Flag file
Hello again,
I never played with Ajax. He is pointing me to how to check for a file, but do I have an Ajax option also to rename the file like with PHP?
I have never used Ajax and don't know how to embed this into my HTML page.
Any help will be appreciated
Thanks
P.S - where are you in the world answering me at this time? I am in Melbourne, Australia
I never played with Ajax. He is pointing me to how to check for a file, but do I have an Ajax option also to rename the file like with PHP?
I have never used Ajax and don't know how to embed this into my HTML page.
Any help will be appreciated
Thanks
P.S - where are you in the world answering me at this time? I am in Melbourne, Australia
Re: PHP - Flag file
I am in the UK.
I think it can all be done using Ajax but unfortunately I also have never used Ajax in earnest.
I think it can all be done using Ajax but unfortunately I also have never used Ajax in earnest.
- BaconFries
-
- Posts: 5365
- Joined: Thu Aug 16, 2007 7:32 pm
Re: PHP - Flag file
I/He will answer this himself even if the time is UK 23:35 pm. You can use/insert any code including ajax into the programme using either the (mentioned frequently in the forum) HTML Object or in the Page HTML. With this It is generally understood though that if you wish is use PHP/javascript/Ajax etc then that you yourself have a understanding (or some) on how to use.He is pointing me to how to check for a file, but do I have an Ajax option also to rename the file like with PHP?
Now in no way am I saying that you cannot or are not allowed to ask for help or assistance with this and others are free to help if they wish to but if you do not get the answer you so wish then you will have to do research using "Google". One of my personal site reference I would recommend is http://www.stackoverflow.com/ signup required when posting try to give as much information as possible to get the best answer and always give a thanks to all that helped resolve your query.
Re: PHP - Flag file
Thanks guys,
I always appreciate any help and don't feel anybody owes me something.
I am a member on that stackoverflow site and posed a query there already
Cheers and good night UK
I always appreciate any help and don't feel anybody owes me something.
I am a member on that stackoverflow site and posed a query there already
Cheers and good night UK
Re: PHP - Flag file
Hello folks,
Well, while you were a sleep, I resolved my problem and wish to share it with you all. It is made of two parts
The JavaScript function - is like this, if the Admin selects OK, it loads a PHP script:
<script type= text/javascript>
function doit()
{
if(confirm("Are you sure you want to do this?"))
{
window.location.href = "rename.php";
}
else
{
alert("Cancelled");
}
}
</script>
And here is the PHP script
<?php
if (file_exists("notyet.txt"))
{
rename("notyet.txt","allowed.txt"); // It does the renaming and goes back to the calling page after showing an Alert box
echo "<script type=\"text/javascript\">window.alert('Restriction Removed!'); window.location.href = '/dataviewer.php';</script>";
exit;
}
else
{
rename("allowed.txt","notyet.txt"); // It does the renaming and goes back to the calling page after showing an Alert box
echo "<script type=\"text/javascript\">window.alert('Restriction Applied!'); window.location.href = '/dataviewer.php';</script>";
exit;
}
?>
Thanks for your help, hope someone else can use this
Cheers and good night from Down under
Well, while you were a sleep, I resolved my problem and wish to share it with you all. It is made of two parts
The JavaScript function - is like this, if the Admin selects OK, it loads a PHP script:
<script type= text/javascript>
function doit()
{
if(confirm("Are you sure you want to do this?"))
{
window.location.href = "rename.php";
}
else
{
alert("Cancelled");
}
}
</script>
And here is the PHP script
<?php
if (file_exists("notyet.txt"))
{
rename("notyet.txt","allowed.txt"); // It does the renaming and goes back to the calling page after showing an Alert box
echo "<script type=\"text/javascript\">window.alert('Restriction Removed!'); window.location.href = '/dataviewer.php';</script>";
exit;
}
else
{
rename("allowed.txt","notyet.txt"); // It does the renaming and goes back to the calling page after showing an Alert box
echo "<script type=\"text/javascript\">window.alert('Restriction Applied!'); window.location.href = '/dataviewer.php';</script>";
exit;
}
?>
Thanks for your help, hope someone else can use this
Cheers and good night from Down under
Re: PHP - Flag file
Thanks, well done.
Interesting way to do it.
Interesting way to do it.
Re: PHP - Flag file
Well WWBman,
It was your comment that PHP is executed on the server first before passing control to the browser that made me think up this idea
So, thank you!
And, you still didn't tell me where in the world you are...
Cheers
It was your comment that PHP is executed on the server first before passing control to the browser that made me think up this idea
So, thank you!
And, you still didn't tell me where in the world you are...
Cheers
- BaconFries
-
- Posts: 5365
- Joined: Thu Aug 16, 2007 7:32 pm
Re: PHP - Flag file
Thanks Baconfries,
Neither have I and this seems to work just fine as intended
Cheers
Neither have I and this seems to work just fine as intended
Cheers