Create Cookie with cross domain in laravel - php

I have two laravel project with virtual host name 1) my.dev.com and 2) your.dev.com
I have create api for set cookie for cross domain and api is located at your.dev.com
Route::middleware('cors')->get('/hello', function () {
$cookie = Cookie::make('custom_cookie', 'hello_world', 10, "/", '.dev.com');
return response()->json('Hello worlds')->withCookie($cookie);
});
I make api call from my.dev.com and code is like this
<html>
<head>
<title>CORS</title>
</head>
<body>
<button type="button">Call API</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("body").on("click","button",function () {
$.get("http://my.dev.com/api/hello",function(data){
alert(data);
});
})
});
</script>
</body>
When I click Call API button from my.dev.com I get response Hello worlds but Cookie is not set your.dev.com
Even Cookie not set any .dev.com virtual host
I want to set Cookie at your.dev.com from my.dev.com with help of Ajax and code already posted here.
Your help would be appreciated.

Related

issue with google login with php

I am making google login for my website. I have also set my google console settings in my google developer console. and use this code for google login.
but it shows me an error: 400 redirect_uri_mismatch while I have already set my redirect_url
and my question is different from This question because as we can see in that question redirect_uri is not declared but I have already declared it.
I am showing my code below
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="*********CLIENT-ID********">
<script type="text/javascript">
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}
</script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
Sign out
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
When I click on Google signup button it redirects on URL
https://accounts.google.com/o/oauth2/auth?redirect_uri=storagerelay%3A%2F%2Fhttps%abc.com%3Fid%3Dauth535373&response_type=permission%20id_token&scope=email%20profile%20openid&openid.realm=&client_id=*******&ss_domain=https%3A%2F%2Fabc.com&fetch_basic_profile=true&gsiwebsdk=2
and shows me Error: redirect_uri_mismatch.
I don't know why this happens.
can anybody help me in this.

Login with linkedin javascript SDK

Can any one provide the working example of login with linkedin javascript SDK? I tried many demos but it does not work at all.
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 81yvk0mewiwqa6
authorize: true
onLoad: onLinkedInLoad
scope: r_basicprofile r_emailaddress
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
alert("hi");
IN.Event.on(IN, "auth", getProfileData);
}
// Use the API call wrapper to request the member's profile data
function getProfileData() {
IN.API.Profile("me").fields("id", "first-name", "last-name", "headline", "location", "picture-url", "public-profile-url", "email-address").result(displayProfileData).error(onError);
}
// Handle the successful return from the API call
function displayProfileData(data){
var user = data.values[0];
document.getElementById("picture").innerHTML = '<img src="'+user.pictureUrl+'" />';
document.getElementById("name").innerHTML = user.firstName+' '+user.lastName;
document.getElementById("intro").innerHTML = user.headline;
document.getElementById("email").innerHTML = user.emailAddress;
document.getElementById("location").innerHTML = user.location.name;
document.getElementById("link").innerHTML = 'Visit profile';
document.getElementById('profileData').style.display = 'block';
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Destroy the session of linkedin
function logout(){
IN.User.logout(removeProfileData);
}
// Remove profile data from page
function removeProfileData(){
document.getElementById('profileData').remove();
}
</script>
</head>
<script type="in/Login"></script>
Linked in
I am trying this one also but i am not getting what is the issue.
Also,
<script type="in/Login"></script>
This line is to display linkedin button but it displays nothing!
Can anyone help?
It was not working because the code was not wrapped inside html tag including head and body.
The code which works is here:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: YOUR_API_KEY
authorize: false
onLoad: onLinkedInLoad
scope: r_basicprofile r_emailaddress
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
// Use the API call wrapper to request the member's profile data
function getProfileData() {
IN.API.Profile("me").fields("id", "first-name", "last-name", "headline", "location", "picture-url", "public-profile-url", "email-address").result(displayProfileData).error(onError);
}
// Handle the successful return from the API call
function displayProfileData(data){
var user = data.values[0];
alert(user.emailAddress);
alert(user.pictureUrl);
alert(user.lastName);
alert(user.headline);
alert(user.location.name);
alert(user.publicProfileUrl);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Destroy the session of linkedin
function logout(){
IN.User.logout(removeProfileData);
}
</script>
</head>
<body>
<script type="in/Login"></script>
</body>
</html>

Can't get this AJAX call working in PhoneGap

Using PhoneGap, I'm trying to build a basic android app that makes an AJAX call to a PHP API and return some JSON data. The code, in its entirety works on the desktop, but it doesn't seem to work for my Android when I make a build. When I build the app, install it on my device, and load it up, I get blank screen.
Here's the client that I wrote... Is there anything wrong with this code?
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.css" />
</head>
<body>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the PhoneGap API
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$.ajax({
url: 'http://api.example.com/test.php',
dataType: 'json',
timeout: 5000,
success: function(data, status) {
//data loaded
$('#results').append(data[0].about);
},
error: function() {
//error loading data
$('#results').append('No data received.');
}
});
$(document).ajaxError(function(event, request, settings) {
$("#msg").append("<li>Error requesting page " + settings.url + "</li>");
});
$(document).ajaxComplete(function(event, request, settings) {
$("#msg").append("<li>Request Complete.</li>");
});
}
</script>
<p id="results"></p>
<p id="msg"></p>
</body>
</html>
I also set the access origins in the config.xml to:
<access origin="http://example.com" subdomains="true" />
<access origin="*"/>
It seems that the AJAX code (and the global AJAX event handlers) is not getting called.
Be sure to have cordova.js included in the right location and available (e.g. by alert(<some cordova property>);). Then try if the onDeviceReady is called at all:
document.addEventListener("deviceready", function(){
alert("deviceready");
},false);

Angular.js > how to manage configuration

I got stuck with passing a configuration to our angular application. My problem is
We have configuration is stored in database, so far it's URL of web service to communicate with
Page is rendered by PHP
How can I pass URL stored in database to ng-app?
So far I have hard-coded services.js
app.constant('config', {ws_url: 'ws://domain/ws'});
app.factory('wampy', function ($rootScope, config) {
var url = config.ws_url;
var ws = new Wampy(url, { autoReconnect: true });
return {
something: function () {
console.log(url); // usage of url
}
}
}
Then it is included into main html code (index.php)
<head>
<script type="text/javascript" src="http://dev.local/js/ng/app.js"></script>
<script type="text/javascript" src="http://dev.local/js/ng/services.js"></script>
</head>
But it can be amended / moved to somewhere else.
Any thoughts?
You could have a snippet of javascript rendered by php into a script tag like so
$config = array('ws_url' => 'ws://domain/ws');
$jsonConfig = json_encode($config);
$snippet = <<<EOS
<script type="text/javascript">
angular.module('appName').constant('config', $jsonConfig);
</script>
EOS;
and then output this $snippet somewhere in your page.

pass query string variables without refresh page

My question is that how to pass query string variables on same page without refreshing the page in php? My code is given below:
<img src="a.jpg">
<?php
$a = $_GET['id'];
$b = $_GET['pid'];
?>
Please help me to resolve this issue
<html>
<head>
<title>Test</title>
<meta name="" content="">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#image_id").click(function(){
var dataString = 'a=10&b=20';
$.ajax({
type:'POST',
url:'foo.php',
data:dataString,
success:function(data) {
if(data=="Something") {
// Do Something
} else {
// Do Something
}
}
});
});
});
</script>
</head>
<body>
<img id="image_id" src="images/bg.jpg" />
</body>
</html>
Then in the 'foo.php' page do this
if(isset($_POST['a'])) {
// DO SOMETHING
}
Remember the things that you want to send to the 'data' of
success:function(data)
must be echoed out in the foo.php page
You can't.
PHP requires execution on the server and so you'd have to either use AJAX and update your page accordingly, or just refresh your page.
You can by sending an AJAX request to the server. Ajax is a way to send asynchronous request via Javascript. Notice that jQuery has a good library about it.
Use jquery to resolve this. By using the $.ajax in jquery you can do the stuff you need without page refresh.

Categories