简体   繁体   English

在PHP中将变量从一个页面发送到另一个页面

[英]Send a variable from one page to another in PHP

I am trying to send a variable value from one page to another. 我试图将变量值从一个页面发送到另一个页面。

I have used include("form-eidtable.php") in user-edit.php at bottom of the page, 我在页面底部的user-edit.php中使用了include("form-eidtable.php")

Look at the image below: 看下图:

在此输入图像描述

I dont know how can how can i do this. 我不知道怎么能这样做。 I am just trying to send the value. 我只是想发送价值。 IS there any way in Javascript in which i can $_GET a variable from PHP page? 在Javascript中有什么方法我可以从PHP页面$ _GET变量? or is there any way i can do this through PHP. 或者我有什么方法可以通过PHP来做到这一点。

Really stuck dont know what should i do. 真的卡住了,不知道该怎么办。

Thank you! 谢谢! (In Advance) (提前)

No need of Javascript. 不需要Javascript。
In your form-editable.php , just start a session and copy the desired variable into $_SESSION[] variable. form-editable.php ,只需启动一个会话并将所需的变量复制到$_SESSION[]变量中。

session_start();
$_SESSION['uid'] = $uid;

And then use it in user-edit.php . 然后在user-edit.php使用它。 Note that here also you will have to start a session. 请注意,您还必须启动会话。

session_start();
$uid = $_SESSION['uid'];

More on PHP sessions. 有关PHP会话的更多信息

You could use aa session 你可以使用一个会话

$_SESSION['uid'] = $uid;

Read more about sessions here. 阅读更多关于会议的内容。

http://www.w3schools.com/php/php_sessions.asp http://www.w3schools.com/php/php_sessions.asp

在你的js函数中使你的var redirecturl=..就像这样

var redirecturl = "user-edit.php?useredit=<?php echo $uid;?>";

You can use $_GET like that, but you have a syntax error in your Javascript after the PHP runs. 您可以使用$_GET ,但PHP运行后您的Javascript中存在语法错误。 You are closing out the string in your redirecturl and then having PHP echo $uid; 你正在关闭redirecturl的字符串,然后使用PHP echo $uid; . This results in Javascript of useredit="344 If you either wrap the PHP block inside the quote or add a + between the JS and the PHP (so long as your $uid is numeric`) it should work without using sessions. 这导致javascript of useredit="344如果要么将PHP块包装在引号中,要么在JS和PHP之间添加一个+ (只要你的$uid是数字`),它就可以在不使用会话的情况下工作。

You can use sessions or cookies the main advantage of the cookie is the fact that the cookie will remain even after the client will close his browser. 您可以使用会话或cookie,cookie的主要优点是即使在客户端关闭浏览器之后cookie仍将保留。 I won't recommend to use a variable in a GET method and use it without proper validation. 我不建议在GET方法中使用变量,并在没有适当验证的情况下使用它。 This will make your site vulnerable to sql injection attacks. 这将使您的网站容易受到SQL注入攻击。 If you want to access it from javascript you can use window.location. 如果你想从javascript访问它,你可以使用window.location。 But as a rule of thumb please validate your GET variables before using them in your sql queries. 但根据经验,请在您的SQL查询中使用它们之前验证您的GET变量。

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

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