Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: An Echo In Here in here

      September 19, 2025

      How To Minimize The Environmental Impact Of Your Website

      September 19, 2025

      Progress adds AI coding assistance to Telerik and Kendo UI libraries

      September 19, 2025

      Wasm 3.0 standard is now officially complete

      September 19, 2025

      Development Release: Ubuntu 25.10 Beta

      September 18, 2025

      Development Release: Linux Mint 7 Beta “LMDE”

      September 18, 2025

      Distribution Release: Tails 7.0

      September 18, 2025

      Distribution Release: Security Onion 2.4.180

      September 18, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      GenStudio for Performance Marketing: What’s New and What We’ve Learned

      September 19, 2025
      Recent

      GenStudio for Performance Marketing: What’s New and What We’ve Learned

      September 19, 2025

      Agentic and Generative Commerce Can Elevate CX in B2B

      September 19, 2025

      AI Momentum and Perficient’s Inclusion in Analyst Reports – Highlights From 2025 So Far

      September 18, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Denmark’s Strategic Leap Replacing Microsoft Office 365 with LibreOffice for Digital Independence

      September 19, 2025
      Recent

      Denmark’s Strategic Leap Replacing Microsoft Office 365 with LibreOffice for Digital Independence

      September 19, 2025

      Development Release: Ubuntu 25.10 Beta

      September 18, 2025

      Development Release: Linux Mint 7 Beta “LMDE”

      September 18, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Tech & Work»CodeSOD: An Echo In Here in here

    CodeSOD: An Echo In Here in here

    September 19, 2025

    Tobbi sends us a true confession: they wrote this code.

    The code we’re about to look at is the kind of code that mixes JavaScript and PHP together, using PHP to generate JavaScript code. That’s already a terrible anti-pattern, but Tobbi adds another layer to the whole thing.

    
    <span class="hljs-keyword">if</span> (AJAX)
    {
        <span class="hljs-meta"><?php</span>
            <span class="hljs-keyword">echo</span> <span class="hljs-string">"AJAX.open("POST", '/timesheets/v2/rapports/FactBCDetail/getDateDebutPeriode.php', true);"</span>;
                
        <span class="hljs-meta">?></span>
        
        AJAX.<span class="hljs-title function_ invoke__">setRequestHeader</span>(<span class="hljs-string">"Content-type"</span>, <span class="hljs-string">"application/x-www-form-urlencoded"</span>);
        AJAX.onreadystatechange = callback_getDateDebutPeriode;
        AJAX.<span class="hljs-title function_ invoke__">send</span>(strPostRequest);
    }
    
    <span class="hljs-keyword">if</span> (AJAX2)
    {
        <span class="hljs-meta"><?php</span>
            <span class="hljs-keyword">echo</span> <span class="hljs-string">"AJAX2.open("POST", '/timesheets/v2/rapports/FactBCDetail/getDateFinPeriode.php', true);"</span>;
        <span class="hljs-meta">?></span>
        AJAX2.<span class="hljs-title function_ invoke__">setRequestHeader</span>(<span class="hljs-string">"Content-type"</span>, <span class="hljs-string">"application/x-www-form-urlencoded"</span>);
        AJAX2.onreadystatechange = callback_getDateFinPeriode;
        AJAX2.<span class="hljs-title function_ invoke__">send</span>(strPostRequest);
    }
    

    So, this uses server side code to… output string literals which could have just been written directly into the JavaScript without the PHP step.

    “What was I thinking when I wrote that?” Tobbi wonders. Likely, you weren’t thinking, Tobbi. Have another cup of coffee, I think you need it.

    All in all, this code is pretty harmless, but is a malodorous brain-fart. As for absolution: this is why we have code reviews. Either your org doesn’t do them, or it doesn’t do them well. Anyone can make this kind of mistake, but only organizational failures get this code merged.

    <!– Easy Reader Version: –>

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    news
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow To Minimize The Environmental Impact Of Your Website
    Next Article Agentic and Generative Commerce Can Elevate CX in B2B

    Related Posts

    Tech & Work

    How To Minimize The Environmental Impact Of Your Website

    September 19, 2025
    Tech & Work

    Progress adds AI coding assistance to Telerik and Kendo UI libraries

    September 19, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    AI-Driven Antitrust and Competition Law: Algorithmic Collusion, Self-Learning Pricing Tools, and Legal Challenges in the US and EU

    Machine Learning

    Declarative vs Imperative with PoM?

    Development

    Zoom Clients for Windows Vulnerability Exposes Users to DoS Attacks

    Security

    Thunderbird 142 Lets You Add Signatures to PDFs In-App

    Linux

    Highlights

    Gradebook – keep track of your grades

    July 11, 2025

    Gradebook is a simple tool that helps you keep track of your grades. This way…

    GameStop’s $500 Million Bitcoin Investment: A Strategic Leap into the Future

    May 30, 2025

    CVE-2025-4563 – Kubernetes NodeRestriction Dynamic Resource Allocation Authorization Bypass

    June 23, 2025

    AI in Finance: Transforming Investments and Banking in the Digital Age

    August 2, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.