I have Created Session on subdomain but right now i am unable to access session variable on Root domain
Login Page : myaccount.javaignite.com //authenticate login
Home: page
www.javaignite.com // here i am unable to get the value
myaccount.javaignite.com/Auth.php
Calling by ajax from index.php
<?php
$sess_name = session_name('app');
session_set_cookie_params(0, '/', '.javaignite.com');
session_start();
if($_POST){
$profile_id =$_POST["profile_id"];
$profile_fullname =$_POST["profile_fullname"];
$profile_img =$_POST["profile_img"];
$profile_email =$_POST["profile_email"];
$_SESSION["profile_id"] =$profile_id;
$_SESSION["profile_fullname"] =$profile_fullname;
$_SESSION["profile_img"] =$profile_img;
$_SESSION["profile_email"] =$profile_email;
$redirect_url ="http://javaignite.com";
if(isset($_SESSION["redir_url"])){
$redirect_url =$_SESSION["redir_url"];
}
echo $redirect_url;
die;
}
?>
javaignite.com/navigation.php
which is include in myaccount.javaignite.com/index.php and index.php (in root)
<?php
print_r($_SESSION);
if(isset($_SESSION["profile_id"])){
?>
<ul class="nav navbar-nav navbar-right" style="margin-right:10px;">
<li class="dropdown selected">
<a class="" href="http://account.javaignite.com/profile"> <i class="fa fa-sign-in"></i>
<?php echo $_SESSION["profile_name"]; ?> </a>
</li>
</ul>
<?php
} else {
?>
<ul class="nav navbar-nav navbar-right" style="margin-right:10px;">
<li class="dropdown selected">
<a class="" href="http://account.javaignite.com/"> <i class="fa fa-sign-in"></i> Login/Signup </a>
</li>
</ul>
<?php
}
?>
You need to update php.ini file. Please read following older question links
1.Allow php sessions to subdomains
2.Session variable from subdomain to main domain
Related
Thanks in advanced for any help provided and taking the time to review my question. I basically just have a Wordpress site that once you login, you see your name and avatar in the top right corner and when you hover over your name an "Edit Profile" and "Log out" link appear. All I want is for a "Login" link to be in that same spot when you're not logged in. (This saves me from having to put a login widget in the sidebar).
I was able to track down the PHP file that holds that specific piece of code and find the spot where the user menu is setup. I'm just not sure what piece of code I could add so that there's a login link there that leads to mysite.com/login/. Here is the current code:
<?php }
//user menu
$user_show_info = ot_get_option('user_show_info');
if ( is_user_logged_in() && $user_show_info =='1') {
$current_user = wp_get_current_user();
$link = get_edit_user_link( $current_user->ID );
?>
<li class="menu-item current_us">
<?php
echo '<a class="account_cr" href="#">'.$current_user->user_login;
echo get_avatar( $current_user->ID, '25' ).'</a>';
?>
<ul class="sub-menu">
<li class="menu-item"><?php _e('Edit Profile','cactusthemes') ?></li>
<li class="menu-item"><?php _e('Logout','cactusthemes') ?></li>
Here's an image to show you what I mean as well. Top is logged out, bottom logged in.
http://6chill.com/loli.jpg
Thanks again for any help that you're able to provide and if you require further details just let me know and I'll do my best to provide them.
Thanks for the prompt reply everyone :) As requested, here's more of the code to ensure nothing was left out.
<?php }
//user menu
$user_show_info = ot_get_option('user_show_info');
if ( is_user_logged_in() && $user_show_info =='1') {
$current_user = wp_get_current_user();
$link = get_edit_user_link( $current_user->ID );
?>
<li class="menu-item current_us">
<?php
echo '<a class="account_cr" href="#">'.$current_user->user_login;
echo get_avatar( $current_user->ID, '25' ).'</a>';
?>
<ul class="sub-menu">
<li class="menu-item"><?php _e('Edit Profile','cactusthemes') ?></li>
<li class="menu-item"><?php _e('Logout','cactusthemes') ?></li>
</ul>
</li>
<?php }?>
<?php //submit menu
if(ot_get_option('user_submit',1)) {
$text_bt_submit = ot_get_option('text_bt_submit');
if($text_bt_submit==''){ $text_bt_submit = 'Submit Video';}
if(ot_get_option('only_user_submit',1)){
if(is_user_logged_in()){?>
<li class="menu-item"><a class="" href="#" data-toggle="modal" data-target="#submitModal"><?php _e($text_bt_submit,'cactusthemes'); ?></a></li>
<?php }
} else{
?>
<li class="menu-item"><a class="" href="#" data-toggle="modal" data-target="#submitModal"><?php _e($text_bt_submit,'cactusthemes'); ?></a></li>
<?php
}
} ?>
I hope that's what you're looking for. Where you see the comment "//submit menu", that's where the "Submit Video" button comes into play. Thanks so much again guys, you're freaking awesome!
Please try this code, I think this will help you
<?php
if ( is_user_logged_in() )
{ ?>
LOGOUT
<!-- add another action as per your requirement-->
<?php } else
{ ?>
<a class="login" href="<?php echo site_url(); ?>/login/">LOGIN</a>
<! -- give link to your login page -->
<?php }
put this code in header file.
You need to add an else to the if statement that checks if the user is logged in. If they aren't logged then you output a link to the login page. You may need to tweak the CSS or the classes on the menu item for the login link.
<?php }
$user_show_info = ot_get_option('user_show_info');
if ( is_user_logged_in() && $user_show_info =='1') {
$current_user = wp_get_current_user();
$link = get_edit_user_link( $current_user->ID );
?>
<li class="menu-item current_us">
<?php
echo '<a class="account_cr" href="#">'.$current_user->user_login;
echo get_avatar( $current_user->ID, '25' ).'</a>';
?>
<ul class="sub-menu">
<li class="menu-item"><?php _e('Edit Profile','cactusthemes') ?></li>
<li class="menu-item"><?php _e('Logout','cactusthemes') ?></li>
</ul>
</li>
<?php } else { ?>
<li class="menu-item current_us">
Login
</li>
<?php } ?>
<?php //submit menu
if(ot_get_option('user_submit',1)) {
$text_bt_submit = ot_get_option('text_bt_submit');
if($text_bt_submit==''){ $text_bt_submit = 'Submit Video';}
if(ot_get_option('only_user_submit',1)){
if(is_user_logged_in()){?>
<li class="menu-item"><a class="" href="#" data-toggle="modal" data-target="#submitModal"><?php _e($text_bt_submit,'cactusthemes'); ?></a></li>
<?php }
} else{
?>
<li class="menu-item"><a class="" href="#" data-toggle="modal" data-target="#submitModal"><?php _e($text_bt_submit,'cactusthemes'); ?></a></li>
<?php
}
} ?>
I'm creating a website..When it comes to the navigation menu, I listed it and need the nav bar class to be active when that menu is clicked. It's fine to give class="active" for the list tag. But I need it to be active only when clicked. How can I achieve this .?
My list is :
<div class="menu">
<ul class="nav" id="nav">
<li class="active">
<?php echo anchor("cntrl/index","Home"); ?>
</li>
<li><?php echo $this->session->userdata('user_name'); ?></li>
<li>About</li>
<li>
<?php echo anchor("cntrl/jobs","Jobs"); ?>
</li>
<li>
<?php echo anchor('cntrl/logout','Logout'); ?>
</li>
<div class="clearfix"></div>
</ul>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/responsive-nav.js"></script>
</div>
Well, I handle this sort of issue as follows:
set the active link (which is resided in the url when the link is clicked) into an variable in the controller function which is called by the link
$data['active_link'] = 'home'; # for example
check it in the view file (JS):
$(document).ready(function(){
var active_link = "<?php echo $active_link;?>";
$("li").removeClass('active');
$("#"+active_link).addClass('active');
});
Use the following code.
<li class="<?php echo (endsWith($_SERVER['REQUEST_URI'], 'cntrl/jobs')? 'active':''); ?>">
<?php echo anchor("cntrl/jobs","Jobs"); ?>
</li>
Main part of this code is
endsWith($_SERVER['REQUEST_URI'], 'cntrl/jobs')
Where $_SERVER['REQUEST_URI'] is your current URL. and 'cntrl/jobs' is your menu which is being checked with current URL.
I'm currently using laravel blade and i currently implemented bootstrap along with the blade template.
Would want to have the navigation button able to interact dynamically along with the selected pages
<div class="navbar">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"><b>iMakan</b></a>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li><a class="active "href="/">Home</a></li>
<li>About Us</li>
<li>Contact Us</li>
<li>Login</li>
<li>Cart</li>
</ul>
</div>
</div>
</nav>
</div>
Laravel provides a built-in function you can use: Request::is().
From the API docs:
Determine if the current request URI matches a pattern.
You use is like this:
Request::is('about'); // returns a boolean
<a href="about" #if(Request::is('about')) class="active" #endif>
You could write a helper function to take care of it:
function isActive($path, $class = 'active')
{
return (Request::is($path)) ? $class : '';
}
Put it in a file called helpers.php in your app directory and include it in the autoload-part of your composer.json like this:
"autoload": {
"files": [
"app/helpers.php"
]
},
Maybe you need to do a composer dump-autoload in your terminal.
And finally use it like this:
About
Here's my way What i do, You shall follow this too
If you have the last part of url like home for Home, aboutus for About Us, then you can do this
Step 1 :
Get Request Uri
$_SERVER['REQUEST_URI']
Step 2 :
Inside you class you can have this condition
<?php if ($_SERVER['REQUEST_URI']=='/') { echo 'active'; } ?>
So you will be having
<li><a href="about" class='<?php if ($_SERVER['REQUEST_URI']=='/') { echo 'active'; } ?>' >About Us</a></li>
The condition will echo active according to your uri
So you will be having something this
<ul class="nav navbar-nav navbar-right">
<li><a class="<?php if ($_SERVER['REQUEST_URI']=='/') { echo 'active'; } ?>" href="/">Home</a></li>
<li><a class='<?php if ($_SERVER['REQUEST_URI']=='/aboutus') { echo 'active'; } ?>'href="about" >About Us</a></li>
<li><a class='<?php if ($_SERVER['REQUEST_URI']=='/contactus') { echo 'active'; } ?>'href="contact">Contact Us</a></li>
<li><a class='<?php if ($_SERVER['REQUEST_URI']=='/login') { echo 'active'; } ?>' href="auth/login">Login</a></li>
<li><a class='<?php if ($_SERVER['REQUEST_URI']=='/cart') { echo 'active'; } ?>' href="503">Cart</a></li>
</ul>
Then you will be getting the class='active' according to your url.
Hope this helps you.
There is a package you can use, but using only what laravel provides I would suggest the following:
<a href="{{ URL::route('home') }}"
class="{{ Route::current()->getName() === 'home' ? : 'active' : ''">Home</a>
Using URL::route(...) will create a URL based on the name of the route and you can check if this name is currently used with the providec check. To name a route, read the laravel documentation about routing.
I know this question comes across a lot, but I just can't figure out how to do this using the, already answered posts.
I have a header with navigation links. I would like to add class="active" to the link that's active at the moment.
How could I do this if I have the following navigation?
<nav>
<ul id="main_nav">
<li class="home">
<a href="search">
<i class="icon-search"></i>
<span>BEDRIJF ZOEKEN</span>
</a>
</li>
<li class="categorie">
<a href="categorieen/all">
<i class="icon-list-ul"></i>
<span>CATEGORIE</span>
</a>
</li>
<li class="aanbieding">
<a href="aanbiedingen">
<i class="icon-shopping-cart"></i>
<span>AANBIEDING</span>
</a>
</li>
<li class="vacature">
<a href="vacatures">
<i class="icon-copy"></i>
<span>VACATURE</span>
</a>
</li>
<li class="agenda">
<a href="agenda">
<i class="icon-calendar"></i>
<span>AGENDA</span>
</a>
</li>
<li class="contact">
<a href="contact">
<i class="icon-envelope"></i>
<span>CONTACT</span>
</a>
</li>
</ul>
</nav>
I tried this, but it did not work:
<script>
$(function() {
var href = $(this).find('a').attr('href');
alert(window.location.pathname)
if (href === window.location.pathname) {
$(this).addClass('active');
}
});
</script>
Maybe there's a better Codeigniter-ish way?
try this one.i think no need of javascript or jquery.
If you are using codeigniter then you can use URI Class.
<li class="home">
<a class="<?php if($this->uri->segment(1)=="search"){echo "active";}?>" href="<?=base_url('search')?>">
<i class="icon-search"></i>
<span>BEDRIJF ZOEKEN</span>
</a>
</li>
please let me know if you face any problem
I created a helper and saved it into the helper directory named as "menu_helper.php":
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
if(!function_exists('active_link')) {
function activate_menu($controller) {
// Getting the class instance.
$ci = get_instance();
// Getting the router class to actived it.
$class = $ci->router->fetch_class();
return ($class == $controller) ? 'active' : '';
}
}
Then in config/autoload.php, I added "menu" as a helper on line 91.
The last step is to put the code for print the "active" class when accessing the page (i.e. Login Page):
<li class="<?php echo activate_menu('login'); ?>">
<?php echo anchor('login', 'Login'); ?>
</li>
if (href === window.location.pathname) {
$('a[href='+ href +']').addClass('active');
}
Try this one:
<a class="<?=(current_url()==base_url('search')) ? 'active':''?>" href="<?=base_url('search')?>">
I'm editing a theme named AquaCart, installed in OpenCart 1.5.5.1. I also integrated Twitter Bootstrap's fixed top navbar. I already modified the navbar and put the Login / Logout menu there, and it's doing fine. This project is for my own online store.
I don't have any PHP skills yet, only HTML+CSS. I have managed to put the login/logout button on my new navbar menu by copying codes from my current theme's header.tpl file and editing the header.php file (from the catalog\english\common\header.php).
Now, I am polishing the menu and wanted to add some custom menu/link named Sign Up!.
I want this Sign Up! menu link to show as Logout link when a user is already logged in.
My current edit shows the logged-in user's name in a <li>, and a logout menu in a second <li>. This is not what I really want. I want to show the Logout link in place of the Sign Up! link when a user is logged in.
Here is my current header.tpl edit:
<ul>
<ul>
<li>
My Account<!--Shall be shown only when user is logged in-->
<ul>
<?php if (!$logged) { ?>
<?php echo $text_welcome; ?>
<?php } else { ?>
<?php echo $text_logged; ?>
<?php } ?>
<li class="divider"></li>
<li>Store Front</li>
<li>Blog Page</li>
</ul>
</li>
<li>Sign Up!</li>
</ul>
</ul>
My header.php from the catalog\language folder of opencart. text_logged and text_welcome was already edited.
<?php
// header.php from catalog\language\english\common\header.php
$_['text_home'] = 'Online Shop';
$_['text_wishlist'] = 'Wish List (%s)';
$_['text_shopping_cart'] = 'Shopping Cart';
$_['text_search'] = 'Search';
$_['text_welcome'] = '<li>Login</li>
<li>Sign Up!</li>';
$_['text_logged'] = '<li>%s</li>
<li>Logout</li>';
$_['text_account'] = 'My Account';
$_['text_checkout'] = 'Checkout';
?>
The above code is rendered like so...
..and I wanted to make the sign Up! link to become Logout when a user is logged in.
I don't know PHP yet, but I'm struggling on studying the PHP files of OpenCart installation, and I've found this string from my header.php file found in catalog\controller\common:
$this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
I am thinking of duplicating that, but don't know what to duplicate and modify. And what are other files involved?
UPDATE:
I've now added a new Text name "Sign Up" and "Login", so I may not be confused, and I can easily substitute it to my Text Link.
So far.. I've added: In my catalog\english\common\header.php:
$_['text_login'] = 'Login';
$_['text_signup'] = 'Sign Up!';
And in my catalog\controller\header.php.
$this->data['text_login'] = $this->language->get('text_login');
$this->data['text_signup'] = $this->language->get('text_signup');
UPDATE 2:
I've re-marked up my Menu, based from shadyxx opinion, I've changed the menu a bit. So for "not Logged-in Users"... This menu should be echoed...
Marked up like this:
<div class="nav-collapse collapse">
<ul>
<li>Login</li>
<li>Register</li>
</ul>
</div>
And for LOGGED-IN USERS, this menu should be echoed...
Marked up like this:
<div>
<ul>
<ul>
<li>
Account></b>
<ul>
<li>%s</a></li>
<li class="divider"></li>
<li>Shopping Cart</a></li>
<li>Checkout</a></li>
</ul>
</li>
<li>Logout</a></li>
</ul>
</ul>
</div>
In my catalog\controller\common\header.php:
$this->data['signup'] = sprintf($this->language->get('text_signup'), $this->url->link('account/register', '', 'SSL'));
$this->data['login_register'] = sprintf($this->language->get('text_login_register'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
$this->data['logged_in'] = sprintf($this->language->get('text_logged_in'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->data['text_shopping_cart'] = $this->language->get('text_shopping_cart'), $this->data['shopping_cart'] = $this->url->link('checkout/cart'), $this->url->link('account/logout', '', 'SSL'));
In my catalog\language\english\common\header.php
$_['text_login_register']
= '<div>
<ul>
<li>Login</a></li>
<li>Register</a></li>
</ul>
</div>';
$_['text_logged_in']
= '<div>
<ul>
<ul>
<li>
Account<b class="caret"></b>
<ul>
<li>%s</li>
<li class="divider"></li>
<li>Shopping Cart</li>
<li>Checkout</li>
</ul>
</li>
<li>Logout</li>
</ul>
</ul>
</div>';
In my header.tpl
<?php if (!$logged) { ?>
<?php echo $login_register; ?>
<?php } else { ?>
<?php echo $logged_in; ?>
<?php } ?>
So, what's not working, using the above codes is the checkout menu. The checkout menu is redirecting a user to the Shopping Cart Page.
I've just copy pasted the above codes. I've tried to understand the use of the existing code and by trial and error.
IMHO, you do not want to have My Account link when there is no user logged in...as it would make no sense to be shown for the visitors (not-logged-in users).
I would show only the Sign Up! link, and after logging in, I would show only the My Account menu that would have the desired Logout link (so as it is right now).
So keep your current template as is, and using this code block (you have given us):
<?php if (!$logged) { ?>
<?php echo $text_welcome; ?>
<?php } else { ?>
<?php echo $text_logged; ?>
<?php } ?>
We can modify your top navbar slightly... The condition <?php if (!$logged) { ?> applies if there is no user logged in, so inside it we will show the Sign Up! link, then the <?php } else { ?> gets applied if there is a user logged in. Thus we will move the My Account menu there. This code is just an example (as you didn't provide us with the navbar source code...):
<ul id="top-navbar>
<?php if (!$logged) { /* only visitor */?>
<li><?php echo $text_signup;?></li>
<?php } else { /* logged in user */?>
<li><span>My Account</span>
<ul class="sub-menu">
<li><span><?php echo $text_logged; ?> <?php echo $logged_username; ?></span></li>
<li><a href="<?php echo $logout; ?>><?php echo $text_logout; ?></a></li>
</ul>
</li>
<?php } ?>
</ul>
In your controller you would have to push the language strings, URLs and username to the template and in language file you would have to add the text strings needed for your menu (if you hadn't done so far...).
EDIT:
Your thinking is good, but the approach not. Do not put HTML into language files, nor controllers, unless really necessary or no other way is possible (which may not occure and if yes, something is wrong).
So, put all the HTML into your template file (header.tpl) and use PHP variables:
<?php if (!$logged) { ?>
<div>
<ul>
<li><?php echo $text_login; ?></li>
<li><?php echo $text_signup; ?></li>
</ul>
</div>
<?php } else { ?>
<div>
<ul>
<li>
<?php echo $text_account; ?><b class="caret"></b>
<ul>
<li><?php echo $username;?></li>
<li class="divider"></li>
<li><?php echo $text_shopping_cart; ?></li>
<li><?php echo $text_checkout; ?></li>
</ul>
</li>
<li><?php echo $text_logout; ?></li>
</ul>
</div>
<?php } ?>
Now many of the URLs and texts are already defined thus we need to add only few of them.
Open your language file (catalog\language\english\common\header.php) and add/modify these:
$_['text_login'] = 'Log In';
$_['text_signup'] = 'Register';
$_['text_logout'] = 'Log Out';
You can remove the previous text_login_register and text_logged_in variables with its values.
Now open the controller (catalog\controller\common\header.php) and find the part that ends with this line:
$this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
And after it, add these lines:
$this->data['text_login'] = $this->language->get('text_login');
$this->data['text_signup'] = $this->language->get('text_signup');
$this->data['text_logout'] = $this->language->get('text_logout');
$this->data['login'] = $this->url->link('account/login', '', 'SSL');
$this->data['signup'] = $this->url->link('account/register', '', 'SSL');
$this->data['logout'] = $this->url->link('account/logout', '', 'SSL');
$this->data['username'] = '';
if($this->customer->isLogged()) {
$this->data['username'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
}
Now you should be done.