Ever wondered how to keep your original session ID thru a redirect or reloaded?
For me, that was a long run but now here's the deal.
In this example, we have two servers, one for login and the other for processing the credentials. Remember, they are both child domains.
Server 1: auth.domain.com
Server 2: web.domain.com
You login in a page on auth.domain.com. You have to start your a session with:
<?php
$anything = session_name("nostromo"); // that's the point
session_set_cookie_params(0, '/', '.domain.com'); // It's pretty funny that MSIE will need this but FF and Chrome won't.
session_start();
echo "ID: ".session_id(); // check your id
[.......authentication and other security stuff......]
header ('Location: http://web.domain.com/index.php?'.$mysecurestring ); // mysecurestring contains some encrypted data, including my session_id
?>
On web.domain.com:
<?php
[...]
if ( isset( $_GET['id'] ) && !empty( $_GET['id'] )){
[....decrypting and validating your data, logging etc...and:]
session_id($my_received_secured_session_id);
echo '<script>
window.location = window.location.href.split("?")[0];
</script>';
}
else {
$anything = session_name("nostromo");
session_start();
echo "We happy Vincent? ".session_id();
}
?>
Getting work this single piece of code has taken me two hectic days.
A következő címkéjű bejegyzések mutatása: php. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: php. Összes bejegyzés megjelenítése
2013. november 14., csütörtök
2013. március 5., kedd
my little handy backup from php
<?php
if ($_POST){
$nap=stripslashes($_POST['nap']);
exec ("find /var/www/ize -not -name \"backup_*\" -a -not -name \"backup.php\" -a -not -name \"*.zip\" -a -not -name \"error.log\" -a -not -path \"*/zend*\" -a -not -path \"*tmp/*\" -a -not -path \"*images/*\" -a -not -path \"*fotok*\" -type f -mtime -$nap > lista");
$fajl = "backup_".`date +%F_%H%M`.".tar.gz";
$output = `tar -cvzf /var/www/ize/backup_\`date +%F_%H%M\`.tar.gz --files-from lista`;
echo "DONE!";
echo "<a href=\"$fajl\">backup</a>";
echo "<pre>$output</pre>";
} else {
?>
<form action="backup.php" method="post">
file age limit to be backuped ?
<input type="text" name="nap" id="nap" cols="2" rows="1">
<button class="button" type="submit">GO</button>
</form>
<?php }; ?>
Feliratkozás:
Bejegyzések (Atom)