David Ehmer
Jun 10 2005, 11:59 AM
This page (www.smilelearning.com.au/freeresources.php) displays a form which
accepts an email address as input. If completed and submitted, entry is
authorised to a links page, a cookie is sent to the users machine and an
email is sent to the site owner with the email address provided.
When returning to this page the user shouldn't see the form requesting their
email address (as they have already provided it), just a link which will
take them to the 'links' page.
Currently the page behaves correctly except that it always displays the
email input form. If I use the code block below the page correctly checks
for a cookie and processes the page as intended.
Unfortunately the form to email script actioned when the form is submitted
wont work now. (it should send the value of 'email' to a specified address).
The script hasn't been modified, just the PHP code that determines whether
to display the login form or not.
<h1>Free resources</h1>
<?
if (isset($_COOKIE['email'])) {
?>
<ul><li><a href="#">Access free resources</a></li></ul>
<?
} elseif ($_GET['checkit']) {
echo "<ul><li><a href="#">Access free resources</a></li></ul>";
}
else {
?>
<p>Please enter your email address below to access the free SMILE
resources.</p>
<form name="emailaddress" id="emailaddress" title="Email address"
onsubmit="return formvalidation();" method="post" action="<? echo
$_SERVER['cgi-bin/formtomailscript2.cgi']; ?>">
<table id="emailtable">
<tr>
<td class="input">
<input name="email" id="email" type="text" size="23" /></td>
</tr>
<tr>
<td>
<div align="center">
<input name="submit" id="submit" type="submit" value="submit" />
</div>
</td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
<!--
document.getElementById('email').focus();
// -->
</script>
If I remove:
<? echo $_SERVER['cgi-bin/formtomailscript2.cgi']; ?>
and replace it with:
"cgi-bin/formtomailscript2.cgi"
then the script executes and sends of the email to the specified account,
but doesn't recognise the cookie, so the form is displayed each time the
page loads. (as is currently implemented on the live site)
However if I use the $_SERVER approach the cookie aspect works fine but the
form to email script doesn't execute.
How can I get the form to email script working and the page checking for a
cookie as well rather than one or the other?
Appreciate any suggestions as the solution for this has proven very elusive.
David
Xenophaw
Jun 11 2005, 11:46 AM
"David Ehmer" <[Email Removed]> wrote
QUOTE |
This page (www.smilelearning.com.au/freeresources.php) displays a form which accepts an email address as input. If completed and submitted, entry is authorised to a links page, a cookie is sent to the users machine and an email is sent to the site owner with the email address provided.
When returning to this page the user shouldn't see the form requesting their email address (as they have already provided it), just a link which will take them to the 'links' page.
Currently the page behaves correctly except that it always displays the email input form. If I use the code block below the page correctly checks for a cookie and processes the page as intended.
Unfortunately the form to email script actioned when the form is submitted wont work now. (it should send the value of 'email' to a specified address). The script hasn't been modified, just the PHP code that determines whether to display the login form or not.
<h1>Free resources</h1
<? if (isset($_COOKIE['email'])) { ? <ul><li><a href="#">Access free resources</a></li></ul <? } elseif ($_GET['checkit']) { echo "<ul><li><a href="#">Access free resources</a></li></ul>"; } else { ?
<p>Please enter your email address below to access the free SMILE resources.</p
<form name="emailaddress" id="emailaddress" title="Email address" onsubmit="return formvalidation();" method="post" action="<? echo $_SERVER['cgi-bin/formtomailscript2.cgi']; ?>"
<table id="emailtable" <tr <td class="input" <input name="email" id="email" type="text" size="23" /></td </tr <tr <td <div align="center" <input name="submit" id="submit" type="submit" value="submit" / </div </td </tr </table
</form <script language="JavaScript" type="text/javascript" <!-- document.getElementById('email').focus(); // -- </script
If I remove:
<? echo $_SERVER['cgi-bin/formtomailscript2.cgi']; ?
and replace it with:
"cgi-bin/formtomailscript2.cgi"
then the script executes and sends of the email to the specified account, but doesn't recognise the cookie, so the form is displayed each time the page loads. (as is currently implemented on the live site)
However if I use the $_SERVER approach the cookie aspect works fine but the form to email script doesn't execute.
|
There isn't a entry named 'cgi-bin/formtomailscript2.cgi' in the array
$_SERVER, so I would guess it could not work.
$_SERVER is just a predefined variable which can be used without to declare
it and which contains information such as headers, paths, and script
locations. An example of the keys it contains is:
$_SERVER["DOCUMENT_ROOT"]
$_SERVER["HTTP_ACCEPT"]
$_SERVER["HTTP_ACCEPT_LANGUAGE"]
$_SERVER["HTTP_CONNECTION"]
$_SERVER["HTTP_HOST"]
$_SERVER["HTTP_USER_AGENT"]
$_SERVER["HTTP_XXXXXXXXXXXXXXX"]
$_SERVER["PATH"]
$_SERVER["REMOTE_ADDR"]
$_SERVER["REMOTE_PORT"]
$_SERVER["SCRIPT_FILENAME"]
$_SERVER["SERVER_ADDR"]
$_SERVER["SERVER_ADMIN"]
$_SERVER["SERVER_NAME"]
$_SERVER["SERVER_PORT"]
$_SERVER["SERVER_SIGNATURE"]
$_SERVER["SERVER_SOFTWARE"]
$_SERVER["GATEWAY_INTERFACE"]
$_SERVER["SERVER_PROTOCOL"]
$_SERVER["REQUEST_METHOD"]
$_SERVER["QUERY_STRING"]
$_SERVER["REQUEST_URI"]
$_SERVER["SCRIPT_NAME"]
$_SERVER["PATH_TRANSLATED"]
$_SERVER["PHP_SELF"]
There would be 2 more keys, in the case the connection is using the https
protocol. None of them will translate a filename to the real path on the
server, but you have to know it. In your case, you could put
action='http://www.smilelearning.com.au/cgi-bin/formtomailscript2.cgi' or
action='/cgi-bin/formtomailscript2.cgi', using a relative path.
QUOTE |
How can I get the form to email script working and the page checking for a cookie as well rather than one or the other?
Appreciate any suggestions as the solution for this has proven very elusive.
David
|