My file structure
front-page
homepage.html
lib
.js
.php
I send the user information to server and doing server side validation. If server side validation fails, i want to load my html page and open log in window if email already exists. I have done the following
if(isset($_POST['submit']) && $_POST['email']!='')
{
$email= $_POST['email'];
$sql1 = "SELECT * FROM Users WHERE emailID = '$email'";
$result1 = mysqli_query($connection,$sql1) or die("Oops");
if (mysqli_num_rows($result1) > 0)
{
//echo "This Email is already used.";
//Write code to go back to register window
//header('Location: ../homepage.html');
echo '<script type="text/javascript">
console.log("cdsafcds");
//jQuery.noConflict();
$(".login_links_login").trigger("click");
</script>';
}
}
I don't see any errors and it isnot triggering the click too. I don't have any restrications. Please provide me the best way to do these kinda stuff. I checked with few sites they loads the separate page if php call fails. But i want to know why can't we do it in the same page if so.
HTML:
<!----head>
<script type="text/javascript" src="lib/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="lib/jquery-validate.min.js"></script>
<script type="text/javascript" src="lib/homepage.js"> </script>
<link rel="stylesheet" type="text/css" href="lib/homepage.css" />
</head!--------->
<form method="POST" action="lib/login_validate.php" class="loginDiv right" id="loginForm">
content goes here
</form>
Submit click: is handled by jquery
Please let me now if any data further needed
Related
Hii Everyone,
Here is my code for facebook Signin.i got this example from http://www.codexworld.com/login-with-facebook-using-php/. here is my index page code
PHP code
<?php
include_once("config.php");
include_once("includes/functions.php");
//destroy facebook session if user clicks reset
if(!$fbuser){
$fbuser = null;
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
$output = '<a class="myLink" href="'.$loginUrl.'">Click Here To Proceed</a>';
}else{
$user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,birthday,picture');
$user = new Users();
$user_data = $user->checkUser('facebook',$user_profile['id'],$user_profile['first_name'],$user_profile['last_name'],$user_profile['email'],$user_profile['gender'],$user_profile['birthday'],$user_profile['picture']['data']['url']);
if(!empty($user_data)){
$output = 'Thanks For Register With Spark.You Should Receive Confirmation Mail Shortly';
}else{
$output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Spark Login with Facebook</title>
<style type="text/css">
h1{font-family:Arial, Helvetica, sans-serif;color:#999999;}
</style>
</head>
<body>
<div>
<?php echo $output; ?>
</div>
</body>
</html>
Here i use a href to show facebook login.after te click of href it will redirecting to facebook login instead automatically want to click and it will redirect the page.Is there any possible way to do that.If anyone know the solution for the problem please help me!!
Why not do this with header location? Here´s how that works: PHP header(Location: ...): Force URL change in address bar
For example:
$loginUrl = $facebook->getLoginUrl(array('redirect_uri' => $homeurl, 'scope' => $fbPermissions));
header("Location: " . $loginUrl);
Official docs: http://php.net/manual/function.header.php
No need for using an $output variable, or for creating a login page (if you want to auto-redirect anyway). Just redirect the user if he is not logged in yet. No need to do something shady like "auto-clicking the login button". It´s not a solution, it´s a bad workaround. Although, it would be a lot better if you would let the user click it. Redirecting to the login page without a proper intro page, where he can see what the App is about, is not a good idea.
Even better: Use the JavaScript SDK for login: http://www.devils-heaven.com/facebook-javascript-sdk-login/
If you want to change the webpage's URL, you do not need to use jQuery to click the link. Instead, there is a simpler way.
JS:
window.location = "http://www.example.com/";
By changing the window.location, you can "redirect" to a new URL.
If you want to redirect only after an event, you can put that in a function of yours.
Example:
window.location = "http://www.example.com"
I'm working on a database of people on a WordPress site usin this plugin.
I want the LinkedIn Member Profile Plugin to display for each person in the database, but the user should only have to enter his/her own LinkedIn-URL and not all of the js code, which is:
<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/MemberProfile" data-id="LINKEDIN_PROFILE_URL" data-format="inline" data-related="false"></script>
I created a custom PHP template to achieve this, but it doesn't display as expected. What I have now is:
if($this->field->name === 'linkedin_badge') : ?>
<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/MemberProfile" data-id="<?php echo $this->field->print_value() ?>" data-format="inline" data-related="false"></script>
<?php else : ?>
<?php endif;
where the field 'linkedin_badge' is where I ask users to type their LinkedIn-URL, but it only displays a small LinkedIn icon and not the larger LinkedIn-badge.
What am I doing wrong?
I have a form in a page that submits to itself. In the PHP portion I check
if($_SERVER['REQUEST_METHOD'] == 'POST')
and then I run few things. I am attempting to show an alert using the Alertify suit if something was posted. But on page load I get error
alertify is not defined
I guess it only does that because the page did not load the include links to the js/css files yet (looking in FireFox's FireBug I see the Alertify script line loading before the <html> tag). What can I do to make it work right?
UPDATE CODE:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<script type="text/javascript">alertify.alert("Hello");</script>';
}
?>
<html>
<head>
<title>Hello There</title>
<!-- Alertify Includes -->
<script type="text/javascript" src="alertify.js"></script>
<link rel="stylesheet" type="text/css" href="alertify.core.css">
<link rel="stylesheet" type="text/css" href="alertify.default.css">
</head>
<body onLoad="onLoad()">
<form action="" method="POST" id="CONFIRM">
<input class="txt" value="" type="text" name="myName" id="myID" onKeyUp="" onChange="" onFocus="" />
</form>
</body>
</html>
After you posted the sources, I think I know what is wrong:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<script type="text/javascript">alertify.alert("Hello");</script>';
}
?>
is located above the script tag that loads your javascript. This means that any code in the PHP segment is executed before that code. In other words, alertify has not yet been defined there.
To resolve this, place a PHP echo inside the head, below the include for alertify, or include the alertify as a separate echo in the PHP, example:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<script type="text/javascript" src="alertify.js"></script>'
echo '<script type="text/javascript">alertify.alert("Hello");</script>';
}
?>
Make sure that you include the script tag for alertify in the of your HTML document.
<script src="PATH_TO_FILE/alertify.min.js"></script>
(Code snipped from alertify's main page)
If you have included a script tag, hit f12 and ctrl-f5 the page, make sure the path to the script is not reutrning a 404.
It is because truely, alertify wouldn't have been defined as at the time you called it, because the script file has not been loaded yet.
Try putting the code
alertify.alert("Hello");';}
?>
after linking to the scripts.
Put it below tag and it'll work.
I have a javascript bootkmarklet that the user can load into what ever webpage they are on.
This then displays a php generated page over the top of the current webpage, this includes some information that the javascript has take from the page the user is on.
What I now need is to be able to have the javascript first run one php file that connects with a mysql database, have the result from the database returned to the javascript which can then call the php file that generates the page overlay.
What I am looking for really is a way for the process to go:
User runs javascript --> javascript runs php for mysql --> javascript gets mysql result back --> javascript runs second php file
Here is a starting point of how to use the ajax features in JQuery.
Edit - separate javascript file
html file:
<html>
<head><title> Ajax test page</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="ajaxfunctions.js"></script>
</head>
<body>
<div id="ajaxResult"></div>
</body>
</html>
js file called 'ajaxfunctions.js':
$(document).ready(function() {
$("#ajaxResult").load("ajaxHello.php");
});
php file called 'ajaxHello.php':
<?php
header("text/html");
echo "hello from php";
?>
To read data from a database the php code needs to be a little longer:
<?php
header("text/html");
$username = "root";
$password = "";
$databaseName = "mydatabase";
$connect = mysql_connect("localhost",$username,$password);
if (!$connect) die("Connection Error");
$result = mysql_select_db("$databaseName");
if(!$result) die("Select DB Error");
$result = mysql_query("select email from users where firstname='Abbey'");
if (!$result) die('Invalid query: ' . mysql_error());
$row = mysql_fetch_assoc($result);
echo "Abbeys email address ".$row['email'];
?>
This examples looks up Abbeys email address from the users table in the users database and returns it. The Database name, username and password are all set at the top of the script.
Usually the ajax request passes some data from the html page, I am happy to add this code if this helps.
Is this something like what you are looking for?
a page directs users back to a page automatically
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php">
when it reaches 'Untitled9.php' i want it to display an alert box saying 'Message sucessfully posted'
I only want it to display when it id directed back to the page and not when first load
e.g Home - Message page = No alert
Home - message page - submit - redirect to message page = alert 'post sucessfully posted'
Can't control the DOM of a page externally.
What you could do however is pass a variable in the query string to the page you're redirecting to like this
Untitled9.php?message=success
Then on your new page have
<?php
session_start();
if ($_GET['message'] == "success" && $_SESSION['revisit'] == "0")
{
$_SESSION['revisit'] = "1";
?>
<script type="text/javascript">window.alert('Message successfully posted.');</script>
<?php
}
?>
In your first page change your code to look like this
<?php
session_start();
$_SESSION['revisit'] = "0";
?>
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php">
If I understand your question correctly, this should work for you (assuming you alter the keys for the $_POST variables accordingly, of course):
<?php (isset($_POST['my_sub_btn'])): ?>
<script type="text/javascript">window.alert('Message successfully posted.');</script>
<?php endif ?>
Assuming you're submitting the message from a form, there should be no reason to redirect using a HTML redirect. Set the action attribute of your form to Untitled9.php and it will handle the rest...
Given your requirements, why not set a parameter on succes? Such as:
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php?success=1">