Jump to content

Search the Community

Showing results for tags 'sessions'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH


  • Community Calendar

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Found 5 results

  1. I have a session running after someone registers and log into my page and i want to use that session ID How can i use the session id to store new information into a other mysql database and when the same user logs in retrieve it again from that database? I want that the user log into the page and then create a character. I just don't know how to bind it together. I made a new page where you need to create/select Character name, $ex, Race, Home world and a new table called "players" with those 4 in it plus id and User_id how would i code it so that the users session ID from the register page combines with the info he/she filled in the player creation form ? if some one could shove me into the right direction it would make my day This is the session function and log in function. function sec_session_start() { $session_name = 'sessionName'; // Set a custom session name $secure = SECURE; // This stops JavaScript being able to access the session id. $httponly = true; // Forces sessions to only use cookies. if (ini_set('session.use_only_cookies', 1) === FALSE) { header("Location: ../error.php?err=Could not initiate a safe session (ini_set)"); exit(); } // Gets current cookies params. $cookieParams = session_get_cookie_params(); session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); // Sets the session name to the one set above. session_name($session_name); session_start(); // Start the PHP session session_regenerate_id(); // regenerated the session, delete the old one. } function login($email, $password, $mysqli) { // Using prepared statements means that SQL injection is not possible. if ($stmt = $mysqli->prepare("SELECT id, username, password, salt, accdate FROM members WHERE email = ? LIMIT 1")) { $stmt->bind_param('s', $email); // Bind "$email" to parameter. $stmt->execute(); // Execute the prepared query. $stmt->store_result(); // get variables from result. $stmt->bind_result($user_id, $username, $db_password, $salt, $accdate); $stmt->fetch(); // hash the password with the unique salt. $password = hash('sha512', $password . $salt); if ($stmt->num_rows == 1) { // If the user exists we check if the account is locked // from too many login attempts if (checkbrute($user_id, $mysqli) == true) { // Account is locked // Send an email to user saying their account is locked return false; } else { // Check if the password in the database matches // the password the user submitted. if ($db_password == $password) { // Password is correct! // Get the user-agent string of the user. $user_browser = $_SERVER['HTTP_USER_AGENT']; // XSS protection as we might print this value // everything works! //so i could add more to the table and get the info from here $user_id = preg_replace("/[^0-9]+/", "", $user_id); $_SESSION['user_id'] = $user_id; $_SESSION['email'] = $email; $_SESSION['username'] = $username; $_SESSION['accdate'] = $accdate; // XSS protection as we might print this value $username = preg_replace("/[^a-zA-Z0-9_-]+/", "", $username); $_SESSION['username'] = $username; $_SESSION['login_string'] = hash('sha512', $password . $user_browser); // Login successful. return true; //TEST if Login successful add to email and username from members and add to players table } else { // Password is not correct // We record this attempt in the database $now = time(); $mysqli->query("INSERT INTO login_attempts(user_id, time) VALUES ('$user_id', '$now')"); return false; } } } else { // No user exists. return false; } }}
  2. Hopefully someone can help me solve with this "easy" problem! I'm looking for a way to populate data in a Contact Form 7 (WordPress) from session. The session will be started by clicking on a book now button like this: <?php session_start(); if(isset($_GET['bookingdate'])) { $_SESSION['started'] = true;}?><a href="?bookingdate"> Book now </a> After clicking the button and the session is started I want to redirect to the form "booking " page and populate one of the fields with the booking date. The visitor will fill the rest of the form and submits. After submission the session will be destroyed. Would that be possible when using Contact Form 7 and WordPress?
  3. I wonder why session_destroy() does not work on the page (destroy_session.php). Set the session: http://learntolive.x10.mx/PHP/Sessions/set_sessions.php <?phpsession_start();$_SESSION['username'] = "username1";$_SESSION['password'] = "password1";$_SESSION['array'] = array('array0','array1','array2');?><html><head><script type="text/javascript">var sPageFullPath = String(window.location.href);var iDelim = sPageFullPath.lastIndexOf("/");var sPageRootPath = sPageFullPath.substring(0,iDelim+1);var iCount = 3;var iTimerCount = iCount*1000;var sRedirectURL = "get_sessions.php";window.onload = CountdownTimer;function CountdownTimer(){ if (iCount>0) { document.getElementById("CountdownTimer").innerHTML = "This page will redirect in "+iCount+" seconds to " + sRedirectURL; iCount--; setTimeout("CountdownTimer()",iTimerCount); } else { window.location = sPageRootPath + sRedirectURL; }}</script></head><body><p>This page assigns values to SESSION valuables.</p><p id="CountdownTimer"></p></body></html> Get the session: http://learntolive.x10.mx/PHP/Sessions/get_sessions.php <?phpsession_start();echo "This page shows values to SESSION valuables."."<br />";echo "The username is ".$_SESSION['username'];echo "<br />";echo "The password is ".$_SESSION['password'];echo "<br />";echo "The array is ".$_SESSION['array'][2];echo "<br />";foreach ($_SESSION['array'] as $value){ echo $value; echo "<br />";}echo "<hr />";print_r ($_SESSION);echo "<hr />";?><html><head></head><body><a href="destroy_sessions.php" title="This page will destroy the session valuables.">destory sessions</a></body></html> Destroy the session: http://learntolive.x10.mx/PHP/Sessions/destroy_sessions.php <?phpsession_start();echo "This page desttoys the session.";echo "<br />";session_destroy();echo "Those sessions set will not be shown now.";echo "<br />";echo "The username is ".$_SESSION['username'];echo "<br />";echo "The password is ".$_SESSION['password'];echo "<br />";echo "The array is ".$_SESSION['array'][2];echo "<br />";foreach ($_SESSION['array'] as $value){ echo $value; echo "<br />";}echo "<hr />";print_r ($_SESSION);?> On the above PHP page, the session valuables are still shown properly.
  4. Yo W3S again... i have this little project of my own.its a little hard to explain, but also only a theory, so feel free to ask in to it... i have been watching a project called TBdev (its a torrent project, yes, but hear me out first...). i have been trying to see how they have builded up their login system with cookies. and to be more specific, their functions inside the main-file called bittorrent.php. anyways, i am kinda building my own functions for this to work, but im trying to build in a little different way then them... i think... here is my functions: function login_session($db_output, $update_user_db = 0){set_my_session( "uid" );//name the sessionset_my_session( "pass" );//name the sessionset_my_session( "stylesheet" );//name the sessionif ($update_user_db == '1'){ @mysql_query("UPDATE users SET last_login = ".TIME_NOW." WHERE id = $id");}}function set_my_session( $name ){CODE HERE...}function unset_my_session( $session_name ){unset($_SESSION['{$session_name}']);}function logout_session() {unset_my_session('uid');unset_my_session('pass');} now, as you see. then the login_session is the main function here to login with..now, this is my login file: $res = mysql_query("SELECT id, passhash, username, secret FROM users WHERE username = " . sqlesc($username) . " AND status = 'confirmed'");$row = mysql_fetch_assoc($res);login_session($row); now, as you see. im taking ALL my DB info out into the function. now here comes the part from where im a little lost, because now i need to build up the function that builds it.that would be the (set_my_session)... my point is to take ALL rows/data out FROM where the username are...so i can see WHAT the kind of data the user has.... BUT. as you see on the login_session, im trying to give them different names for Each and one, so i can see the difference on them...that is the way the TBdev project did it, and that was the thing that was giving into me mostly... so here comes the question...if i am going to take ALL the data out from DB, and i need to know the different name on each and one.is it possible to take the row/col name... like if one of the rows were named 'user_id', is it possible to use THAT name to the session?, and as you can see here at my project right now, do you think i can get it to work?... -thanks for advice if possible!... EDIT: and ohh, as you see... im also needing to UNSET the sessions again, that is where the names for the different sessions come into the picture, but give me some advice, because im pretty surtent that this one will work, just needing a little advice to go on with... -thanks!...
  5. hello w3schools once again.. was thinking..im building this new website with user-login's to the website.. is it possible to make a box that will show ALL logged in users within like 10 min or so?.. was just thinking about it...if yes, wonna give a clue about it?.. -thanks alot! ...
  • Create New...