Jump to content

Using ProcessWire session on external script


androbey
 Share

Recommended Posts

Hi everybody, 

unfortunately I am facing an issue, which I am both not able to resolve and don't know if here is the "right" place to ask for help. 

However, I am hoping that some of you can give me advice. 

To summarize what I want to do: 

From inside a template file I want to get page content from a file which is outside the site directory and using current ProcessWire session information (to "authenticate" the user, or rather just check if user is logged in or not). The external script is in a folder which lies on the same level as site and wire directories.

Inside my template file I have: 
 

<?php
function getContents($url){
  $c = curl_init($url);
  curl_setopt($c, CURLOPT_VERBOSE, 1);
  curl_setopt($c, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
  curl_setopt($c, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($c, CURLOPT_COOKIE, $_SERVER['HTTP_COOKIE']);
  $content = curl_exec($c);
  curl_close($c);
  return $content;
}

$url = $config->externalURL . 'data/getEntries.php';
$response = getContents($url);


From inside the external script ("getEntries.php") I "check" if user is logged in like: 

 

<?php namespace ProcessWire;
//bootstrapping ProcessWire
require('../../index.php');

function getAccessStatus(){
  $session = wire('session');
  //following does not work, because $session is empty, also $_SERVER['HTTP_COOKIE'] is null.
  if(wire('user')->isLoggedin() == true){
    $res['success'] = true;
	$res['status'] = 'OK';
  }else{
    $res['success'] = false;
	$res['status'] = 'No Auth';
	}
  return $res;
}


Am I missing something or is what I want to achieve not possible this way?

Hopefully someone can help. 

Thank you, 

Andreas

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...