Solved

I need any user to submit a form and dont show it to anyone else after being submitted

Posted on 2006-10-25
5
169 Views
Last Modified: 2012-05-05
I have a page that shows up as an error page on my website  if the db cant connect.

I added the following to the page. This provides a form to a user to alert the admin that the site is down (works with sms) I will place a notice like" you are the first to see this erorror please advise the site admin"  

Then once theyve submitted it to me I dont want it to show up to anyone else.

I was thinking on the form submit to set a variable to 1 and later check the variable if its 1 I will not show the form code otherwise I will.

I have no clue as to how to make this work any thoughts Do I simply

define $count as global

then set
 
$count = 1; in the code that transmits the sms? Will this hold that variable no matter how many times the page is loaded?

Thanks



<form method="POST" action="<?php echo $PHP_SELF; ?>">
Number:<br />
<input type="text" name="number" maxlength="10" class="inputbox"><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type="text" name="subject" maxlength="20" class="inputbox"><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name="message" rows="10" cols="15" class="inputbox"></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type="submit" name="do" value="Send" class="button">
</form>
0
Comment
Question by:Roba122
  • 2
5 Comments
 
LVL 4

Expert Comment

by:anilande
ID: 17809800
if u want to retain a value after submitting the form use
$_SESSION['hit']=1;

this value will be retained in the server/session until the session is not destroyed.

to know about details about sessions visit this link

http://in.php.net/session
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17810639
you could write your data to a text file on the server, so that the solution is independant of any sessions for example.  You should make sure that you have the proper write/execute permissions on the server.  If you prefer, instead of posting form data to $_SERVER[PHP_SELF], you could post form data to a file in a section of your server that is not accessable from the web, this will remove any dangers of setting write permissions to web accessible folders.

in your section for handling the sms sending, you need to add the following code prior to the sms sending, which will write a small text file in the same directory as the script.  By writing the data in a php format, we can use it later if you want to make your script more advanced (reset button?)

<?php
$your_data = "$smssent=1";
// Open the file and erase the contents if any
$fp = fopen("smssent.php", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>

You then need to use the following code on your main error page, which will decide whether or not to show your form, based on whether or not the file exists.  If you want to add reset scripts etc, you can always check the data that is held in the "$smssent" variable instead.

<?php
$filename='smssent.php'

if (file_exists($filename)) {
   //Nothing needs to be done, we don't want to show the form
}
else {
echo "<form method='POST' action='$PHP_SELF'>
Number:<br />
<input type='text' name='number' maxlength='10' class='inputbox'><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type='text' name='subject' maxlength='20' class='inputbox'><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name='message' rows='10' cols='15' class='inputbox'></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type='submit' name='do' value='Send' class='button'>
</form>"
}
?>
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 500 total points
ID: 17810715
There was an error in my last post, please find proper code below!!


you could write your data to a text file on the server, so that the solution is independant of any sessions for example.  You should make sure that you have the proper write/execute permissions on the server.  If you prefer, instead of posting form data to $_SERVER[PHP_SELF], you could post form data to a file in a section of your server that is not accessable from the web, this will remove any dangers of setting write permissions to web accessible folders.

in your section for handling the sms sending, you need to add the following code prior to the sms sending, which will write a small text file in the same directory as the script.  By writing the data in a php format, we can use it later if you want to make your script more advanced (reset button?)

<?php
$your_data = "$smssent=1";
// Open the file and erase the contents if any
$fp = fopen("smssent.php", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>

You then need to use the following code on your main error page, which will decide whether or not to show your form, based on whether or not the file exists.  If you want to add reset scripts etc, you can always check the data that is held in the "$smssent" variable instead.

<?php
$filename='smssent.php';

if (file_exists($filename)) {
   //Nothing needs to be done, we don't want to show the form
}
else {
echo "<form method='POST' action='$PHP_SELF'>
Number:<br />
<input type='text' name='number' maxlength='10' class='inputbox'><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type='text' name='subject' maxlength='20' class='inputbox'><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name='message' rows='10' cols='15' class='inputbox'></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type='submit' name='do' value='Send' class='button'>
</form>";
}
?>
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now