(X)HTML, JavaScript, DHTML, XML, CSS Client scripting tehnologije, Dynamic HTML, Cascading Stylesheets, XML i standardi |
|
Alati teme | Način prikaza |
![]() |
#1 |
član
Na probnom radu
Datum učlanjenja: 04.02.2008
Poruke: 41
Hvala: 13
512 "Hvala" u 1 poruci
![]() ![]() ![]() ![]() ![]() ![]() |
![]() Pozdrav,
Pre svega zelim svima da pozelim srecnu Novu godinu ![]() Imam sledeci problem. Na jednoj strani imam link koji otvara popup prozor u kome se pojavljuje twitter aplikacija za prijavljivanje. Nakon klika na "Allow" popup prozor se zatvara, JS funkcija prikuplja $GET parametre iz URL-a, prosledjuje maticnoj strani i refresuje je sa dodatkom prikupljenih parametara. Problem je sledeci...nakon refresovanja maticne strane, ona ponovo poziva funkciju koja prikuplja $_GET parametre iz URL-a i u konzoli dobijam gresku "Cannot read property 'location' of null"...Evo koda, nadam se da cete mi pomoci ![]() Kôd:
<?php session_start(); require_once 'include/twitter.class.php'; echo "Dobrodosli ".$_SESSION['login']."! <br />"; ?> <script type="text/javascript"> function twitter() { window.open('./login.php?action=twitter','myWin','scrollbars =yes, width=500,height=500'); window.onClick = function(){self.close()}; } function gup( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results != null ) return results[1]; } function callTwitter() { var a = gup('oauth_verifier'); var b = gup('oauth_token'); window.close(); window.opener.location.search = '?oauth_token='+b+'&oauth_verifier='+a; } </script> <a href="javascript:;" onClick="twitter();">Open Window</a> <?php echo ' <a href="?action=twitter">Register Twitter</a><br /> <form action="login.php" method="post"> <input type="submit" name="logout" value="Log Out"/> </form> '; if(isset($_POST['logout'])) { unset($_SESSION['login']); unset($_SESSION['konektovan']); session_unset(); header( "refresh:1;url=index.php" ); } if(isset($_GET['action'])=="twitter") { $t = new Twitter(); $t->twitterLogin(); } if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])) { echo '<script type="text/javascript">callTwitter(); </script>'; echo 'Uspesno konektovanje sa twitterom'; } ?> Twitter funckija Kôd:
<?php include_once("db.class.php"); include_once("twitteroauth.php"); class Twitter { function twitterLogin() { // The TwitterOAuth instance $twitteroauth = new TwitterOAuth('uAVGfCIg9YqVhrmd5Rq1w', '9iqj4SBerAbcJ0uUnnbaAZn2o9OPFiTmIE9VVErJRy0'); // Requesting authentication tokens, the parameter is the URL we will be redirected to $request_token = $twitteroauth->getRequestToken('http://localhost/sea/login.php'); // Saving them into the session $_SESSION['oauth_token'] = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; // If everything goes well.. if($twitteroauth->http_code==200) { // Let's generate the URL and redirect $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']); $_SESSION['konektovan'] = "Konektovan"; header('Location: '. $url); } else { // It's a bad idea to kill the script, but we've got to know when there's an error. die('Something wrong happened.'); } } function registerTwitter($username) { $config = new config("localhost", "root", "", "seadb", "sea_", "mysql"); $db = new Db($config); $db->openConnection(); if($db->pingServer() == true) { $sql = $db->query("INSERT INTO {twitter}(id) SELECT id FROM {user} WHERE username='".$username."'"); } } } ?> |
![]() |
![]() |
Alati teme | |
Način prikaza | |
|
|