John Davidson

c# - my php command lost when session_start and destry

0 comments
Message:


my webserver consist of C# server program, html and php


is running well


but when i send reset configurations command to C# program and logout to pages


then that commands is lost


this is my code


Server <-> JS <-> Html


C# Server Program(Received Part,Websocket Server)


using WebSocketSharp;


using WebSocketSharp.Server;


C# Program.cs



static WebSocketServer webSocketServer;

public static class Program
{
webSocketServer = new WebSocketServer(7777);
webSocketServer.AddWebSocketService<Chat>("/Chat");
webSocketServer.Start();
}

public static void CommandConverter(Model_CMD model_CMD)
{
switch(MdeolCMD.cmd)
{
case "Config":
switch (model_CMD.Parameter)
{
case "RESET":
ConfingRESET();
break;
}
break;
}
}


C# Chat.cs


using Newtonsoft.Json;
public class Chat : WebSocketBehavior
{
protected override void OnMessage(MessageEventArgs e)
{
var text = e.Data;
Model_CMD model_CMD = JsonConvert.DeserializeObject<Model_CMD>(text);
Program.CommandConverter(model_CMD, ID, true);
}
}

C# Model_CMD.cs


public class Model_CMD
{
public Model_CMD(string CMD, string Parameter, string Value = "", string Value2 = "", string Return = "")
{
this.CMD = CMD;
this.Parameter = Parameter;
this.Value = Value;
this.Value2 = Value2;
this.Return = Return;
}


public string CMD { get; set; }
public string Parameter { get; set; }
public string Value { get; set; }
public string Value2 { get; set; }
public string Return { get; set; }
}


JS Part(Send Command)



function Configuration_Reset()
{
var s_data = {};
s_data["id"] = "<?=$_SESSION['user_id']?>";
s_data["pw"] = "<?=$_SESSION['user_pw']?>";

SendCMD("RESET","Config",s_data["id"].toString(),s_data["pw"].toString());
window.location.href = "./logout.php";

}

function SendCMD(CMD, Parameter, Value1, Value2)
{
var s_data = {};
s_data["CMD"] = CMD;
s_data["Parameter"] = Parameter;
s_data["Value"] = Value1;
s_data["Value2"] = Value2;
s_data["Return"] = "";

socket.send((JSON.stringify(s_data));
}


logout.php


<?php
session_start();
session_destroy();
?>

<meta http-equiv='refresh' content='0;url=login.php'>

can i have some try?


-- ADDED


html js Command to C# Program


then transmitted well in C# when without logout.php after command
(if in js part without window.location.href = "./logout.php";
then C# server can catch command)


but send command and call logout.php then anything catch on C# Program


so how i can catch command in c# when command send and logout


-- ADDED


C# Minimal code add to run C# server



My Answer:
Hello! How can I assist you today?

Rate this post

3 of 5 based on 1986 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us