MyBB Community Forums

Full Version: access-control-allow-origin and my_setcookie
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

All works fine but mysetcookie does not save the cookie, Then I save the cookie using javascript, which I think is not so secure

my_setcookie("mybbuser", $mybb->user['uid']."_".$mybb->user['loginkey'], null, true);

Only when I use

 header("access-control-allow-origin:$http_origin");

Some idea?
Wait what are you asking? header() is a PHP function, not javascript. And what does that have to do with my_setcookie? Only when you set the 'access-control-allow-origin' header what..? That's a sentence fragment and I don't understand what you're trying to ask. You shouldn't have to worry about access-control if you're developing locally and just trying to set a cookie, access-control headers are used for grabbing data from external domains.
The only problem is that it is not saving the cookie, with my_setcookie function of mybb or with the setcookie function of php

<?php

if (array_key_exists('HTTP_ORIGIN', $_SERVER)) {
   $http_origin = $_SERVER['HTTP_ORIGIN'];
}
else if (array_key_exists('HTTP_REFERER', $_SERVER)) {
   $http_origin = $_SERVER['HTTP_REFERER'];
} else {
   $http_origin = $_SERVER['REMOTE_ADDR'];
}
$allowed_domains = array(
 'http://wio.com.mx',
 'http://www.wio.com.mx',
 'http://siprocesa.wio.com.mx',
 'http://hosting.wio.com.mx'
);
if (in_array($http_origin, $allowed_domains))
{  
   header("access-control-allow-origin:$http_origin");
}

error_reporting(E_ALL);
ini_set('display_errors', '1');

include("./../../../comun.php");
//In comun.php is included global.php
$comun=new comunes;
class ajax{
function derivacionaccion($datos){
$html="";
$derivacion=explode("¡",$datos);
$info=$derivacion[0];
$seccion=$derivacion[1];
switch ($seccion) {
case 4:
//login
$html=$this->login($info);
break;
}
return $html;
}
function login($info,$resultadoint=0){
global $plugins,$mybb,$db,$templates,$config;
$datos=explode("|",$info);
$inline_errors = "";
$plugins->run_hooks("member_do_login_start");
// Is a fatal call if user has had too many tries
$errors = array();
$logins = login_attempt_check();
require_once "./../../../interactu.wio.com.mx/public_html/inc/functions_user.php";
require_once "./../../../interactu.wio.com.mx/public_html/inc/datahandlers/login.php";
$loginhandler = new LoginDataHandler("get");
$user = array(
'username' => $datos[0],
'password' => $datos[1],
'remember' => "yes",
'imagestring' => ""
);
$user_loginattempts = get_user_by_username($user['username'], array('fields' => 'loginattempts'));
$user['loginattempts'] = (int)$user_loginattempts['loginattempts'];
$loginhandler->set_data($user);
$validated = $loginhandler->validate_login();
if($validated==1){
$loginhandler->complete_login();
$mybb->user = get_user($loginhandler->login_data['uid']);
my_setcookie("mybbuser", $mybb->user['uid']."_".$mybb->user['loginkey'], null, true);
// setcookie("mybbuser", $mybb->user['uid']."_".$mybb->user['loginkey'],$date_of_expiry,"/", "hosting.wio.com.mx");

$usuario=$mybb->user['username'];
$logout=md5($mybb->user['loginkey']);
if($mybb->user['usergroup']==4){
//eval('$adminpanelvinc= "'.$templates->get('TD_ajax_adminvinc').'";'); 
}
//eval('$resultado= "'.$templates->get('HT_logeado').'";');
$resultado=$usuario."|".$mybb->user['uid']."_".$mybb->user['loginkey'];
}else{
$db->update_query("users", array('loginattempts' => 'loginattempts+1'), "LOWER(username) = '".$db->escape_string(my_strtolower($user['username']))."'", 1, true);
$user_loginattempts = get_user_by_username($user['username'], array('fields' => 'loginattempts'));
$user['loginattempts'] = (int)$user_loginattempts['loginattempts'];
if($user['loginattempts']<5){
$resultado=0;
}
if($user['loginattempts']>5){
$resultado=1; 
}
}
$plugins->run_hooks("member_do_login_end");
return $resultado;
}
}
$ajax=new ajax;
$datos=$comun->filtrovars($_POST['datos']);
$html=$ajax->derivacionaccion($datos);
output_page($html,1);