您好我想在网址中使用用户会话ID,但出于某种原因,智能PHP不会返回任何会话值。
我想知道在我可以在tpl文件中打印以下内容之前是否还需要做些什么。
{$smarty.session.id}
{$userid}
我试图将这两个文件放入我的tpl文件中,但是一旦页面加载就不会显示。
$smarty->assign('userid', ''.$_SESSION['userid']);
我的模板文件
{*********************************************************
Multi line comment block with credits block
@ author: harrower.xyz
@ Site: SIITE.XYZ
@ Date Created 11/06/2016
@ Last Edited 07/01/2017
@ Orginially Created By Russell Harrower
@ Edited By Russell Harrower
@ maintainer: russell@site.xyz
**********************************************************}
{* The header file with the main logo and stuff *}
{extends file='./tpl-files/template.tpl'}
{block name=head}
<script type="text/javascript">
window.onload = function (){
hidestuff("entermanually");
}
function addEvent(obj, event, func) {
if (obj.addEventListener) {
obj.addEventListener(event, func, false);
return true;
} else if (obj.attachEvent) {
obj.attachEvent('on' + event, func);
} else {
var f = obj['on' + event];
obj['on' + event] = typeof f === 'function' ? function() {
f();
func();
} : func
}
}
//SHOW AND HIDE DATA FROM USERS
function showstuff(boxid){
document.getElementById(boxid).style.display="block";
componentHandler.upgradeAllRegistered();
}
function hidestuff(boxid){
document.getElementById(boxid).style.display="none";
}
function manuallyenterdata(){
hidestuff("RAU");
hidestuff("fb");
showstuff("entermanually");
}
</script>
<script src="plugins/stepper/stepper.min.js"></script>
<script src="plugins/dropzone/dropzone.js"></script>
<link rel="stylesheet" href="plugins/dropzone/dropzone.css">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<link href='templates/main/style/newprofile.css' rel='stylesheet' type='text/css'>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
// alert(accessToken);
testAPI();
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.6' // use graph api version 2.5
});
// Now that we've initialized the JavaScript SDK, we call
// FB.getLoginStatus(). This function gets the state of the
// person visiting this page and can return one of three states to
// the callback you provide. They can be:
//
// 1. Logged into your app ('connected')
// 2. Logged into Facebook, but not your app ('not_authorized')
// 3. Not logged into Facebook and can't tell if they are logged into
// your app or not.
//
// These three cases are handled in the callback function.
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.open("POST", "facebook_login",true);
//xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify(response));
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=id,first_name,middle_name,last_name,birthday,picture,cover,email,about', function(response) {
// alert(JSON.stringify(response, null, 4));
console.log('Successful login for: ' + response.first_name + ' ' + response.last_name + '\n ' + response.birthday + '\n ' + response.email +'\n ' + response.cover.source + '\n '+ response.picture.data.url +'\n '+ response.about);
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.open("POST", "facebook_profile",true);
//xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify(response));
//window.location.replace("facebook.php");
// document.getElementById('status').innerHTML =
// 'Thanks for logging in, ' + response.name + ' - '+ response.email + '!'+ ' - '+ response.gender;
});
}
</script>
{/block}
{block name=body}
<div class="mdl-section__centre mdl-grid mdl-cell mdl-cell--12-col" style="margin-bottom:0 !important;">
<div class="mdl-card-fullwide mdl-shadow--0dp">
<div class="mdl-card__supporting-text">
<div class="mdl-stepper-horizontal-alternative">
<div class="mdl-stepper-step active-step editable-step">
<div class="mdl-stepper-circle"><span>1</span></div>
<div class="mdl-stepper-title">Basic Information</div>
<div class="mdl-stepper-bar-left"></div>
<div class="mdl-stepper-bar-right"></div>
</div>
<div class="mdl-stepper-step active-step">
<div class="mdl-stepper-circle"><span>2</span></div>
<div class="mdl-stepper-title">Contact Information</div>
<div class="mdl-stepper-optional"></div>
<div class="mdl-stepper-bar-left"></div>
<div class="mdl-stepper-bar-right"></div>
</div>
<div class="mdl-stepper-step">
<div class="mdl-stepper-circle"><span>3</span></div>
<div class="mdl-stepper-title">Your Pets</div>
<div class="mdl-stepper-optional"></div>
<div class="mdl-stepper-bar-left"></div>
<div class="mdl-stepper-bar-right"></div>
</div>
<div class="mdl-stepper-step">
<div class="mdl-stepper-circle"><span>4</span></div>
<div class="mdl-stepper-title">Share</div>
<div class="mdl-stepper-optional">Optional</div>
<div class="mdl-stepper-bar-left"></div>
<div class="mdl-stepper-bar-right"></div>
</div>
</div>
</div>
</div>
<div id="RAU" class="mdl-card-fullwide mdl-card">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">Your Profile Information</h2>
</div>
<div class="mdl-card__supporting-text mdl-grid mdl-cell mdl-cell--12-col">
{$smarty.session.uid}
</div>
<div id="fb" class="mdl-section__centre mdl-grid mdl-cell mdl-cell--3-col" style="margin-bottom:0;">
<fb:login-button size="large" scope="public_profile,email,user_birthday,user_location" onlogin="checkLoginState();">
Fetch My Facebook Information
</fb:login-button>
</div>
<!-- Accent-colored raised button with ripple -->
<div id="manualprofile" class="mdl-section__centre mdl-grid mdl-cell mdl-cell--3-col" style="margin-bottom:0;">
<button onClick="manuallyenterdata()" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
Don't link my Facebook {$smarty.session.id}
</button>
</div>
</div>
</div>
<div id="entermanually" class="mdl-card-fullwide mdl-card">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">Upload a Profile Picture</h2>
</div>
<div class="mdl-card__supporting-text mdl-grid mdl-cell mdl-cell--12-col">
</div>
<div class="mdl-grid mdl-cell mdl-cell--11-col">
<!-- Simple Textfield -->
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<div id="profile" class="dropzone">
</div>
</div>
</div>
<!-- <div class="mdl-card__actions mdl-card--border">
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
Get Started
</a>
</div>-->
<!--<div class="mdl-card__menu">
<button class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect">
<i class="material-icons">share</i>
</button>
</div>-->
</div>
<div class="mdl-card__actions mdl-card--border">
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" style="float:right;">
Next Step
</a>
</div>
</div>
</div>
</div>
</div>
{literal}
<script type="text/javascript">
var mydrop = new Dropzone("div#profile", {
url: "https://site.xyz/v1/users/post",
paramName: "file",
maxFiles : 1,
uploadMultiple: false,
addRemoveLinks : false,
acceptedFiles: 'image/*',
autoProcessQueue: true,
init: function() {
var submitButton = document.querySelector("#act-on-upload")
myDropzone = this;
submitButton.addEventListener("click", function() {
myDropzone.processQueue();
});
myDropzone.on("addedfile", function(file) {
if (!file.type.match(/image.*/)) {
if(file.type.match(/application.zip/)){
myDropzone.emit("thumbnail", file, "path/to/img");
} else {
myDropzone.emit("thumbnail", file, "path/to/img");
}
}
});
myDropzone.on("complete", function(file) {
myDropzone.removeFile(file);
});
},
});
console.log( mydrop.dropzone );
</script>
{/literal}
{/block}