Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
When admin log in to the admin panel it should redirect him to the admin panel and the second time to not, but it always redirecting.
if($logedin_admin='1'){
$logedin_admin=0;
$_SESSION['is_admin']=1;
header('Location: admin/index.php');
}
Can anyone tell me why?
I've made the if:
if(isset($logedin_admin) && $logedin_admin=='1'){
echo 'dsdasdas';
$logedin_admin=0;
$_SESSION['is_admin']=1;
header('Location: admin/index.php');
exit;
}
but it isn't redirecting and it isn't echoing dsdasdas
It should be if($logedin_admin=='1'){
You are doing an assignment operation instead of a comparison..
Also, make sure if the session was started...
The code..
<?php
session_start(); //<=--------- Add this
if($logedin_admin=='1'){
$logedin_admin=0;
$_SESSION['is_admin']=1;
header('Location: admin/index.php');
exit; //<=----------- Add an exit too.
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm not the best at php and mysql and i'm still learning however i have this userlevel variable which i define in my session
and if i message it back to myself using
<?php echo"$session->userlevel"; ?>
It'll work, it'll tell me that me that my userlevel is "0" which it should be however when i'm using an if statement to check it won't work?
<?php
if ($_SESSION['userlevel'] = 0) {
echo "Userlevel 0 was found!";
}
?>
Any though
if($_SESSION['userlevel'] = 0)
should be
if($_SESSION['userlevel'] == 0)
Otherwise you don't check, you assign the value 0 to $_SESSION['userlevel']
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
header("Location: {$TBDEV['baseurl']}/login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]));
Is it a variable? PHP reserved word? something to do with HTML?
It's a $_GET parameter. When you submit the code, the page receiving it will be able to use $_GET['returnto'] to return you to the page you're currently on.
Take some time to learn about $_GET
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am not sure if the IF must be followed by ELSE like in my example above or if IF can be used alone like it is without any ELSE.
Will the page show to anyone if there is no ELSE? I am a beginner...
<?php
$rank = $user["rank"];
if ($rank != 'ADMIN'){
header('Location: get_the_he.._out.php');
exit();
}
else {
?>
<html>
<head><title>Show Page</title></head>
<body>
Here we show page if user is admin
</body>
</html>
<?php } ?>
NO. There is no need to have an ELSE with an IF. However you then need to make sure that the script will not continue after the IF, as you are doing here :)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
When I try to require a file into my HTML, my web page isn't loading anymore.
The file I want to require is empty so it isn't a scripting error.
require_once('required/dbClass.php');
session_start();
$_SESSION['user'] = 'Test User';
$testing=true;
This code above is working just fine and my page is loading as it is supposed to.
But when I try the next code, my page isn't loading anymore
require 'config.php';
require_once('required/dbClass.php');
session_start();
$_SESSION['user'] = 'Test User';
$testing=true;
I don't know what's wrong, I've tried getting an error with error_reporting(E_ALL); but that doesn't display anything.
Did I do something wrong?
Config.php was in a different directory
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So, I'm making a profile page, and I need to have it so it displays other content if it's not your username in the URL. How would i go about doing this, considering this doesn't seem to be working.
else if(isset($_GET[!$myUsername])){
echo "hi";
}
Thank You!
Its probably a bad idea to pass a username in the url ($_GET holds the url parameters)
I would start by reading up on php sessions here is a quick tutorial:
http://www.tizag.com/phpT/phpsessions.php
The exact answer to your question is is the placement of the the "!", it needs to be moved in front of isset().
if (!isset($_GET['myUserName'])) {
//this is true when ?mysuername= is not present in the address bar.
}
After you read up on the sessions you will handle this by setting a a session variable, something names "loggedIn" or similar.
if (isset($_SESSION['loggedIn'])) {
//Show Logged IN Content
echo "Your user id is: ". $_SESSION['userId'];
} else {
//Show not logged in content
echo "You should probably log in before trying to look at this content";
}