$_GET does not equal variable [closed] - php

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";
}

Related

What does " if(true) " means? [closed]

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 3 years ago.
Improve this question
I'm building a functionality which displays a message dynamically, i.e if the forms are correctly filled or not.
I came across this piece of code and I don't understand how does it really work.
if(true) {
$this->flash('Yay ! File uploaded successfully', 'success');
} else {
$this->flash('There is some error', 'error');
From what I've already looked for, I guess it's used to see whether or not there is an array available, since PHP returns false if there isn't one.
(according to PHP manual )
I still don't get how does this work, there is no variables such as if($foo) but just plain boolean on this condition.
And yes, it seems to work as intended.
Thanks for your enlightments.
This looks like a debugging statement left in.
if(true)
This is always true, so you could remove the test entirely and just run with the true statement.

Image Source to Include a PHP Input [closed]

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 am trying to create an image that changes dependent on the genre grabbed from an icecast server, I am pretty sure I have the base code correct I think I've just incorrectly inputted the PHP variable.
<?php
$stats = $core->radioInfo( "http://http://sc.onlyhabbo.net:8124/status-json.xsl" );
?>
<img src=http://www.habbo.com/habbo-imaging/avatarimage?user=<?php
echo $stats['genre'];
?>&action=std&direction=2&head_direction=2&gesture=sml&size=m&img_format=gif/>
is the full code. Have I inputted the PHP variable incorrectly
Where are the quotes in your Html?
<img src="http://www.habbo.com/habbo-imaging/avatarimage?user=<?php
echo $stats['genre'];
?>&action=std&direction=2&head_direction=2&gesture=sml&size=m&img_format=gif"/>
UPDATE EVERYBODY
This is now resolved, I decided to go down the CURL route for this, and at first it didn't work until my host raised our CloudLinux Process Limit. I am unsure what the actual issue with this code was, but the CURL route works fine. Thank you for any answers

Is IF obligatory to be followed by ELSE [closed]

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 :)

Header always redirect: [closed]

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.
}

Using a PHP location header [closed]

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 9 years ago.
Improve this question
I am trying to use a variable in a PHP location header, but I can't seem to get it to work. What am I doing wrong?
My Code:
$id= 14;
header('Location:collection.php?idollection=$id);
Just by assumptions.. You want to re-direct with a $_GET value based on a variable source?
How about:
$id = 1;
header("Location: collection.php?idollection=".$id);
exit;
Use of the exit will make sure the page will not continue executing after header has been called. Furthermore, make sure that there is no whitespaces or any output prior to the header being called.
Make sure to use double quotes. You used single quotes and actually only used one. Try this:
header("location:collection.php?idcollection=$id");

Categories