douyun1852 2013-06-05 03:11
浏览 56

<?php echo htmlentities($ _ SERVER ['PHP_SELF']); ?>以形式返回index.php

I believe I've found the issue with my form using Firebug. Upon closer inspection my form action was being set to index.php when someone is on the homepage. I changed this to a simple / within firebug and it worked. My issue was that the form would work on some pages while it wouldn't on others. The action is being set at

<?php echo htmlentities($_SERVER['PHP_SELF']); ?>

within my code. How do I get it to appear as / only on the homepage rather than index.php. The site I'm referring to and page is the home page at 'link' if needed. The form in question is the newsletter form. While navigating to 'link' presents the correct address. The code is :

</div>
<div class="footer">
<div class="wideNewsletter">
<div class="wrapNewsletter">
<div class="newsletterIntro"><b>NEWSLETTER SIGN UP</b></div>
<div class="newsletterForm">
<?php/* var_dump($_SERVER) */?>
<?php
$name = "";
$email = "";
$msg_to_user = "";
if ($_POST['name'] != "") {

    include_once "connect_to_mysql.php";

    // Be sure to filter this data to deter SQL injection, filter before querying database
    $name = mysql_real_escape_string(strip_tags(trim($_POST['name'])));
    $email = mysql_real_escape_string(strip_tags(trim($_POST['email'])));

    $sql = mysql_query("SELECT * FROM newsletter WHERE email='$email'");
    $numRows = mysql_num_rows($sql);

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}


    if (!$email) {

        $msg_to_user = '<div class="warning"><ul><li>Please type an email address ' . $name . '.</li></ul></div><br /><br />';

    } else if ($numRows > 0) {

        $msg_to_user = '<div class="warning"><ul><li>' . $email . ' is already in the system.</li></ul></div><br /><br />';

    } else {

        $sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime) 
                                                    VALUES('$name','$email',now() )")  or die (mysql_error());

        $msg_to_user = '<div class="success"><ul><li>Thanks ' . $name . ', hope you find what you want!</li></ul></div><br /><br />';
        $name = "";
        $email = "";
    }
    $message = 'Name: ' . $_POST['name'] . 'Page:'.$curPageURL.', Email: ' . $_POST['email']; 
mail('newproducts@moniquetrinidadjewelry.com', 'New Newsletter Sign Up at Monique Trinidad Jewelry',  $message);
}
?>
<form style="width:430px;" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<fieldset style="text-align:left;padding:0px;border:0px;"> 
Name:
<input name="name" type="text" maxlength="36" value="<?php echo $name; ?>" />
Email:
<input name="email" type="text" maxlength="36" value="<?php echo $email; ?>" />
<input type="image" src="https://www.moniquetrinidadjewelry.com/images/new-images/green-bullet.png" border="0" name="mySubmitBtn" type="submit" value="Submit">

</fieldset> 
</form></div>
<div style="position:absolute;top:120px;"><?php echo $msg_to_user; ?></div>
<div class="newsletterExplain">Receive product updates. Remember only one of each!</div>
</div>
</div><!--wide newletter end-->
<div class="wrapFooter">


<div class="tearOneFooter">
    <div class="footerColumnList">
        <div class="footerTitles">Connect With Us</div>
        <div class="footerLists">
            <ul>
                <li><a href="https://www.moniquetrinidadjewelry.com/contact/contact-pop.php">Connect With Monique!</a></li>
            </ul>
        </div>

    </div>
<!--Seperate Connect With us Column from Information Column-->
    <div class="footerColumnList">
        <div class="footerTitles">Information</div>
        <div class="footerLists">
            <ul>
                <li><a href="https://www.moniquetrinidadjewelry.com/about-us.php">About Us</a></li>
                <li><a href="https://www.moniquetrinidadjewelry.com/packaging.php">Packaging</a></li>
                <li><a href="https://www.moniquetrinidadjewelry.com/terms-and-conditions.php">Terms & Conditions</a></li>
            </ul>
        </div>
    </div>
<!--Seperate Information Column from Shipping and Returns Column-->
    <div class="footerColumnList">
        <div class="footerTitles">Shipping and Returns</div>
        <div class="footerLists">
            <ul>
                <li><a href="https://www.moniquetrinidadjewelry.com/return-policy.php">Orders and Returns<a/></li>
                <li><a href="https://www.moniquetrinidadjewelry.com/secure-shopping.php">Secure Shopping</a></li>
                <li></li>
            </ul>
        </div>
    </div>
<!--Seperate Shipping and Returns Column from Services & Support Column-->
    <div class="footerColumnList">
        <div class="footerTitles">Hours Of Operation</div>
        <div class="footerLists">
            <ul>
                <li>We are a 24/7 <br />Online Establishment!<br />(US Based)</li>
            </ul>
        </div>
    </div>
<!--Seperate Connect With us Column from Information Column-->
</div>
<!--Beging SecondTearFooterArea-->
<div class="tearTwoFooter">

    <!--<div class="signUpNewsLetter"><img src="https://www.moniquetrinidadjewelry.com/images/news_letter_temp_IMG.png" alt="newsletter" /></div>-->
    <div class="paymentOptions"><img src="https://www.moniquetrinidadjewelry.com/images/payment_options_temp.png" alt="payment options" /></div>
    <div class="twitter"><a href="https://twitter.com/MoniqueJewelry"><img src="https://www.moniquetrinidadjewelry.com/images/twitter_temp.png" alt="twitterLink" /></a></div>


</div>
</div>
</div>
</div>

========================================================================== Expansion on question:

Removed link as no longer needed. Is it possible to sanitize action="" when not using php_self?

  • 写回答

1条回答 默认 最新

  • douchuifk90315 2013-06-05 03:16
    关注

    If you want the form to submit to the page that you are currently on use an empty action attribute which will cause the form to submit to the current url.

    <form style="width:430px;" action="" method="post">
    
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法