WebsiteBaker Support (2.13.x) > Hilfe & Support (deutsch)

Logout mittels Curl POST-Request

(1/2) > >>

markherrmann:
Hi Leute,
zu Logout gibt's schon viele Posts zum Thema Redirect aber noch keinen für mein aktuelles Problem. Ich wollte mal fragen, ob schon jemand Erfahrung mit dem Thema Logout über CURL gesammelt hat.

Ich habe eine Php-Function, wenn ich die aufrufe dann wird abgemeldet (so die Theorie).
Warum? Ich möchte Usern die Möglichkeit geben Ihren Account zu löschen. Wie ich das bewerkstellige ist mir eigentlich klar (ich setze Sie in der Datenbank auf inaktiv) ... Möchte sie dann aber auch abmelden (ohne separaten Button).

Deswegen habe ich mir überlegt ich sende einen POST-Request an logout.php ... Das Ergebnis waren leider eine menge Fehlermeldungen aber kein Logout  :oops:

Meine Function für den Logout sieht wie folgt aus:


--- Code: ---function userLogout() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://xxxxxxxxxxxxxxxx/account/logout.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
'redirect' => 'https://xxxxxxxxxxxxxxxxx/pages/home.php',
'page_id' => '2'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}

--- End code ---

vom Prinzip ist das wie der Logoutbutton <form...>...</form> im Template oder Droplet (ist das selbe Prinzip) ... und da funktioniert es einwandfrei. Nur eben ohne, dass ich Button drücken muss. Ich möchte nicht mittel JS den Request auslösen (weil JS ja auch aus sein kann)

Als Fehlermeldung bekomme ich zu sehen:

--- Code: ---string(183) "There was an uncatched exception
md5(): Argument #1 ($string) must be of type string, array given
in line (173) of (/framework/Sessions/SameSiteSessionStarter.php):
"
--- End code ---

markherrmann:
Weiß nicht ob das Sicherheitstechnisc h beste Lösung ist aber ich machs erstmal wie folgt:


--- Code: ---function logoutUserNew() {
$page_id = 2;
$redirect_url = 'https://xxxxxxxxxxxxxxx/pages/home.php';

$_SESSION['USER_ID'] = null;
$_SESSION['GROUPS_ID'] = null;
$_SESSION['USERNAME'] = null;
$_SESSION['PAGE_PERMISSIONS'] = null;
$_SESSION['SYSTEM_PERMISSIONS'] = null;
$_SESSION = [];

session_unset();
unset($_COOKIE[session_name()]);
session_destroy();

header('Location: '.WB_URL.'/index.php');
exit;
   
}
--- End code ---

schreibt mir, wenn Ihr anderer Meinung seid.

crnogorac081:
from where are you sending logout request when you use CURL , can you explain ?

markherrmann:
From Frontend...  :?
I create a seperate page (for users) there is a form, where users can press a button that calls my function like this...


--- Code: ---$url_this = WB_URL.$_SERVER['PHP_SELF'];
$url_target = $url_this;    // sometimes i use different targets xml-export or pdf-export (for that this stupid additional var here dont need)
$sec_ftan = $wb->getFtan($wb->createFTAN());
$sec_recordid = $wb->getIdKey('record_id');
$form_name = 'form_'.PAGE_ID;
$msg_confirm = 'bla bla bla\n another bla bla bla';

$ui_start = '...';
$ui_start .= '<form id="'.$form_name.'" name="'.$form_name.'" action="'.$url_this.'" method="post" target="_self" onSubmit="return confirm(\''.$msg_confirm.'\')" />'."\n";
$ui_start .= '<input type="hidden" name="'.$sec_ftan['name'].'" value="'.$sec_ftan['value'].'" />'."\n";
$ui_start .= '<input type="hidden" name="record_id" value="'.$sec_recordid.'" />'."\n";
$ui_start .= '<input type="submit" value="zugang löschen" />'."\n";
$ui_start .= '</form>'."\n";

echo $ui_start;

if (!empty($_POST)) {
if ($wb->checkFtan()) {
if ($sql_result_deactivate) {
confirmMail(); // send mail to user that account is off
logoutUserNew(); // logout user
} else {
// fail msg (maybe)

} // end sql_result...
} // end checkFtan
} // end empty

--- End code ---

crnogorac081:
Is forum wb module or some external ? If it is external you cannot unset Sessions created by wb like that I think. Maybe you Can clear login cookie but pćcookie path must be correct

Navigation

[0] Message Index

[#] Next page

Go to full version