I have a php file containing my website's login script.
If the user doesn't enter the correct password, then the else is executed (see code below):
PHP
else {
echo "<script type='text/javascript'>";
echo "$('.error').replaceWith('<h2>Your password is wrong!</h2>')";
echo "</script>";
}
and I have a blank h2 for the error to be replaced onsubmit:
<div id="error_space">
<h2 class="error"></h2>
</div>
The only problem is that the error won't get replaced...
Hope that someone can help!
EDIT: I echoed it directly as suggested below.
Thanks.
You're missing a ' from your line
echo "$('.error').replaceWith('<h2>Your password is wrong!</h2>)";
^ here
u just forgot '
else {
echo "<script type='text/javascript'>";
echo "$('.error').replaceWith('<h2>Your password is wrong!</h2>')";
echo "</script>";
}
Related
I am very new at PHP and I don't even know if this is possible but I was wondering if it was possible to only show the comment section only if the user is logged in. I use the following the check if the user if logged in or not.
<?php if (isset($_SESSION['name'])){
/* this displays the comment section */
<div class="fb-comments" data-href="https://mywebsite.com" data-width="650" data-numposts="10"></div>
} else {
echo "Please login";
}
?>
do it like this and let me know.
<?php if (isset($_SESSION['name'])){ ?>
<div class="fb-comments" data-href="https://mywebsite.com" data-width="650" data-numposts="10"></div>
<?php } else {
echo "Please login";
}
?>
enclose the div to echo. Everytime you want to print HTML code inside of a PHP code just print it using echo "html code here";
echo '<div class="fb-comments" data-href="https://mywebsite.com" data-width="650" data-numposts="10"></div>';
I want to bind the complete URL in a PHP variable.
My URL looks like this: http://develop.example.com/spf#users/admin.
To get the URL I use following:
http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]
and for the hash value is use this JS:
document.write(window.location.hash);
So my PHP variable looks like below:
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"."<script>document.write(window.location.hash);</script>";
When I echo the $current_url I get this output: http://develop.example.com/spf#users/admin.
Now I want to have a check on the current URL:
if ($current_url != "http://develop.example.com/spf#users/admin") {
echo "you are NOT the admin";
}
else {
echo "you are the admin";
}
Unfortunately, even when the URL is exactly the same, he keeps hanging on: "you are NOT the admin".
What is going wrong here?
you can use following script and your code is correct but the problem is "document.write(window.location.hash);" this code remove it then run
<?php
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$match="http://localhost:900/at/";
// echo base64_encode($current_url);
// echo "<br>";
// echo base64_encode($match) ;
if ($current_url==$match) {
echo "you are the admin";
}
else {
echo "you are NOT the admin";
}
?>
i have a problem in PHP, i want first show a message like this:
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
and when i clicked on ok, then redirect to another page, my code is like this:
$fgmembersite->RedirectToURL("home2.php");
complete code:
if(isset($_POST['submitted']))
{
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
$fgmembersite->RedirectToURL("home2.php");
}
but this code do not show me the message just redirect to home2.php, if there is another way except of 'if' please explain. the simplest way
thanks
If you just want to redirect to another page.. you can do this:
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
echo '<script>window.location.href = "the-target-page.php";</script>';
you should use javascript o redirect only. You are trying to mix, both php and javascript
echo "<script>javascript:alert('message successfully sent'); window.location = 'home2.php'</script>";
I have an index.php for registration, a login.php as the registration handler. when the registration is failed, it sent out the error message to client. I use this code for sending out the message
header('Location: http://localhost/musicshare/index.php?reg=false');
and receive in index.php
if(isset($_POST['reg'])){
echo 'set';//for checking whether reg is set
if($_POST['reg']=='false'){
echo '<script type="text/javascript">';
echo 'alert("Reg faile")';
echo '</script>';
}
}
However, It seems not working at all; Please help, thanks.
Use $_GET instead of $_POST:
if (isset($_GET['reg']) && $_GET['reg'] == 'false'){
// do something
}
When you use a header() it fires a GET request.
So you should use $_GET['reg']
if(isset($_GET['reg'])){
echo 'set';//for checking whether reg is set
if($_GET['reg']=='false'){
echo '<script type="text/javascript">';
echo 'alert("Reg faile")';
echo '</script>';
}
}
i'm triying to use javascript redirect to main window after log in succeed in an iframe.
this is my code :
if ($_GET['redirect']!='') {
$redirect=$_GET['redirect'];
$smart->assign('redirect',$redirect);
}
$redirect=$_GET['redirect'];
echo $redirect;
if(isset ($_SESSION['user'])&&$_SESSION['user']!='') {
$user->email=$_SESSION['user'];
$user->addCorporate();
$user->signIn();
$user->loadSession();
echo("<script language=\"javascript\" type=\"text/javascript\">");
echo "document.write('redirecting...');";
if ($redirect!='') {
echo 'self.parent.location = "'.$redirect.'"';
} else
echo 'self.parent.location = "index.php"';
//echo $redirect;
// redirect($redirect);
echo "</script>";
}
the echo $redirect displays http://xxxxxxxx/play.php?action=play&id=d59541b89828da34e9a8345a1bdafe2b
but the redirection is made to http://xxxxxxxx/play.php? (without the php option)
This sounds pretty mysterious.
Here's how I'd proceed: Turn off JavaScript in your browser and examine your created JavaScript. Then, at least, you know whether maybe for some bizarre reason the wrong URL is print out after all, or whether the problem's in the redirection part.
If you change the line:
echo 'self.parent.location = "'.$redirect.'"';
to this:
echo 'alert("'.$redirect.'")';
What happens?