if(isset($_GET['action']) && $_GET['action']=='album_id=$album['id']')
Now I am sure all of you can see the error here I am trying to check if this link is clicked
<a href="<?php echo $profile_data['username'];?>?action=album_id=<?php echo $album['id'];?>">
Now this link works and displays as it should in the url but I can not figure out how to pass $album['id'] to the if statements isset?
EDIT
ok i did this:
<a href="<?php echo $profile_data['username'];?>?action=album_id&action_id=<?php echo $album['id'];?>">
and
if($_GET['action'] == 'album_id' && $_GET['action_id'] == $album['id'])
and returned undefined variable in the if statement says album is undefined variable
This is my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /lr/profile.php?username=$1 [QSA]
Here is my entire php file:
<?php
include 'core/init.php';
include 'init.image.php';
protect_page();
include 'includes/overall/overall_header.php';
if(isset($_GET['username']) === true && empty($_GET['username']) === false){
$username = $_GET['username'];
if(user_exists($username) === true){
$user_id = user_id_from_username($username);
$profile_data = user_data($user_id, 'first_name','last_name','email', 'username');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Yor Page</h1>
<div id="navWrapper">
<ul>
<li>
<img src="uploads/profile/blank_profile.gif" width="150" height="150" id="blank_profile">
</li>
<nav>
<ul>
<li>
Albums
</li>
<li>
Music
</li>
</ul>
</nav>
</ul>
</div>
<?php
if(isset($_GET['action']) && $_GET['action']=='albums'){
$albums = get_profile_albums($user_id);
if(empty($albums)){
echo 'No Albums';
}else{
foreach($albums as $album){
if (empty($album['image'])) {
$album['image'] = 'uploads/profile/blank_profile.gif';
}
?>
<p><?php echo $album['name'],' (', $album['count'], ')'?> <br />
<a href="<?php echo $profile_data['username']; ?>?action=album&album_id=<?php echo $album['id']; ?>">
<img src="uploads/thumbs/<?php echo $album['id'];?>/<?php echo $album['image'];?>" />
</a><br />
<?php echo $album['description'];?>...<br />
</p>
<?php
}
}
}
else if (isset($_GET['action']) && $_GET['action']=='album' && isset($_GET['album_id'])){
echo 'albums';
}
if(isset($_GET['action']) && $_GET['action']=='music'){
echo'<h1>Music</h1>';
}
}else{
echo 'Sorry, that user doesn\'t exist';
}
}else{
header('Location: index.php');
exit();
}
include 'includes/overall/overall_footer.php';
?>
the proper way would be to have the url properly encoded:
<a href="<?php echo $profile_data['username'];?>?action=<?php echo urlencode('album_id='.$album['id']); ?>">
and then decode it
if(isset($_GET['action']) && urldecode($_GET['action'])=='album_id='.$album['id'])
You don't have a destination, where's the php file you try to access? You started with username. Check here href="<?php echo $profile_data['username'];?>?
Try separate the action and the id, it's probably just me, I found it kinda weird to put it like action=album=1
you can try like this
$_GET['action'] == 'album' && $_GET['action_id'] == $album['id']
so the url would be looking like
?action=album&action_id=1
I think #Dreen answered to your question, but I would separate the action parameter to something like action and id:
<a href="<?php echo $profile_data['username'];?>?action=album&id=<?php echo $album['id'];?>">
and check
if(isset($_GET['action']) && $_GET['action']=='album' && isset($_GET['id']) && $_GET['id']==$album['id'])
Related
I'm planning to create a header navigate bar for both user & admin with different content. If it is the user, so they will only see the Log out button. If it is the Admin, they will see button "Usermanagement" and "Logout" using php. For now I didn't to manage to ensure that the php read the status of current user. 'roles' = 'Y' is consider as admin, i store it inside mssql. Below is my code.
<?php if( isset($_SESSION['username']) && !empty($_SESSION['username']))
{ ?>
<a class="right" href="logout.php">Log Out</a>
<?php if( isset($_SESSION['roles']) && $_SESSION['roles']===['Y']) ?>
<a class="right" href="userManagement.php">User Profile</a>
<?php }else{ ?>
<a class="right" href="login.php">Login</a>
<a class="right" href="register.php">Register</a>
<?php } ?>
any help would highly appreciated, i've been searching and applying many code since last 4 days, none of the code working.
I'm not sure if you want this or not.
<?php if (isset($_SESSION['username']) && !empty($_SESSION['username'])) { ?>
<a class="right" href="logout.php">Log Out</a>
<?php if ($_SESSION['roles'] === "Y") { ?>
<a class="right" href="userManagement.php">User Profile</a>
<?php } ?>
<?php } else { ?>
<a class="right" href="login.php">Login</a>
<a class="right" href="register.php">Register</a>
<?php } ?>
To conditionally output HTML code you need to echo it from PHP. Here's what I think you want. I have kept your formatting
<?php
if( isset($_SESSION['username']) && !empty($_SESSION['username']))
{echo '<a class="right" href="logout.php">Log Out</a>';}
if( isset($_SESSION['roles']) && $_SESSION['roles']===['Y'])
{echo '<a class="right" href="userManagement.php">User Profile</a>';}
else
{echo '<a class="right" href="login.php">Login</a>';
echo '<a class="right" href="register.php">Register</a>';}
?>
I have the below code which works perfectly. When the title is JohnPage, it does not display in the li.
<?php foreach($this->pages AS $page) { ?>
<li <?php echo $page['title'] == ('JohnPage') ? 'style="display:none";' : ''; ?>>
<a<?php echo ($page['active']?' class="active"':'');?> href="<?php echo $page['href'];?>"><?php echo $page['title'];?></a>
</li>
<?php } ?>
However, I want to say: if the title is either JohnPage or MyPage, do not display in the li. I tried the following:
<li <?php echo $page['title'] == ('JohnPage' OR 'MyPage') ? 'style="display:none";' : ''; ?>>
<li <?php echo $page['title'] == ('JohnPage' || 'MyPage') ? 'style="display:none";' : ''; ?>>
Neither works. Thanks for your help.
Instead of putting your conditional statements there. Try it this way.
<?php
foreach($this->pages AS $page) { ?>
<li <?php if($page['title'] == 'JohnPage' || $page['title'] == 'MyPage') { ?>style="display:none<?php } ?>">
<a <?php echo ($page['active']?' class="active"':'') ?> href="<?php echo $page['href'] ?>"><?php echo $page['title'] ?></a>
</li>
<?php
} // end foreach
?>
I get the following PHP Notice in my opencart log file.
Undefined variable: http_type in /home/AAA/public_html/vqmod/vqcache/vq2-catalog_view_theme_template_product_product.tpl on line 3
Here is what I have in my product.php file's few first few lines
<?php if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$http_type = "https:";} else {$http_type = "http:";}
<!---THIS IS LINE 3---> ?>
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb" xmlns:v="<?php echo $http_type;?>//rdf.data-vocabulary.org/#" id="brd-crumbs" >
<ul>
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li typeof="v:Breadcrumb">
<?php echo $breadcrumb['separator']; ?><a property="v:title" rel="v:url" href="<?php echo $breadcrumb['href']; ?>"><span><?php echo $breadcrumb['text']; ?></span></a></li>
<?php } ?>
</ul>
</div>
Any help is highly appreciated
Firstly, it's just a notice so I expect everything is working as you would expect.
The notice is generated because when the $http_type variable is echoed, it hasn't necessarily been set to anything. If you add $http_type = ''; before the initial if statement, that will get rid of the notice.
I am trying to return a $user_id variable from file to if(isset(...)) statement. I will perform a different if statement but just trying to echo out the $user_id variable to test that I am setting the page.
<?php
include 'core/init.php';
include 'init.image.php';
protect_page();
include 'includes/overall/overall_header.php';
if(isset($_GET['username']) === true && empty($_GET['username']) === false){
$username = $_GET['username'];
if(user_exists($username) === true){
$user_id = user_id_from_username($username);
$profile_data = user_data($user_id, 'first_name','last_name','email', 'username');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Yor Page</h1>
<div id="navWrapper">
<ul>
<li>
<img src="uploads/profile/blank_profile.gif" width="150" height="150" id="blank_profile">
</li>
<nav>
<ul>
<li>
Albums
</li>
<li>
Music
</li>
</ul>
</nav>
</ul>
</div>
<?php
if(isset($_GET['action']) && $_GET['action']=='albums'){
$albums = get_profile_albums($user_id);
if(empty($albums)){
echo 'No Albums';
}else{
foreach($albums as $album){
if (empty($album['image'])) {
$album['image'] = 'uploads/profile/blank_profile.gif';
}
?>
<p><?php echo $album['name'],' (', $album['count'], ')'?> <br />
<a href="<?php echo $profile_data['username'];?>?action=album_id=<?php echo $album['id'];?>">
<img src="uploads/thumbs/<?php echo $album['id'];?>/<?php echo $album['image'];?>" />
</a><br />
<?php echo $album['description'];?>...<br />
</p>
<?php
}
}
}
if(isset($_GET['action']) && $_GET['action']=='album_id=$album['id']'){
echo $user_id;
}
if(isset($_GET['action']) && $_GET['action']=='music'){
echo'<h1>Music</h1>';
}
}else{
echo 'Sorry, that user doesn\'t exist';
}
}else{
header('Location: index.php');
exit();
}
include 'includes/overall/overall_footer.php';
?>
Single quotes do not parse the string but double quotes do. For example:
$album_id = 1;
echo 'album_id=$album_id ';
echo "album_id=$album_id";
Will result in album_id=$album_id album_id=1
Thus, $_GET['action']=='album_id=$album_id' is checking if $_GET['action'] is equal to 'album_id=$album_id' and not what $album_id is evaluated to.
Your check should be more along these lines:
if (/* ... */ && $_GET['action']=="album_id=$album_id") {
Edit: Suggestion.
You should check $_GET['action'] once and store $action. From there create an if/else if/else statement checking each possible type of action (music, albums, album, etc). If a type of action requires extra user supplied data, include that in the respective if block. For example:
$action = $_GET['action'];
// URL: /script.php?action=albums
if ($action == 'albums') {
// ...
}
// URL: /script.php?action=album&album_id=12
else if ($action == 'album') {
if (!empty($_GET['album_id'])) {
$album_id = $_GET['album_id'];
echo "User with id $user_id is trying to access album with id $album_id";
}
// ...
}
// ...
No more $_GET['action']=="album_id=$album_id"
You are passing the variable correctly.
What I'm more concerned with in the following line is:
if(isset($_GET['action']) && $_GET['action']=='album_id=$album_id'){
'album_id=$album_id' doesnt look right and is probably why your if is not firing... It looks like you're trying to use the variable $album_id wrapped in single quotes and that will not substitute the value and rather keep $album_id in tact. I'm not sure if this is what you intended but if not its likely the source of your problem.
I'm trying to specify that my logo appears on some pages and not on others, the only pages I do not want it showing on are the homepage and /index.php. I have the big logo appearing and disappearing as I want it and so I presumed I could just do the opposite for the small logo but I must be doing something wrong. Here is my current code:
<?php
$dunpage = $_SERVER['REQUEST_URI']; if ($dunpage != '/index.php' || $dunpage != '/') {?>
<h1 class="small-logo">
<span><?php echo $siteName; ?>
</h1>
<?php }
?>
<?php
$currentpage = $_SERVER['REQUEST_URI']; if ($currentpage == '/' || $currentpage == '/index.php') {?>
<h1 class="logo";>
<span><?php echo $siteName; ?>
</h1>
<?php }
?>
Instead of a logical OR in your first condition, you should be using a logical AND:
$dunpage = $_SERVER['REQUEST_URI']; if ($dunpage != '/index.php' || $dunpage != '/') {?>
// Should be
$dunpage = $_SERVER['REQUEST_URI']; if ($dunpage != '/index.php' && $dunpage != '/') {?>
Effectively, you were saying "act if the page is either not index.php, or not /." So in either of those cases, the opposite would be true. If it wasn't index.php, it could be /, for example.
try
if ($dunpage != '/index.php' && $dunpage != '/') {
for your small logo.
You correctly negated the == operator, but not the || operator. You're saying that if dunpage is not /index.php OR dunpage is not /, do that, which basically means do that always. Change || to && for the small logo.
Why don't you use an else?
<?php
$currentpage = $_SERVER['REQUEST_URI']; if ($currentpage == '/' || $currentpage == '/index.php') { ?>
<h1 class="logo";>
<span><?php echo $siteName; ?>
</h1>
<?php
} else {
?>
<h1 class="small-logo">
<span><?php echo $siteName; ?>
</h1>
<?php
}
?>
(You don't actually mention that it's either a large or a small logo that you want to display, but I have to assume that is the case here.)
Or you can use in_array() in this case.
<?php
$displayMainLogo = array('/', '/index.php');
if ( in_array($_SERVER['REQUEST_URI'], $displayMainLogo) ) { ?>
<h1 class="logo";>
<span><?php echo $siteName; ?>
</h1>
<?php
} else {
?>
<h1 class="small-logo">
<span><?php echo $siteName; ?>
</h1>
<?php
}
?>
If you understand how to do a ternary (http://php.net/manual/en/language.operators.comparison.php), then this is as terse as you can make it.
<h1 class="<?php echo (in_array($_SERVER['REQUEST_URI'], $displayMainLogo)) ? 'logo' : 'small-logo' ?>";>
<span><?php echo $siteName; ?>
</h1>