Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
i want to redirect index.php which if user click on logout button it redirects to login.php page but it don't.
http://localhost:/dropedit/GAMEBOX
and if some one type like following it went all wrong like,whole page becomes garbled
http://localhost:/dropedit/GAMEBOX/index.php
logout button code is Logout ?
i tried but din't find some thing!
Make the login button a part of a form, and have the form submit to index.php. The form will contain an empty input that tells the page that you have been logged out. For example:
<form action = '/' method = 'post'>
<input style = 'display: none;' name = 'logout' value = 'logoutTrue">
<input type = 'submit' value = 'Logout'>
</form>
Next, a simple if statement to check if you have been logged out:
<?php
if (isset($_POST['logout'])) {
$logoutVal = $_POST['logout'];
if ($logoutVal === "logoutTrue") {
header("Location: http://localhost/login.php");
}
}
?>
Uh, this should work, I think? If it doesn't please post the error codes.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to pass a variable from one php function to another.
1st function creates a button.
2nd function needs to be able to receive variable that button sent to the 2nd function.
Nothing happens when i click the button. Page just flickers.
<?php
function myFunc(){
$filename = "123";
echo '<form method="post"><input type="submit" name="button1"class="button" value="Button1" onclick="myOtherFunc("tomato")" /></form>';
}
myFunc();
function myOtherFunc($filename){
echo '$filename'."anyting ?" ;
}
Onclick will not execute php code. PHP code is executed on the server BEFORE your page is rendered. Once your page is rendered, the only code that can be executed without reloading the page is Javascript. The onclick attribute on your button will look for a Javascript function called func_ImageView, which does not exist. If you want the content if your func_ImageView function to be called, you need to call that code in php, but you should instead use javascript for this from what it looks like.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a table with add, edit, delete options. Now I want to hide divs with buttons for not logging users.
Or maybe I should make a deactivated buttons for not loggin users?
when user login then you have session like
$_SESSION['email']=$email;
then used this code
<?php
if(isset($_SESSION['email']))
{
echo "<div>any text</div>";
}
?>
do some effort to write the code
Depending on how your site works there are two possible solutions that I can think of.
USE PHP
If the user is logged in then use:
<?php
if ($logged_in) {
?>
<div>Your text here</div>
<?php
}
?>
NOTE: You do not need to use "echo" or "print" if you close and open your PHP tags between the "if" as shown below. This can make the HTML part of the much easier to read and write.
USE JAVASCRIPT
If the page does not reload when the user logs in then you will need to use Javascript to hide and show the DIV using something like:
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a php page wich has a button (index.php), and this php page contains variables and I want to use them in another php script(script.php) in another file but at the same time, I want the user to be redirected to an html page (success.html)
How do I do that?
Set your <form action="script.php" method="post"> in index.php and put this line of code at the end of your script in script.php:
header('location: 'success.html']);
How are you passing your variables to script.php?
If you put this script in script.php:
foreach ($_POST as $key => $value){
$$key=$value;
}
Then it will create variables for all of your form elements with a name="" atribute, and assign them their respective values.
Example:
<input type="text" name="firstname" value="John">
will create the variable
$firstname = 'John';
This is very simple there are several ways of doing this, you can use sessions or set a form to posts the results. So on index.php you could do something like this
<?php
session_start()
$_SESSION['foo'] = 'bar';
header("location:success.html");
?>
you now have global access to $_SESSION['foo'];
<?php
echo $_SESSION['foo']; // will output bar
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have a form where users can register in my site. I distinguish the new users and already registered users from their email. Thus, if an already registered user submits the registration form I would like to direct him to the FORGET PASSWORD page. if a new user submits I would like to direct to the WELCOME TO SITE page.
But, I do not know how to handle the active section of form since the active section just get an URL and users always direct to the given URL.
What can I do about the active section of form? Can I give two URLs and a condition for choosing one of them to the active section?
Best Regards,
Vahid
PHP pseudo-code:
<?php
if(user exists){ $url = "forgetpassword.html"; }
else { $url = "welcome.html";}
?>
HTML pseudo-code:
<form action="<?php echo $url; ?>" />
Something like this?
Lookup the email address in your database.
If found: echo header("Location: url for your forgot password page");
else
echo header("Location: url for your login page");
See: Redirect to specified URL on PHP script completion?
You can do a redirection like this: header('Location: http://www.example.com/');
form
<form method="POST" action="register.php">
...
</form>
register.php
$result = checkRegistration($email,...,...);
if($result) {
header("Location: welcome.php");
} else {
header("Location: password.php");
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm changing for this website's sake...I'm trying to explain that I need something to let registrar create the register form, then if leave oe textbox blank, the click on submit, then JavaScript's alert to tell registrar to fill the blank textbox. I need this in PHP. Thank you for help in advance.
Gary
I didn't see a javascript tag within your question. You can check to see if the text area has been set before writing the database.
<?php
$textArea = $_POST['textAreaName'];
$error = false;
if($_POST) {
if(isset($textArea)) {
// run code and write to DB
} else {
$error = "Please fill out text area";
}
}
?>
HTML
<form.......>
<?php echo $error ? $error :"" ?>
<textarea></textarea>
</form>
Use javascript on the front-end, like so:
if(document.getElementById('InputId').value == ''){alert('fill in the blanks');}
You should always do a check using PHP as well:
if(!isset($_GET['InputId']) || empty($_GET['InputId'])){return false;}