Hi Andi,

I stand corrected – looks like session_start is needed in each. I was able to 
obtain session variables with this setup:

Login.php
<?php

require_once 'CAS.php';
phpCAS::client(CAS_VERSION_2_0, 'my.cas.server', 8080, 'mycascontext');
phpCAS::setNoCasServerValidation();
phpCAS::forceAuthentication();

// logout if desired
if (isset($_REQUEST['logout'])) {
        phpCAS::logout();
        session_destroy();
}
session_start();
$_SESSION['id'] = session_id();
$_SESSION['username'] = phpCAS::getUser();
if (isset($_SESSION['id'])) {
        echo $_SESSION['id'].'</br>';
        echo $_SESSION['username'].'</br>';
}
echo "<a href='Other.php'>Other page</a>";
?>


Other.php
<?php
session_start();
if (isset($_SESSION['id'])) {
        echo $_SESSION['id'].'</br>';
        echo $_SESSION['username'].'</br>';
}
?>


Navigating to Login.php prompts for CAS login and displays session/username 
upon success. Then, clicking the Other page links takes me to Other.php and the 
session data is printed to the screen.

Let me know if that helps. Apologies for the ambiguity in my initial replies.

Thanks,
-Neil

From: Andi Zulfadli [mailto:[email protected]]
Sent: Friday, July 24, 2015 8:28 AM
To: [email protected]
Subject: Re: [cas-user] Using session_id() variabel as Global Session variable.

Dear Sir Neil

Yes. noting change.

in login.php script show :
____________________________________________________________________________________________________________
Notice: A session had already been started - ignoring session_start() in 
D:\Workspace\demo\ta\login.php on line 65
ST-16-6uVfdkqBhVSZNWbunEkT-caspoliupgacid
syarif
___________________________________________________________________________________________________________

butin my addtional script nothing session value show Sir.

what is the problem sir?
do I need to send my client script to you?

Thank you very much.

Thank you

Best Regards

Andi Zulfadli







2015-07-24 7:10 GMT-07:00 Neil Sabol <[email protected]<mailto:[email protected]>>:
Ok thanks for trying – that was a wager but seems to be not the root cause.

Does the same thing happen if you uncomment session_start(); in your login 
script and comment it in your additional script?

Thanks,
-Neil

From: Andi Zulfadli 
[mailto:[email protected]<mailto:[email protected]>]
Sent: Friday, July 24, 2015 1:27 AM
To: [email protected]<mailto:[email protected]>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [cas-user] Using session_id() variabel as Global Session variable.

This is my script in other additional script.
______________________________________________________
 <?php

 session_start();

 if (isset($_SESSION['id'])) {
 echo $_SESSION['id'];
 }

?>
________________________________________________________
i do not understand why the session is not readable.

this is my login script.
___________________________________________________________
<?php

//session_start();

// Load the settings from the central config file
require_once 'config.php';
// Load the CAS lib
require_once $phpcas_path . 'CAS.php';

// Enable debugging
phpCAS::setDebug();

// Initialize phpCAS
phpCAS::client(CAS_VERSION_2_0, 'cas.poliupg.ac.id<http://cas.poliupg.ac.id>', 
8443, $cas_context);

phpCAS::handleLogoutRequests(true, 
"cas.poliupg.ac.id<http://cas.poliupg.ac.id>");

phpCAS::handleLogoutRequests();

phpCAS::setNoCasServerValidation();

// force CAS authentication

phpCAS::forceAuthentication();

// at this step, the user has been authenticated by the CAS server
// and the user's login name can be read with phpCAS::getUser().

 //phpCAS::handleLogoutRequests(true, 
array("cas.poliupg.ac.id<http://cas.poliupg.ac.id>"));

// logout if desired
if (isset($_REQUEST['logout'])) {
  phpCAS::logout();
  session_destroy();
}


 $_SESSION['id'] = session_id();
 $_SESSION['username'] = phpCAS::getUser();


if (isset($_SESSION['id'])) {

 // echo "<script language=\"JavaScript\">{ location.href=\"index.php\"; 
self.focus(); }</script>";

 echo $_SESSION['id'].'</br>';
 echo $_SESSION['username'].'</br>';

}

?>
______________________________________________________________________

in this login script, I try to print my $_SESSION['id'] variable after i login 
in cas server through phpCAS client.

and it works. the session is readable.

so i think the session variabel works. but. when i show in the others simple 
page like above. it is not readable even i append session_start script.

thank you very much for your help Sir.

Best Regards

Andi Zulfadli

2015-07-23 12:56 GMT-07:00 Neil Sabol <[email protected]<mailto:[email protected]>>:
Hi Andi,

I am not an expert, but it looks like you may be missing “session_start();” in 
your code to create the PHP session.

Hope that helps.

Thanks,
-Neil

From: Andi Zulfadli 
[mailto:[email protected]<mailto:[email protected]>]
Sent: Thursday, July 23, 2015 1:36 PM
To: [email protected]<mailto:[email protected]>
Subject: [cas-user] Using session_id() variabel as Global Session variable.

Dear Master.

Please Your Help.

I am using phpCAS Client 1.3.3 with simple authentication to CAS server with 
LDAP backend.

and i have successfull authentication and get return ticket / session id 
variabel. ex: "ST-404-sKkVIrpxuedp52YOtjGs-caspoliupgacid"

my problem is, i want to use the ticket / session id variabel as global session 
variabel and use the session for build other page in my application.

I do not know what the cause why in other pages session is not readable.

plese your help.

Thank you.
My "index.php" Code :
_________________________________________________________________________
// Load the settings from the central config file
require_once 'config.php';

// Load the CAS lib
require_once $phpcas_path . 'CAS.php';

// Enable debugging
phpCAS::setDebug();

// Initialize phpCAS
phpCAS::client(CAS_VERSION_2_0, 'cas.poliupg.ac.id<http://cas.poliupg.ac.id>', 
8443, $cas_context);

phpCAS::handleLogoutRequests(true, 
"cas.poliupg.ac.id<http://cas.poliupg.ac.id>");

phpCAS::setNoCasServerValidation();

// force CAS authentication

phpCAS::forceAuthentication();


// logout if desired
if (isset($_REQUEST['logout'])) {
            session_destroy();
            phpCAS::logout();
}

// for this test, simply print that the authentication was successfull

$_SESSION['id'] = session_id();
$_SESSION['username'] = phpCAS::getUser();
$_SESSION['name'] = session_name();
$_SESSION['version'] = phpCAS::getVersion();
_________________________________________________________________________







--

You are currently subscribed to 
[email protected]<mailto:[email protected]> as: 
[email protected]<mailto:[email protected]>

To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user

--

You are currently subscribed to 
[email protected]<mailto:[email protected]> as: 
[email protected]<mailto:jasig-cas-user%[email protected]>

To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user
--
You received this message because you are subscribed to a topic in the Google 
Groups "jasig-cas-user" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/jasig-cas-user/CtDFf4fPs8w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected]<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.




--

You are currently subscribed to 
[email protected]<mailto:[email protected]> as: 
[email protected]<mailto:[email protected]>

To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user



--

You are currently subscribed to 
[email protected]<mailto:[email protected]> as: 
[email protected]<mailto:[email protected]>

To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user




--

You are currently subscribed to 
[email protected]<mailto:[email protected]> as: 
[email protected]<mailto:[email protected]>

To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user

-- 
You are currently subscribed to [email protected] as: 
[email protected]
To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user

Reply via email to