简体   繁体   English

PHP变量到node.js

[英]PHP variable to node.js

I manage my webpage with php, and as soon I login I want to pass a PHP variable to my index.ejs file. 我使用php管理我的网页,一旦登录,我想将PHP变量传递给我的index.ejs文件。

<textarea id="inputText" class="base--textarea input--text-area" placeholder="Please enter text to analyze...">
<?php 
session_start();
echo $_SESSION['description'];
?> 
</textarea>

Now, when I run nodejs app.js , in localhost 3000, node reads it as plain text.How can I pass the values that I login into my node app. 现在,当我运行nodejs app.js ,在localhost 3000中,节点将其作为纯文本读取。如何将我登录的值传递到我的节点应用程序中。

app.get('/search.html', function(req, res) {
    // Process the request for the GET variables
    var url_parts = url.parse(req.url, true);
    var query = url_parts.query; // These are all your GET variables
    var search_keyword = query.keyword;

    if(search_keyword) {
        // The keyword indeed exists
        console.log(search_keyword);

    }
    res.end();
});

Here's how I do it: 我是这样做的:

Create a new ExpressJS app If you run the app and go to "search.html?keyword=haha", your console will output "haha". 创建一个新的ExpressJS应用程序如果您运行该应用程序并转到“search.html?keyword = haha​​”,您的控制台将输出“haha”。 You can do anything after that with the keyword. 之后您可以使用关键字执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM