最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - send php value without using form or session? - Stack Overflow

programmeradmin4浏览0评论

is there a way for me to send a $_POST value to another page without using FORM or SESSION method? because the form method is already being use inside the page itself but i need to send 1 variable to the other page for confirmation.

a simple php or javascript will be great!

this is the value

<input name="sig"  id="sig" type="text" value="<?php echo $_POST["sig"]; ?>" /> 

code that is supposed to catch the code on the next page

<?php
$pass = $_POST['password'];
$password = "service2012";  // Modify Password to suit for access, Max 10 Char.
if ( $pass != $password) {
    header("Location: ");
}
?>

is there a way for me to send a $_POST value to another page without using FORM or SESSION method? because the form method is already being use inside the page itself but i need to send 1 variable to the other page for confirmation.

a simple php or javascript will be great!

this is the value

<input name="sig"  id="sig" type="text" value="<?php echo $_POST["sig"]; ?>" /> 

code that is supposed to catch the code on the next page

<?php
$pass = $_POST['password'];
$password = "service2012";  // Modify Password to suit for access, Max 10 Char.
if ( $pass != $password) {
    header("Location: https://www.login.html");
}
?>
Share Improve this question edited Sep 24, 2012 at 6:03 telexper asked Sep 24, 2012 at 5:41 telexpertelexper 2,44110 gold badges39 silver badges66 bronze badges 3
  • Use AJAX or redesign your application – Alexander Larikov Commented Sep 24, 2012 at 5:43
  • redisign is not an option because the value i'm planning to send to the other page is a password to open it otherwise the user will be sent back to the log-in page or get stuck to the current page he is in. – telexper Commented Sep 24, 2012 at 5:44
  • isn't that the purpose of a login page? – Mr. 14 Commented Sep 24, 2012 at 5:52
Add a ment  | 

4 Answers 4

Reset to default 3

If you are passing a password to the other page, then it does not make sense using GET values. All the solutions till now have been GET values, which anyone can modify. It is usually not safe and creates an XSS vector.

I want to understand why do you want to pass the password to the next page, cause usually, you design your application such that the user enters the password once, and you create a SESSION variable.

You then check this SESSION on each page that requires the user to be logged in. You can use any popular programming language to understand how to create SESSIONS. For PHP :

<?php
session_start(); 
$_SESSION['page'] = 'SomePage'; // store session data
echo "Page = ". $_SESSION['page']; //retrieve data
?>

You should ideally, create a session and then pass this session variable in place of passing POST data.

Let me know in case you need further clarification on this.

yes send it via javascript

EDIT:

<script>
function sendval(){
  var d=document.getElementById("password").value;
  document.location.href='otherpage.php?password='+d;
}
</script>

your otherpage.php

<?php 
$pass = $_GET['password']; 
$password = "service2012"; // Modify Password to suit for access, Max 10 Char. 
if ( $pass != $password) { 
    header("Location: login.html";); 
} 
?> 

This is rough code,

you can call the function however you feel like.

Also you can use ajax to send the variables.

If you want to send some important data like password than i will highly remand you to use POST method and if you don't want to do so use

<form action="main.php" method="GET">
$pass = $_GET['password'];
$password = "service2012";  // Modify Password to suit for access, Max 10 Char.
if ( $pass != $password) {
    header("Location: https://www.login.html");
}//this is insecure method

use a link like

http:/website./main.php?data=1

//data is variable which you want to send 

and in main.php

$data=$_GET['data'] ;

you can simply get data using global $_GET array

create a simple link <a href="main.php?data=1">link</a> or you can use onclick="main.php?data=1"

You can embed your variable in URL like this Edit:

www.server./abc.php?variable=value;

In abc.php page you will get the value.

发布评论

评论列表(0)

  1. 暂无评论