我有php脚本,负责取消订阅时事通讯用户。请查看以下内容:
<?php
session_start();
$without_login = 1;
include("includes/config.inc.php");
if(!(isset($_REQUEST['email']) && $_REQUEST['email'] != ''))
{
header("location:".$basehref);
exit(0);
}
$meta_title = 'Unsubscribe - '.store_company_name;
$meta_desc = '';
$meta_keyword = '';
include("header.php");
?>
<div class="content" itemscope itemtype="http://schema.org/WebPage">
<div class="pnav" itemprop="breadcrumb"><a href="<?php echo $basehref;?>" title="Home">Home</a> » <span id="on1">Unsubscribe From Mailing List</span></div>
<section>
<div class="about">
<h1 itemprop="about">Unsubscribe From Mailing List</h1>
<hr>
<div itemprop="description" id="static_desc">
<form action="" method="post" name="form">
<input type="hidden" name="unsubscribe_email" id="unsubscribe_email" value="<?php echo mysql_real_escape_string($_REQUEST['email']);?>" />
<div class="story_left" style="min-height:200px;"><br />
<?php
$error = 0;
$to = $_REQUEST['email'];
$encrypt_email = decode5t($to);
if($encrypt_email != '')
{
$check_url = mysql_query("select * from tb_member where `email` = '".$encrypt_email."' and newsletter = 1");
if(mysql_num_rows($check_url) > 0)
{
$error = 1;
}
if($error == 0)
{
$check_url = mysql_query("select * from news_letters where `email` = '".$encrypt_email."'");
if(mysql_num_rows($check_url) > 0)
{
$error = 1;
}
}
}
if($error == 0)
{
echo 'The unsubscribe link you have clicked is invalid. <br> <br /> <input type="button" onclick="window.location=\''.$basehref.'\';" value="Continue" title="Continue" style="float:left; margin-left:250px;" class="choose-btn1" name="submit" />';
}
else
{
?>
Please confirm your unsubscribe request from <?php echo store_company_name;?> newsletters by clicking on the "Unsubscribe" button below to remove your email address.<br /><br />
<input type="button" class="ungo-btn choose-btn1" title="Unsubscribe" value="Unsubscribe" name="submit" style="float:left; margin-right:20px;" />
<input type="button" onclick="window.location='<?php echo $basehref;?>';" value="Cancel" title="Cancel" style="float:left;" class="choose-btn1" name="cancel" />
<?php
}
?>
</div>
</form>
</div>
</div>
</section>
<div class="clear"></div>
</div>
<?php
include("footer.php");
?>
有人可以建议如何将命令放入链接以启动取消订阅用户吗?我使用下面的一个但没有成功。
<a href='http://www.xyz.co.uk/unsubscribe.php?email=$_REQUEST['email']'>UNSUBSCRIBE HERE</a>
答案 0 :(得分:1)
我认为您的脚本不会取消订阅用户,因为没有更新数据库的mysql查询。
以下代码表明用户需要单击“提交”按钮来处理数据,在您的情况下是取消订阅用户。
<input type="button" class="ungo-btn choose-btn1" title="Unsubscribe"
value="Unsubscribe" name="submit" style="float:left; margin-right:20px;" />
但是,即使在用户单击“提交”按钮后,我也不确定数据的发送位置,因为表单操作为“”,请参阅以下内容:
<form action="" method="post" name="form">
假设newsletter = 1表示用户订阅了简报,以下是脚本的简单示例 更新数据库并设置newsletter = 0(unsub newsletter)
$to = $_REQUEST['email'];
$encrypt_email = decode5t($to);
if($encrypt_email != '')
{
$check_url = mysql_query("select * from tb_member where `email` = '$encrypt_email' and newsletter = 1");
if(mysql_num_rows($check_url) > 0)
{
mysql_query("UPDATE tb_member set newsletter = '0' where `email` = '$encrypt_email' and newsletter = 1");
$error = 1;
}
if($error == 0)
{
$check_url = mysql_query("select * from news_letters where `email` = '$encrypt_email'");
if(mysql_num_rows($check_url) > 0)
{
mysql_query("UPDATE tb_member set newsletter = '0' where `email` = '$encrypt_email'");
$error = 1;
}
}
}
if($error == 0)
{
echo "The unsubscribe link you have clicked is invalid";
}