简体   繁体   中英

pass the url from php via javascript pop-up

url.php

<?php
include "../googlelogin/src/Google_Client.php";
include "../googlelogin/src/contrib/Google_Oauth2Service.php";
include "../fblogin/src/facebook.php";
//FOR FACEBOOK LOGIN//
    $fbconfig['appid' ]     = "329433909112888";
    $fbconfig['secret']     = "ca2bdc9990b0b2ad0763abcka79dce60c91f";
    $fbconfig['baseurl']    = "http://localhost/sbs/fblogin/index.php?rd=hm";
    $facebook = new Facebook(array(
        'appId'  => $fbconfig['appid'],
        'secret' => $fbconfig['secret'],
        'baseurl'=>$fbconfig['baseurl'], 
        'cookie' => true,
    ));
    $loginUrl   = $facebook->getLoginUrl(
        array('redirect_uri'=>$fbconfig['baseurl'], 
        'scope'  =>            'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,   user_hometown,user_photos ,user_work_history',
    )
    );
//FOR GOOGLE LOGIN//
    $client = new Google_Client();
    $client->setApplicationName("Google UserInfo PHP Starter Application");
    $client->setApprovalPrompt('auto');
    $client->setClientId('777637661406-cp7kekelp1l5i0se9f576sqf36a0q4lc.apps.googleusercontent.com');
    $client->setClientSecret('uztEmqG1CFt06752lqtRZjZ-');   
    $client->setState('hm');
    $client->setRedirectUri('http://localhost/sbs/googlelogin/index.php');
    $client->setDeveloperKey('AIzaSyD3HiHElDciE6Pb5UfZtDdNWe_kiKNk6rg');
    $oauth2 = new Google_Oauth2Service($client);
    $authUrl = $client->createAuthUrl();

    ?>

I want to pass the FACEBOOK , TWITTER AND GOOGLE url in via java script in the pop up . I know the PHP part but I don't know the JS part

pop.js

function sin(){
    var lbox = new LadduBox();
    lbox.init({"width":495, "height":242, "HTML":'<div style="width:495px; height:242px; background-color:#ffffff; border:2px solid orange;"><table cellspacing="0" cellpadding="0" border="0" align="center" width="485" height="152" style="font-family:arial; font-size:20px; font-weight:bold;"><tr><td align="right" colspan="3"><img src="images/untitled-1.png" style="margin:10px; cursor:pointer;" id="btnClose"/></td></tr><tr><td height="30" colspan="3"> <div style="font-family:arial; font-size:20px; color:#ff6c00; padding-left:200px;">SIGN IN</div></td></tr><tr><td><div style="margin:10px; font-size:14px;">EMAIL<br><input type="text"/></div><br><div style="margin-left:10px; margin-top:-10px; font-size:14px;">PASSWORD<br><input type="text"/></div></td><td><img src="images/orbar.png" /></td><td align="center"><img src="images/redfb.png" style="margin-bottom:7px;"/><br><img src="images/redgoogle.png" style="margin-bottom:7px;"/><br><img src="images/redtwitter.png" /></td></tr></div>', 'btnCloseId':'#btnClose'});
    lbox.fire();
}

When the user click on the sign-in button , this pop-up will show . I want FACEBOOK , TWITTER AND GOOGLE URL in the pop-up but i don't know how to pass it in javascript .

"When the user click on the sign-in button, this pop-up will show":

Now, the popup code will be inside a PHP file. Include url.php in this file at top, then you can access those $authUrl or $loginUrl anywhere in this file.

Now, in your sin(), you have HTML inside your lbox.init. There you can put these urls as below. BUT, REMOVE sin() FROM INSIDE YOUR JS FILE, AND PUT IT IN THE PHP FILE IN HEAD SECTION. Because, JS file cannot have PHP code.

<div style="width:495px; height:242px; background-color:#ffffff; border:2px solid orange;"><a href="<?php echo $loginUrl; ?>">Facebook Login</a><a href="<?php echo $authUrl; ?>">Google Login</a></div>

Just an example, you can put this anywhere you want within the html. If you want to put PHP inside .js file, you have to do something like below:

AddType application/x-httpd-php .js

AddHandler x-httpd-php5 .js

<FilesMatch "\.(js|php)$">
 SetHandler application/x-httpd-php
</FilesMatch>

Add the above code in .htaccess file and run php inside js files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM