Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2013, 01:47 AM   PM User | #1
v0idmp3
New to the CF scene

 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
v0idmp3 is an unknown quantity at this point
Parent-Child window problem

Hi,

First, at all, I want to wish happy new year for all members

I have a little problem. I have one php page with link for authorization on Twitter. When user click on that link, he gets popup window for allowing twitter application, and then popup automaticly close, send informations from URL (oauth_token etc) from PopUp window to parent window, and after that user get a little message. Here is the problem. When I send 'get' data from url to parent window, and auto-refresh parent window, it again calls JS function for getting parameters from URL and I get error "cannot read property 'location' of null"...My english is poor, so here my code and I hope that you help me

Code:
<?php
session_start();
require_once 'include/twitter.class.php';
echo "Welcome ".$_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();">Register Twitter</a>
<?php 
echo '


<form action="login.php" method="post">
<input type="submit" name="logout" value="Log Out"/>
</form>
';
if(isset($_POST['logout']))
{
	unset($_SESSION['login']);
	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 'Successful connecting with twitter';
}
	



?>
Twitter Class
Code:
	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']);
			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.');
		}
	}
v0idmp3 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:37 PM.


Advertisement
Log in to turn off these ads.