0

I am converting an old PHP porject over to ASP.Net (vb) and wondered if someone could point me in the right direction in order to convert this final snippet of code.

There are 3 functions that are called from within this and i ahve converted those already and to be honest is the session arrays that are giving me the headache.

I have thought about using Hashtables and DirecCasting but this was just confusing me further.

Any help would be greatly apreciated.

$response = array();

$messages = array();

if (!empty($_POST['cbox'])) {

    if (!empty($_SESSION['opsd_user_'.$_POST['cbox']])) {
        $messages = $_SESSION['opsd_user_'.$_POST['cbox']];
    }
} else 
{

    if (!empty($_POST['blist']) && $_POST['blist'] == 1) { getBList(); }

    if (!empty($_POST['initialize']) && $_POST['initialize'] == 1) { 
        getStatus(); 

        if (!empty($_SESSION['opsd_sessionvars'])) {
            $response['initialize'] = $_SESSION['opsd_sessionvars'];

            if (!empty($_SESSION['opsd_sessionvars']['openCBID']) && !empty($_SESSION['opsd_user_'.$_SESSION['opsd_sessionvars']['openCBID']])) {
            $messages = array_merge($messages,$_SESSION['opsd_user_'.$_SESSION['opsd_sessionvars']['openCBID']]);
            }
        }
    } else {

        if (empty($_SESSION['opsd_sessionvars'])) {
            $_SESSION['opsd_sessionvars'] = array();
        }

        if (!empty($_POST['sessionvars'])) {
            ksort($_POST['sessionvars']);
        } else {
            $_POST['sessionvars'] = '';
        }

        if (!empty($_POST['updatesession']) && $_POST['updatesession'] == 1) { 
            $_SESSION['opsd_sessionvars'] = $_POST['sessionvars'];
        }

        if ($_SESSION['opsd_sessionvars'] != $_POST['sessionvars']) {
            $response['updatesession'] = $_SESSION['opsd_sessionvars'];
        }

    }

    getLastTimestamp();
    fetchMessages();
}
3
  • 4
    First, do you understand what the code does? Commented Feb 23, 2011 at 17:39
  • Yes I am aware of what the code does, there are a number of ajax posts that come in and these are updated (some) into session variables. there are 3 distinct areas I am struggling with: 1 - $response['initialize'] = Session['opsd_sessionvars']; 2 - ksort($_POST['sessionvars']); 3 - $messages = array_merge($messages,$_SESSION['opsd_user_'.$_SESSION['opsd_sessionvars']['openCBID']]); Iam just not sure how to convert these, I think I have the rest already done Commented Feb 23, 2011 at 19:56
  • That you're struggling to convert sort and merge operations shows that you don't. Commented Feb 23, 2011 at 21:34

1 Answer 1

1

I think what you're looking for is the Session and Request.Form properties of the ASP.NET page. A simple find/replace of $_SESSION with Session in the page should work wonders, as should a replacement of $_POST with Request.Form.

Sign up to request clarification or add additional context in comments.

2 Comments

OK I get that and will make the required changes but I dont get the following: $messages = array_merge($messages,$_SESSION['opsd_user_'.$_SESSION['opsd_sessionvars']['openCBID']]); and ksort($_POST['sessionvars']); I have checked php.net but have not really been able to find ant .net equivalents.
If $messages is a string-keyed array, then the .NET equivalent is a Dictionary(String, something). The ksort() method is equivalent to pushing those same key-value pairs into a SortedDictionary(K,V) and iterating over it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.