Currently when i showing my username(through session) and logout function , both of them is in different lines
Image: http://prntscr.com/nc2v1b ( This is output )
What i want : https://prnt.sc/nc2w23
Username is on the right side of "Logout"
First of all, remove this part style='float:right;'
Using float:right will move the text right.
Second, need some spacing here:
echo $_SESSION["username"]." "; // you can use `|` to separation
echo '<span>Logout</span></li>';
Float right will push everything to the right (last item being the one the the most on the right).
Your code seem to work if you need to have everything on one line though.
<?php
session_start(); // Right at the top of your script
?>
<li class='active'>
<?php
if($_SESSION['logged']==true)
{
echo '<span>Logout</span>' . $_SESSION["username"];
}
else
{
echo '<span>Login/Register</span>';
}
echo '</li>';
?>
Related
Basically my task is,through the mandatory use of _GET,I'm supposed to make a code that fetches a specific php file when someone types in something like ..php?page=airlines and I dunno if I'm just lacking information or what but this isn't working router.php:
<?php
$nav =array("home"=>"C:\xampp\htdocs\project\home.php",
"flight"=>"C:xampp\htdocs\project\flight-detail.php",
"order"=>"C:xampp\htdocs\project\order-flight.php,",
"testimonial"=>"C:xampp\htdocs\project\add-testimonial.php");
if ( isset($nav[$_GET['page']]) )
{
echo header('Location: ' . $nav[$_GET['page']]);
}
if i understood your question, there are many ways to reach your goal.
I write an example that no change very your code:
<?php
$myPath="C:\xampp\htdocs\project\";
$nav =array("home"=>"home.php",
"flight"=>"flight-detail.php",
"order"=>"order-flight.php,",
"testimonial"=>"add-testimonial.php");
if ( isset($_GET['page']) and !empty($_GET['page']))
{
$myFile=nav[$_GET['page']];//i assume that in page there are only array keys value
echo header('Location: ' . myPath.$myFile);//i.e. I suppose in page there is home output is: "C:\xampp\htdocs\project\home.php"; file
}
else
{
echo 'error: page not found!';
}
An other "easy" solution is to create in first page the link where the user can choose the page:
<a href="C:\xampp\htdocs\project\home.php">HOME<a>
<a href="C:\xampp\htdocs\project\flight-detail.php">FLIGHT DETAIL<a>
....
Hope this helps
I'm troubled with some PHP session issues.
I have a main page, where i start the session, and some links to a second page. I want to keep track of the pages (breadcrumbs), so i store these in the session.
When i test, this works for some, and doesn't for others... i don't see the problem.
Page 1: (index.php)
<?php
session_start();
if (!isset($_SESSION['kruimels'])){
$_SESSION['kruimels']["home"]="index.php");
}else{
unset($_SESSION['kruimels']);
array_push($_SESSION['kruimels']["home"]="index.php");
}
?>
<a href='sub.php?id=1'>item1</a>
<a href='sub.php?id=2'>item2</a>
<a href='sub.php?id=3'>item3</a>
<a href='sub.php?id=4'>item4</a>
Second page: (sub.php)
<?php
session_start();
/* I get the name of the page by querying the DB...*/
if (isset($_SESSION['kruimels'])){
$_SESSION['kruimels'][$nameOfPage]="sub.php?id=".$_GET['id'];
}
?>
<?php
foreach ($_SESSION['kruimels'] as $naam => $path) {
echo "<li><a href='$path'>$naam</a></li>";
}
?>
The strange thing is, somethimes it gets saved, sometimes it doesn't...
i don't see the problem...
Help?
Greetings,
Martijn
you have no need to start a session for this just use basename($_SERVER['REQUEST_URI']); this function of php. This will give you the name of your current file.
After this, you got your file name and now explode this with (.) And echo wherever you want to show
And than Try below code
$pagename = explode('.', basename($_SERVER['SCRIPT_NAME']));
echo $pagename[0];
I have created a custom wordpress post type everything works but my client asked me to insert a function that doenst show the button if the link field is empty that is also working but when I want to display the tekst or link the part where the php is inserted just doesnt shows up what am I doing wrong
I am able to get the data on other parts of this php file but not in this part of the page
<?php
$linktitle = $day_aray=get_field("under_shoe_button_title");
$linkexist = get_field("under_shoe_button_link");
echo($linktitle);
if (empty($linkexist)) {
echo '<html> <p></p></html>' ;
}
else {
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html> <?php echo($linktitle); ?> <html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
}
?>
If you would look carefully, you would notice, that you are echoing a string where, inside the string, you are trying to echo again. Even with little programming knowledge, you should understand, that it is not logical to do that.
The same goes for php opening <?php tag. You opened the tag at start of the page and later on, inside a string, you are trying to open it again. This does not work.
Instead, close the string (or escape it) and then add the echo option.
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html>';
echo($linktitle);
echo '<html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
And please, read the comments to you question and learn basic HTML
There are so many things wrong in your code
Firstly you are using echo inside echo you should use concatenation instead.
so you want to echo it like this
echo '<your html code>'.$linktitle.'<your other html code>';
Also your html code is wrong coz u are using many html tags.
The following code is for a Wordpress plugin, it displays points and tank of a user:
<?php
if(function_exists('cp_displayPoints') && $authordata->ID){
echo '<span class="cubepoints_buddypress">'; cp_displayPoints($authordata->ID); echo '</span>';
if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($authordata->ID).'</span>';
}
?>
I am trying to extract these two echo functions from the If statement but only succeeded with one of them. I can echo the points like this:
<?php cp_displayPoints($authordata->ID); ?>
Works fine. Now I tried doing the same with the second echo:
<?php cp_module_ranks_getRank($authordata->ID); ?>
But it did not work. Obviously, there is some basic thing that I am missing here. Do you know what it is?
The first one likely prints directly to output, while the second returns its value. So, you need to echo() the second one, just as they're doing in your sample code:
<?php echo cp_module_ranks_getRank($authordata->ID); ?>
I have two scripts but I can't make them work together.
1- A simply page views counter
<?php
if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
echo "Pageviews=". $_SESSION['views'];
?>
2 - A Random link from a list but without repeat the links
<?php
if (empty($_SESSION['links'])) {
// first time visit, populate random links in session
$links = array('http://some-site.com', 'http://some-other-site.com', 'http://example.com');
shuffle($links);
$_SESSION['links'] = $links;
}
$link = array_shift($_SESSION['links']);
$_SESSION['links'][] = $link;
?>
For some reason if I use one of them the other will stop to work, both had worked fine but I can't make them work together on the same site.
On the header I have <?php session_start(); ?> but I also moved the script to different parts of the site and I get always the same problem, one stop to work. I also had the <?php session_start();?> at the start of each piece of code but nothing seems to work.
At some point I manage to make both scripts work but the page views counter script was counting from 3 to 3, not from 1 to 1 - Note that the random link script have also 3 values on it; so my guess is that something is incompatible with both scripts
Any help and guide in how or where I need to place the code will be appreciated.
Thanks and sorry for my English
Daniel
try is on the top of the code
just add "$_SESSION['views'] = 0;" to the top once when u run the main script i think it will work
$_SESSION['views'] = 0;
if (empty($_SESSION['links'])) {
// first time visit, populate random links in session
$links = array('http://some-site.com', 'http://some-other-site.com',
'http://example.com');
shuffle($links);
$_SESSION['links'] = $links;
}
$link = array_shift($_SESSION['links']);
$_SESSION['links'][] = $link;
echo "<pre>";
print_r($_SESSION['links']);
echo "</pre>"
if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
echo "Pageviews=". $_SESSION['views'];