开发者

Passing a PHP variable to another page via jQuery

EDIT: I can put the question in a shorter way that perhaps focuses more closely on the real problem:

Is there a way to keep PHP Sockets alive over multiple pages? That is, can I store the connection (the socket object) in any way?

I want to save a socket connection between two PHP pages where the other page is loaded via jQuery ajax. I tried it with sessions and so far got this on my main page:

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$res = socket_connect($sock, $host, $port);
session_start();
$_SESSION['sock'] = $sock;  

I then load a page with jQuery:

$("#" + in_n开发者_Python百科ame + "_holder").load("set_setpoint.php", {name:in_name, value:in_value});

And in set_setpoints.php:

session_start();     
require_once("sock_funcs.php");    
echo $_SESSION['sock'];

I only get '0', but what I should get is something like "Resource id #xxx". Maybe sessions is the wrong way?


You can't pass resources between pages.

see PHP pfsockopen in a session


Why don't you use COOKIE to save your value and then access using CLIENT anywhere you want.

1

$_COOKIE["socketNo"] = "somevalue";

Access it like

$_COOKIE["socketNo"];

Make sure the cookie is accessible.

2

You can pass the data as a query-string to the URL that is used on AJAX call and retrieve it in your script.

$("#" + in_name + "_holder").load("set_setpoint.php?socketNo=", {name:in_name, value:in_value});

in set_setpoints.php

$sock = $_GET["socketNo"];


You can use GET or POST to pass the content, or you can set a cookied encoded and share the content between the two applications.


just try $.get(); in jquery,,

for ur question $.get() or $.post();

if u use $.get(); then u can understand how this parrameter run if any doubt ask me dude..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜