Jump to content

dflow

Members
  • Posts

    631
  • Joined

  • Last visited

Everything posted by dflow

  1. after inserting data i get 0 sometimes i created a mysql_connect for it <?php $maincon = mysql_connect('local', "root", "root"); mysql_select_db("root"); then //insert and $success = mysql_query($query); echo $ref_id = mysql_insert_id($maincon); ?> $ref_id is returned as 0, although the connection is there var_dumping the query returns the values
  2. they are empty i var_dumped($picture) $picture=array(); does not set it as an array when doing this: var_dump($pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue); i get results??
  3. still nada
  4. nothing is echoed for the second foreach??? :confused: foreach($pictures as $picture) -im breaking cause it's a large file $doc = new DOMDocument(); $doc->load('accommodation.xml'); $i = 0; $accommodations = $doc->getElementsByTagName('accommodation'); foreach($accommodations as $accommodation) { if(++$i > 2) break; $supplierID = $accommodation->getElementsByTagName('code')->item(0)->nodeValue; $pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue; $pictures=array(); foreach($pictures as $picture) { echo $url = $picture->getElementsByTagName('url')->item(0)->nodeValue; } }//end //XMl schema <?xml version="1.0" encoding="utf-8"?> <accommodations> <accommodation> <code>1</code> <pictures> <picture> <url>http://example.com/images.k.jpg</url> </picture> </pictures>
  5. I did that before with a php loop, i was wondering if there is a way to recognize the end of the concatenated textfield to change and add to the end part inside mysql example: TEXT1(<BR> at the end)+TEXT2(<BR> at the end) --> NEWTEXT(<BR> at the end) update [table_name] set [NEWTEXT] = replace([NEWTEXT],'[<BR>]','[<BR> New Title]');
  6. how can one add text at the end of a BLOB/text field like insert '.<br><br>'
  7. i didn't notice i created a new word
  8. i'm redirecting: but my session is destroyed. i tried to use session_write_close(); to maintain , but nada. the page is redirected blank session_write_close(); $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['SCRIPT_NAME']; $params = $_SERVER['QUERY_STRING']; $currentUrl = $protocol . '://' . $host . $script; if ($host<>'example.com'){ session_write_close(); header("Location: https://www.example2222.com"); } else{}
  9. im trying to use the : https://github.com/facebook/php-sdk to get the current logged in user to facebook the problem is that im getting an old session each time. i have an app which is inside a facebook iframe. here is some code i found but it isn't returning the current user: <?php require_once('facebook.php'); // Print an individual cookie echo $_COOKIE["fbsr"]; echo $HTTP_COOKIE_VARS["fbsr"]; // Another way to debug/test is to view all cookies // after the page reloads, print them out if (isset($_COOKIE['cookie'])) { foreach ($_COOKIE['cookie'] as $name => $value) { $name = htmlspecialchars($name); $value = htmlspecialchars($value); echo "$name : $value <br />\n"; } } // Remember to copy files from the SDK's src/ directory to a // directory in your application on the server, such as php-sdk/ // Create our application instance // (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => 'xxxxxxxxxxxx', 'secret' => 'xxxxxxx', )); // Get User ID $user = $facebook->getUser(); // We may or may not have this data based // on whether the user is logged in. // If we have a $user id here, it means we know // the user is logged into // Facebook, but we don’t know if the access token is valid. An access // token is invalid if the user logged out of Facebook. if ($user) { echo 'user'; try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } // Login or logout url will be needed depending on current user state. if ($user) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl(); } // This call will always work since we are fetching public data. ?> <!doctype html> <html xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <title>php-sdk</title> <style> body { font-family: 'Lucida Grande', Verdana, Arial, sans-serif; } h1 a { text-decoration: none; color: #3b5998; } h1 a:hover { text-decoration: underline; } </style> </head> <body> <h1>php-sdk</h1> <?php if ($user): ?> <a href="<?php echo $logoutUrl; ?>">Logout</a> <?php else: ?> <div> Login using OAuth 2.0 handled by the PHP SDK: <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> </div> <?php endif ?> <h3>PHP Session</h3> <pre><?php print_r($_SESSION); ?></pre> <?php if ($user): ?> <h3>You</h3> <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> <h3>Your User Object (/me)</h3> <pre><?php print_r($user_profile); ?></pre> <?php else: ?> <strong><em>You are not Connected.</em></strong> <?php endif ?> </body> </html>
  10. ok got these scripts //login page $_SESSION["userCakeUser"] = $loggedInUser; $_SESSION['start'] = time(); // taking now logged in time $_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 1 minute for testing } //session timetout include on all pages //Session Destroy if(isUserLoggedIn()){ $now = time(); // checking the time now when home page starts $_SESSION['expire']; if($now > $_SESSION['expire']) { session_destroy(); } } is the logic correct? it doesnt destroy the session i want to force the user to login each time session was expired
  11. yes thanks, marked im running it locally, my mac is handeling it OK , through a GUI terminal, i got server shutdown on my VPS, don't know why, anyways, im doing currently 1 million at a time and i removed a section from the former query UPDATE worldcitylist INNER JOIN worldregionlist as country ON (worldcitylist.countrycode=country.countrycode) SET worldcitylist.country_id = country.country_id WHERE id BETWEEN 1000000 AND 2000000
  12. what would be the best way to automate/force session destroy and cookie erase i have a facebook iframe, with facebook login which gets the activation token now the user is not logged out from the login script after he logs out of facebook. any ideas how to force cookie timeout without a logout button? im playing with <?php session_start(); //Global User Object Var //loggedInUser can be used globally if constructed if (isset($_SESSION['userCakeUser'])) { $obj = casttoclass('stdClass', $_SESSION['userCakeUser']); $_SESSION['userCakeUser'] = $obj; $_SESSION['start'] = time(); // taking now logged in time $_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 1 minute } if(isset($_SESSION["userCakeUser"]) && is_object($_SESSION["userCakeUser"])) { $loggedInUser = $_SESSION["userCakeUser"]; } ?>
  13. i manage to ALTER TABLE worldcitylist ADD id INT NOT NULL AUTO_INCREMENT UNIQUE; then i use your between suggestion thanks
  14. the lat and lng are unique, city names aren't
  15. i have no warnings i had an issue with mysql server timeouts which i fixed when running this query it doesnt execute, how do i use the UID method to split the query into parts, maybe the size of the table isn't letting it execute UPDATE worldcitylist INNER JOIN worldregionlist as country ON (worldcitylist.countrycode=country.countrycode) INNER JOIN worldregionlist as region ON (worldcitylist.region_id = region.region_id) SET worldcitylist.country_id = country.country_id
  16. this script works without a problem outside facebook when included in an facebook iframe it doesnt redirect correctly in firefox i am prompted with resend and IE 8.9 retry window. something with the flow? <?php /* UserCake Version: 1.4 http://usercake.com Developed by: Adam Davis */ require_once("../userCake/models/config.php"); //Prevent the user visiting the logged in page if he/she is already logged in //if(isUserLoggedIn()) { header("Location: account.php"); die(); } ?> <?php define('YOUR_APP_ID', 'xxxxxxxxxxxxxxx'); define('YOUR_APP_SECRET', 'xxxxxxxxxxxxxx'); function get_new_facebook_cookie($app_id, $app_secret) { $signed_request = parse_signed_request($_COOKIE['fbsr_' . $app_id], $app_secret); // $signed_request should now have most of the old elements $signed_request[uid] = $signed_request[user_id]; // for compatibility if (!is_null($signed_request)) { // the cookie is valid/signed correctly // lets change "code" into an "access_token" $access_token_response = @file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=$app_id&redirect_uri=&client_secret=$app_secret&code=$signed_request[code]"); parse_str($access_token_response); $signed_request[access_token] = $access_token; $signed_request[expires] = time() + $expires; } return $signed_request; } function get_facebook_cookie($app_id, $app_secret) { $args = array(); parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args); ksort($args); $payload = ''; foreach ($args as $key => $value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . $app_secret) != $args['sig']) { return null; } return $args; } function parse_signed_request($signed_request, $secret) { list($encoded_sig, $payload) = explode('.', $signed_request, 2); // decode the data $sig = base64_url_decode($encoded_sig); $data = json_decode(base64_url_decode($payload), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') { error_log('Unknown algorithm. Expected HMAC-SHA256'); return null; } // check sig $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); if ($sig !== $expected_sig) { error_log('Bad Signed JSON signature!'); return null; } return $data; } function base64_url_decode($input) { return base64_decode(strtr($input, '-_', '+/')); } $cookie = get_new_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET); if (!empty($cookie['access_token'])) { $fb = array(); $fb['access_token'] = $cookie['access_token']; $fb['uid'] = $cookie['uid']; $fb['sig'] = $cookie['sig']; $fb['session_key'] = $cookie['session_key']; $user = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' .$cookie['access_token'])); //$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' .$cookie['access_token'])); $fb['email'] = $user->email; /** * After getting all the facebook parameters (need to check if we got email the access_token is ok * if we don't have email the access_token is not valid and we need to unset it and make the user * login again. * * Now we need to check if the user is in the usercake DB. * If the user exists we just need to log him in into usercake without a password. * If the user don't exists we will need to add him to usercake database. * Then we will need to log him in. * */ //email not empty if (!empty($fb['email'])) { require_once '../database_connection.php'; $password = 'fb_user'; $username = $fb['uid']; $email = $fb['email']; $query = 'SELECT User_ID from userCake_Users WHERE Email = \''.$fb['email'].'\''; $results = mysql_query($query); if (mysql_num_rows($results) == 0) { //user doesn't exists need to create him //$query = 'INESRT INTO userCake_Users(Username,Username_Clean,Password,Email,ActivationToken,LastActivationRequest,LostPasswordRequest,Active,Group_ID,SignUpDate,LastSignIn,fb_token,fb_uid,fb_sig,fb_session_key) values(' //.'\''.$fb['uid'].'\',\''.$fb['email'].'\',' //.'\''.$fb['uid'].'\',\''.$fb['email'].'\',' $user = new User($username,$password,$email); if(!$user->userCakeAddUser()) { //an error has occured die("error 112413"); } $userdetails = fetchUserDetails($username); //need to activate the user and update the facebook parameters after we added the user. $update = 'UPDATE userCake_Users SET Active = 1, fb_token = \''.$fb['access_token'].'\',' .'fb_uid = \''.$fb['uid'].'\', fb_sig = \''.$fb['sig'].'\', fb_session_key = \''.$fb['session_key'].'\' WHERE User_ID=\''.$userdetails['User_ID'].'\''; mysql_query($update); } else { //user already exists. //lets just update the facebook data $userdetails = fetchUserDetails($username); $update = 'UPDATE userCake_Users SET Active = 1, fb_token = \''.$fb['access_token'].'\',' .'fb_uid = \''.$fb['uid'].'\', fb_sig = \''.$fb['sig'].'\', fb_session_key = \''.$fb['session_key'].'\' WHERE User_ID=\''.$userdetails['User_ID'].'\''; mysql_query($update); } //make user logged-in according to userCake. $loggedInUser = new loggedInUser(); $loggedInUser->email = $userdetails["Email"]; $loggedInUser->user_id = $userdetails["User_ID"]; $loggedInUser->hash_pw = $userdetails["Password"]; $loggedInUser->display_username = $userdetails["Username"]; $loggedInUser->clean_username = $userdetails["Username_Clean"]; //Update last sign in $loggedInUser->updateLastSignIn(); $_SESSION["userCakeUser"] = $loggedInUser; //move user to logged in page.. header("Location: /apartmentsManagment.php"); die(""); } } else { //unset cookie if there is no uid and access token unset($cookie); $cookie = false; } ?> <html> <head> <script id="facebook-jssdk" src="//connect.facebook.net/en_US/all.js"></script> </head> <body> <?php if ($cookie) { ?> Welcome <?= $user->name ?> <?php } else { ?> <fb:login-button scope="email,offline_access"></fb:login-button> <?php } ?> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId : '<?= YOUR_APP_ID ?>', status : true, cookie : true, xfbml : true, oauth : true }); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); window.fbAsyncInit(); </script> </body> </html>
  17. how do i do that?
  18. yep i dont get it myself, i have 0 affected rows ... i thought it's something to do with the float structure.
  19. gotchya index the 7mil records
  20. how would i do that?
  21. ok i use a GUI interface for the terminal well i hope im not going to damage my server how would i access the shell and run : mysql -u root -p mysql then : shell> mysql --max_allowed_packet=32M
  22. well if you have any idea how to deal with this: Lost connection to MySQL server during query.Read timeout (600 seconds) reached. – 600668 ms im running on a localmachine
  23. BTW apparently you can't use LIMIT with UPDATE and JOINS , well im running your query , no errors yet and it is running how long should this take?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.