2015-11-06 172 views
0

我的老闆網站上的所有頁面都啓動會話,每次用戶訪問時都會在屬性頁面上定義(或重新定義)一個變量。該變量應該傳遞給聯繫頁面,並將其插入到PHP聯繫表單中,並通過電子郵件發送給我的老闆,以便他知道人們與他聯繫的是哪些資產。PHP變量會話代碼不工作

這裏是我用來定義變量的代碼:

$_SESSION['property'] = "55-scholard-ph5";//Set Property Name 

我有我使用的是正常工作的通用PHP接觸形式,我也有

<?php // Start the session 
session_start(); ?> 

開頭的每一頁。該解決方案工作了大約一個月,但現在它不插入該變量。

下面是完整的HTML網頁代碼:

<!--FORM SESSION CODE--> 
<?php 

// Start the session 
session_start(); 
?> 
<!--FORM SESSION CODE--> 

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=1100"> 
<title>Boris Kholodov &#183; 55 Scollard, Penthouse 5 &#183; Toronto, Canada</title> 
    <meta name="description" content="View 55 Scollard, Penthouse 5 at Boris Kholodov's real estate website."> 
<link rel="stylesheet" type="text/css" href="../design.css"> 


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script src="../javajq/jquery.touchslider.min.js"></script> 
<script> 
jQuery(function($) { 
    $(".touchslider").touchSlider({container: this, 
duration: 800, // the speed of the sliding animation in milliseconds 
delay: 5000, // initial auto-scrolling delay for each loop 
margin: 3, // borders size. The margin is set in pixels. 
mouseTouch: true, 
namespace: "touchslider", 
next: ".touchslider-next", // jQuery object for the elements to which a "scroll forwards" action should be bound. 
pagination: ".touchslider-nav-item", 
currentClass: "touchslider-nav-item-current", // class name for current pagination item. 
prev: ".touchslider-prev", // jQuery object for the elements to which a "scroll backwards" action should be bound. 
autoplay: true, // Activate auto-scrolling, choose either "true" or "false" 
viewport: ".touchslider-viewport"}); 
}); 
</script> 

</head> 

<body bgcolor="#fafbff"> 

<!--FORM ADDRESS CODE--> 
<?php 
$_SESSION['property'] = "55-scholard-ph5";//Set Property Name 
?> 
<!--FORM ADDRESS CODE--> 


<?php include('../navigation.html');?> 



<!-- MAIN CONTENT --> 
<div id="page-wrap"> 
    <!--JAVASCRIPT DISABLED NOTIFICATION--> 
    <noscript> 
     <?php include('../noscript.html');?> 
    </noscript> 

    <!---------------------------------------- MOBILE SLIDER ----------------------------------------> 

<div class="touchslider hideslide" style="text-align: center;"> 
    <div class="touchslider-viewport" style="width:1000px; height:550px; overflow:hidden; position: relative;"><div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/1.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/2.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/3.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/4.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/5.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/6.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/7.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/8.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/9.jpg" class="round" width="1000" height="550" /></div> 
     <div class="touchslider-item"><img src="images/55-scholard-ph5/10.jpg" class="round" width="1000" height="550" /></div> 


    </div> 
    </div> 

    <br /><br /> 

    <!---------------------------------------- LEAVING FOR NOW, BUT DONT NEED IT ----------------------------------------> 
    <div style="text-align:center; height:5px; width: 1000px; position: relative;"> 
     <span class="touchslider-prev" style="cursor:pointer; z-index: 40;"><span class="prevbutton"></span></span> 

     <span class="touchslider-next" style="cursor:pointer; z-index: 40;"><span class="nextbutton"></span></span> 
    </div> 


</div> 

    <!---------------------------------------- DESKTOP SLIDER ----------------------------------------> 


    <div id="container" class="hidephone" > 
    <ul> 
    <li><img src="images/55-scholard-ph5/1.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/2.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/3.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/4.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/5.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/6.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/7.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/8.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/9.jpg" class="round" width="1000" height="550" /></li> 
    <li><img src="images/55-scholard-ph5/10.jpg" class="round" width="1000" height="550" /></li> 
    </ul> 
    <span class="button prevButton"></span> 
    <span class="button nextButton"></span> 


    </div> 

    <img src="images/spacer.gif" class="hidephone" /> 


    <hr class="purple"> 
    <br /> 


    <!----------------------------------------MAIN INFO AREA--------------------------------------> 
    <article> 
    <section> 
    <div class="lefttextbig"> 
     <header> 
     <h1 class="black cursive">Luxury Penthouse at the Four Seasons</h1> 
     <br /> 
     <h2 class="black">$1,950,000 &#183; 55 Scollard, Penthouse 5</h2> 
     </header> 
     <p class="black"> 
      <br /> 
      <span class="subtitle">CANADA'S MOST PRESTIGIOUS ADDRESS </span> &nbsp; Yorkville. Bloor. Four Seasons. Everyone knows. This is the most prestigious and coveted address in Canada. Luxurious, stylish, seductive, the new Four Seasons Hotel Toronto has already established itself as Toronto’s most famous meeting place. Its architectural pedigree, its personality and its name have successfully attracted those from Toronto and those from abroad. 
      <br /><br /> 

      <span class="subtitle">ONLY THE BEST</span> &nbsp; Designed by architectsAlliance in collaboration with Page & Steele this hotel condo development demonstrates a contemporary design paired with a level of elegance that will satisfy the most discerning purchaser. The private residences offer the best in design and service. 

      <br /><br /> 

      <span class="subtitle">360 DEGREE LUXURY</span> &nbsp; Penthouse 5 is a luxuriously finished residence, measuring 1265 precious square feet, offering you 11-foot ceilings and stunning views from floor-to-ceiling windows throughout. This suite is bright, impressive, modern, yet elegant. The layout features a discreet entrance area, an open living area, split bedrooms, 2 full baths and a 20ft balcony. 

      <br /><br /> 

      <span class="subtitle">ALL YOU COULD ASK FOR &mdash; AND THEN SOME</span> &nbsp; The east tower is a private, exclusive, resident-only building. Its owners enjoy privacy coupled with easy access to all the benefits of Four Season living, including access to hotel amenities, facilities and services. Just steps away from five-star Yorkville shops and restaurants, and central Toronto metro stations. 

      <br /><br /> 
      To schedule a viewing <a href="listing-contact.php" class="black">contact Boris Kholodov</a>.<br /><br /> 

     </p> 

     <hr class="purple"> 

     <br /><br /> 

     <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2885.828667395075!2d-79.3884502!3d43.672532999999994!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x882b34aedb4fae43%3A0xedbc5eb829dd0221!2s55+Scollard+St%2C+Toronto%2C+ON+M5R!5e0!3m2!1sen!2sca!4v1427829323609" width="650" height="350" frameborder="0" style="border:0"></iframe> 
    </div> 
    </section> 
    <!----------------------------------------MAIN INFO AREA--------------------------------------> 

    <!----------------------------------------DETAILED INFO----------------------------------------> 
    <section> 
    <div class="rightinfo"> 

      <!-- Boris's Photo, Title and Contact Info--> 
       <?php include('boris-info.html');?> 


       <!-- <hr class="purple"> 

       <p class="small"> 
        <span class="italic">Open House Times:</span><br /> 
        Sat 28<sup>th</sup>/2:30pm&#8211;4:30pm<br /> 
        Sun 1<sup>st</sup>/2:30pm&#8211;4:30pm 
       </p> --> 

       <hr class="purple"> 

       <a href="listing-book.php" style="text-decoration: none;"> 
        <div class="purpleb round formstyle bgcolor sendform" style=" 
        padding: 15px 15px 8px 15px; 
        width: 210px; 
        text-align: center;"> 
         <span class="parastyle black" style="font-weight: normal; 
         letter-spacing: 0.1em;"> 
          BOOK A SHOWING 
         </span> 

        </div> 
       </a> 

       <hr class="purple"> 

       <a href="images/55-scholard-ph5/55-scholard-ph5-floorplan-boris.pdf" style="text-decoration: none;" target="_blank"> 
        <div class="purpleb round formstyle bgcolor sendform" style=" 
        padding: 15px 15px 8px 15px; 
        width: 210px; 
        text-align: center;"> 
         <span class="parastyle black" style="font-weight: normal; 
         letter-spacing: 0.1em;"> 
          VIEW FLOORPLAN 
         </span> 

        </div> 
       </a> 

       <hr class="purple"> 

       <a href="listing-contact.php" style="text-decoration: none;"> 
        <div class="purpleb round formstyle bgcolor sendform" style=" 
        padding: 15px 15px 8px 15px; 
        width: 210px; 
        text-align: center;"> 
         <span class="parastyle black" style="font-weight: normal; 
         letter-spacing: 0.1em;"> 
          CONTACT BORIS 
         </span> 

        </div> 
       </a> 

       <hr class="purple"> 



       <p class="small"> 
        <span class="italic">Type:</span> 
        Downtown Penthouse 
        <br /> 
        <span class="italic">Neighbourhood:</span> 
        Yorkville 
        <br /> 
        <span class="italic">Square Footage:</span> 
        1265<sup>sf</sup> + Balcony 
        <br /> 
        <!--<span class="italic">Lot Size:</span> 
        33<sup>ft</sup> &#215; 128<sup>ft</sup> 
        <br /> --> 
        <span class="italic">Property Tax:</span> 
        $15,266 for 2014 
        <br /> 
        <span class="italic">Bedrooms:</span> 
        2 
        <br /> 
        <span class="italic">Washrooms:</span> 
        2 
        <br /> 
        <span class="italic">Parking:</span> 
        1 Owned Underground 
       </p> 

       <hr class="purple"> 
       <p class="small"> 
        <span class="italic">Inclusions:</span> 
     <ul >      
        <li class="small">Miele Gas Cooktop and Oven, Sub-Zero Fridge, Panasonic Microwave, Dishwasher, Stacked Washer/Dryer</li> 
        <li class="small">All Existing Light Fixtures</li> 
        <li class="small">All Existing Window Coverings</li> 
     </ul> 

        <hr class="purple"> 
       <p class="small"> 
        To inquire further about this property please <a href="listing-contact.php" class="black">contact Boris</a>. 
       </p> 

      </div> 
     </section> 
     <!----------------------------------------DETAILED INFO----------------------------------------> 
    </article> 

<?php include('../footer.html');?> 


</div> 
<!-- MAIN CONTENT --> 


<script src="../javajq/jquery-1.11.2.min.js"></script> 

<script> 
$(window).load(function(){ 
     var pages = $('#container li'), current=0; 
     var currentPage,nextPage; 
     var timeoutID; 
     var buttonClicked=0; 

     var handler1=function(){ 
      buttonClicked=1; 
      $('#container .button').unbind('click'); 
      currentPage= pages.eq(current); 
      if($(this).hasClass('prevButton')) 
      { 
       if (current <= 0) 
        current=pages.length-1; 
        else 
        current=current-1; 
      } 
      else 
      { 

       if (current >= pages.length-1) 
        current=0; 
       else 
        current=current+1; 
      } 
      nextPage = pages.eq(current); 
      currentPage.fadeTo('slow',0.3,function(){ 
       nextPage.fadeIn('slow',function(){ 
        nextPage.css("opacity",1); 
        currentPage.hide(); 
        currentPage.css("opacity",1); 
        $('#container .button').bind('click',handler1); 
       }); 
      });   
     } 

     var handler2=function(){ 
      if (buttonClicked==0) 
      { 
      $('#container .button').unbind('click'); 
      currentPage= pages.eq(current); 
      if (current >= pages.length-1) 
       current=0; 
      else 
       current=current+1; 
      nextPage = pages.eq(current); 
      currentPage.fadeTo('slow',0.3,function(){ 
       nextPage.fadeIn('slow',function(){ 
        nextPage.css("opacity",1); 
        currentPage.hide(); 
        currentPage.css("opacity",1); 
        $('#container .button').bind('click',handler1);    
       }); 
      }); 
      timeoutID=setTimeout(function(){ 
       handler2(); 
      }, 8000); 
      } 
     } 

     $('#container .button').click(function(){ 
      clearTimeout(timeoutID); 
      handler1(); 
     }); 

     timeoutID=setTimeout(function(){ 
      handler2(); 
      }, 8000); 

}); 

</script> 

<!--GOOGLE TRACKING--> 
<script> 
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

    ga('create', 'UA-61408930-1', 'auto'); 
    ga('send', 'pageview'); 

</script> 
<!--GOOGLE TRACKING--> 

</body> 
</html> 

下面是一個單獨的PHP文件中引用的聯繫表格代碼:

<?php 
session_start(); 
if(!isset($_POST['submit'])) 
{ 
    //This page should not be accessed directly. Please use the form. 
    echo "Error, please return to last page."; 
} 
$property = $_SESSION['property']; 
$name = $_POST['name']; 
$visitor_email = $_POST['email']; 
$tel = $_POST['tel']; 
$message = $_POST['message']; 
$spambot = $_POST['spambot']; 

if ($spambot != 'Yes') { 
    $spambot = 'No'; 
} 

//Validate first 
if($spambot == 'No') 
{ 
    echo "Please go back and check the 'I'm not a Spambot' box."; 
    exit; 
} 

if(empty($name)||empty($visitor_email)||empty($tel)) 
{ 
    echo "Name, email and phone number are mandatory."; 
    exit; 
} 

if(IsInjected($visitor_email)) 
{ 
    echo "Bad email value!"; 
    exit; 
} 


// Email information 
$email_from = "[email protected]"; 
$email_subject = "Real Estate"; 
$email_body = 

"PROPERTY: $property \n \n". 

"NAME: $name\n \n". 

"MESSAGE:\n 
$message \n \n ". 

"PHONE NUMBER: $tel\n \n". 

"EMAIL: $visitor_email\n \n". 

$to = "[email protected]"; 
$headers = "From: $email_from \r\n"; 
$headers .= "Reply-To: $visitor_email \r\n"; 
//Send the email! 
mail($to,$email_subject,$email_body,$headers); 
//done. redirect to thank-you page. 
header('Location: ../contact/thankyou.php'); 


// Function to validate against any email injection attempts 
function IsInjected($str) 
{ 
    $injections = array('(\n+)', 
       '(\r+)', 
       '(\t+)', 
       '(%0A+)', 
       '(%0D+)', 
       '(%08+)', 
       '(%09+)' 
      ); 
    $inject = join('|', $injections); 
    $inject = "/$inject/i"; 
    if(preg_match($inject,$str)) 
    { 
    return true; 
    } 
    else 
    { 
    return false; 
    } 
} 

?> 

問題是什麼?

您可以通過訪問此屬性頁並單擊任何聯繫鏈接來體驗聯繫表單。請在表格正文中輸入「社區測試」,以便我的老闆知道它不是真正的客戶。

http://agentboris.com/listings/92-park.php

+0

您將需要展示更多的代碼。 – rjdown

+0

我認爲在任何人都可以幫忙之前,你將不得不展示更多的代碼。 –

+0

什麼是您設置它的代碼?和你訪問它的地方的代碼? – chris85

回答

0

如果你不介意的話,我想建議你不要使用Session要做到這一點,很多用戶(比如我)查看之前打開多個頁面,讓你的財產將得到公正的最後一個,把錯誤的財產發給你的老闆。相反,您可以通過URL變量傳遞此信息,將聯繫人按鈕的href屬性更改爲:每個頁面上的http://agentboris.com/listings/listing-contact.php?property=55-scholard-ph5,並在聯繫人的PHP代碼中使用PHP $_GET["property"]。您也可以在每個頁面上使用聯繫表單。

關於解決方案停止工作的疑問,請確保您不使用任何地方@session_destroy(),也不在其他地方重新設置它,有時候我做這樣的事情:if (!$_SESSION["property"] = "")在現實中,我在重新設定爲""。當然,你在聯繫人的頁面開始會話,在<?php之後......你必須開始會話才能獲得變量ok。

希望它能幫助你!問候!

PS。你有一個漂亮的網站!

+0

感謝您的迴應,我試過在頁面上測試這個,但它不工作,它不會調用?property = 56-berkindle。 –

+0

另外,我沒有在任何地方使用@session_destroy。 –