Free Web Hosting Forum
(#1 (permalink))
Old
NievesCorp's Avatar
Senior Member
NievesCorp is on a distinguished road
 
Posts: 930
Join Date: Jun 2009
Location: Sabana Hoyos, Arecibo, PR.
Send a message via MSN to NievesCorp Send a message via Skype™ to NievesCorp
Question if isset (Multiple cookies) - 07-20-2012, 01:22 AM

Hello;

My goal tonight is to create a cookie-operated member's menu. I want to make it so that if you're not logged in with your primary and secondary credentials you see a Log in dropdown menu, but if you're logged in, you see a dropdown with your name on it (stored in a cookie). I also want to make it so that if you're logged in, but don't have your name saved, the dropdown menu just says "You" as a header. Below I present the code written so far, I need to know how to correct ot, sinse I see that it's not totally correct.
Code:
    <? if (!isset($_COOKIE["name"]) || ($_COOKIE["primary_username"]) || ($_COOKIE["primary_password"]) || ($_COOKIE["secondary_username"]) || ($_COOKIE["secondary_password"])) { ?>
    <li class="menu_right"><a href="#" class="drop"><? if (isset($_COOKIE["name"])) { $name = $_GET['name']; echo $name; } else { echo "You"; } ?></a>
     <div class="dropdown_1column align_right">
      <div class="col_1">
       <ul class="simple">
        <li><a href="#">FreelanceSwitch</a></li>
        <li><a href="#">Creattica</a></li>
        <li><a href="#">WorkAwesome</a></li>
        <li><a href="#">Mac Apps</a></li>
        <li><a href="#">Web Apps</a></li>
        <li><a href="#">NetTuts</a></li>
        <li><a href="#">VectorTuts</a></li>
        <li><a href="#">PsdTuts</a></li>
        <li><a href="#">PhotoTuts</a></li>
        <li><a href="#">ActiveTuts</a></li>
        <li><a href="#">Design</a></li>
        <li><a href="#">Logo</a></li>
        <li><a href="#">Flash</a></li>
        <li><a href="#">Illustration</a></li>
        <li><a href="#">More...</a></li>
       </ul>   
      </div>
     </div>
    </li>
    <? } else { ?>
    <li class="menu_right"><a href="http://x.<? echo $base; ?>/search/search.php" class="drop">Log in</a>
     <div class="dropdown_2columns align_right">
      <div class="col1_2">
      <div class="col_1">
       <p><b>Name:</b></p>
      </div>
      <div class="col_1">
       <input class="v2" name="name" placeholder="John Davis" style="width:98%" type="text" value=""/>
      </div>
     </div>
    </li>
    <? } ?>
Oh, and here's the url just in case: http://www.spiritfonds.comlu.com/foyer.html

Thanks in advance!


Best regards;
- Miguel de la Nieves

Founder, Headmaster & Chief Executive Officer at The Spirit Fonds (Lebensborn).
Learn to speak Japanese like a pro by clicking here!
- Request a professional web template construction miguelnieves.phoenixwarez@gmail.com (Skype).
- We make templates at whatever cost suites your demands!
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 07-20-2012, 04:59 AM

When I tested your code, I got "You" printed althogh I am not logged in. So, how about
the following code, adding another if syntax for $name?

<? if(isset($_COOKIE["name"])) {
$name = $_GET['name'];
if($name) {echo $name;}
else {echo "You";}
} ?></a>
Reply With Quote
(#3 (permalink))
Old
NievesCorp's Avatar
Senior Member
NievesCorp is on a distinguished road
 
Posts: 930
Join Date: Jun 2009
Location: Sabana Hoyos, Arecibo, PR.
Send a message via MSN to NievesCorp Send a message via Skype™ to NievesCorp
Default 07-20-2012, 05:28 AM

Will try & reply.
Thanks!


Best regards;
- Miguel de la Nieves

Founder, Headmaster & Chief Executive Officer at The Spirit Fonds (Lebensborn).
Learn to speak Japanese like a pro by clicking here!
- Request a professional web template construction miguelnieves.phoenixwarez@gmail.com (Skype).
- We make templates at whatever cost suites your demands!
Reply With Quote
(#4 (permalink))
Old
NievesCorp's Avatar
Senior Member
NievesCorp is on a distinguished road
 
Posts: 930
Join Date: Jun 2009
Location: Sabana Hoyos, Arecibo, PR.
Send a message via MSN to NievesCorp Send a message via Skype™ to NievesCorp
Question 07-20-2012, 05:33 AM

Hmmm, it seems to work, but now we don't get the "Log in" menu OR the "You" menu.
I also have another question, is the Boolean of cookies legit?

The Code (Revised):
Code:
<? if (!isset($_COOKIE["name"]) || ($_COOKIE["primary_username"]) || ($_COOKIE["primary_password"]) || ($_COOKIE["secondary_username"]) || ($_COOKIE["secondary_password"])) { ?>
    <li class="menu_right"><a href="#" class="drop"><? if(isset($_COOKIE["name"])) { $name = $_GET['name']; if($name) {echo $name;} else {echo "You";} } ?></a>
     <div class="dropdown_1column align_right">
      <div class="col_1">
       <ul class="simple">
        <li><a href="#">FreelanceSwitch</a></li>
        <li><a href="#">Creattica</a></li>
        <li><a href="#">WorkAwesome</a></li>
        <li><a href="#">Mac Apps</a></li>
        <li><a href="#">Web Apps</a></li>
        <li><a href="#">NetTuts</a></li>
        <li><a href="#">VectorTuts</a></li>
        <li><a href="#">PsdTuts</a></li>
        <li><a href="#">PhotoTuts</a></li>
        <li><a href="#">ActiveTuts</a></li>
        <li><a href="#">Design</a></li>
        <li><a href="#">Logo</a></li>
        <li><a href="#">Flash</a></li>
        <li><a href="#">Illustration</a></li>
        <li><a href="#">More...</a></li>
       </ul>   
      </div>
     </div>
    </li>
    <? } else { ?>
    <li class="menu_right"><a href="http://x.<? echo $base; ?>/search/search.php" class="drop">Log in</a>
     <div class="dropdown_2columns align_right">
      <div class="col1_2">
      <div class="col_1">
       <p><b>Name:</b></p>
      </div>
      <div class="col_1">
       <form action="#" method="post">
       <input class="v2" name="name" placeholder="John Davis" style="width:98%" type="text" value=""/>
      </div>
      <div class="col_1">
       <p><b>Spirit ID:</b></p>
      </div>
      <div class="col_1">
       <input class="v2" name="primary_username" placeholder="XXXXXX-XXXXX" style="width:98%" type="text" value=""/>
      </div>
      <div class="col_1">
       <p><b>Primary Password:</b></p>
      </div>
      <div class="col_1">
       <input class="v2" name="primary_password" placeholder="Password" style="width:98%" type="password" value=""/>
      </div>
      <div class="col_1">
       <p><b>Username:</b></p>
      </div>
      <div class="col_1">
       <input class="v2" name="secondary_username" placeholder="JohnDavis101" style="width:98%" type="text" value=""/>
      </div>
      <div class="col_1">
       <p><b>Secondary Password:</b></p>
      </div>
      <div class="col_1">
       <input class="v2" name="secondary_password" placeholder="Password" style="width:98%" type="password" value=""/>
      </div>
      <div class="col_1"></div>
      <div class="col_1">
       <input class="button" type="button" value="Submit"/>
       </form>
      </div>
     </div>
    </li>
    <? } ?>


Best regards;
- Miguel de la Nieves

Founder, Headmaster & Chief Executive Officer at The Spirit Fonds (Lebensborn).
Learn to speak Japanese like a pro by clicking here!
- Request a professional web template construction miguelnieves.phoenixwarez@gmail.com (Skype).
- We make templates at whatever cost suites your demands!

Last edited by NievesCorp; 07-20-2012 at 05:37 AM. Reason: Code update
Reply With Quote
(#5 (permalink))
Old
Leder678's Avatar
Senior Member
Leder678 is on a distinguished road
 
Posts: 1,615
Join Date: Jan 2009
Location: Norway
Send a message via MSN to Leder678
Default 07-20-2012, 06:46 AM

Well, firstly, notice that using php shorttags is a bad habbit.
Then you should take a note that the menu only shows if your "name" isn't set, so whenever $_COOKIE["name"] is set, you will get to the "ELSE" part of the main code.

Also notice that you should use the isset() code for all of your cookie "ifs" (else some servers might give a "Notice: Undefined index: COOKIEKEY in " every now and then)

I acctually believe that you want the menu to only show when they have the cookie set? In that case, this code should work (I changed the shorttags to normal tags when I did this small, well "fix")

PHP Code:
    <?php 
    $_COOKIE
["name"] = "YoDude";
    if (    
        isset(
$_COOKIE["name"]) || 
        isset(
$_COOKIE["primary_username"]) || 
        isset(
$_COOKIE["primary_password"]) || 
        isset(
$_COOKIE["secondary_username"]) || 
        isset(
$_COOKIE["secondary_password"])) { 
    
?>
    <li class="menu_right"><a href="#" class="drop">
    <?php 
        
if (isset($_COOKIE["name"])) { 
            echo 
$_COOKIE['name']; 
        } else { 
            echo 
"You"
        } 
    
?>
        </a>
     <div class="dropdown_1column align_right">
      <div class="col_1">
       <ul class="simple">
        <li><a href="#">FreelanceSwitch</a></li>
        <li><a href="#">Creattica</a></li>
        <li><a href="#">WorkAwesome</a></li>
        <li><a href="#">Mac Apps</a></li>
        <li><a href="#">Web Apps</a></li>
        <li><a href="#">NetTuts</a></li>
        <li><a href="#">VectorTuts</a></li>
        <li><a href="#">PsdTuts</a></li>
        <li><a href="#">PhotoTuts</a></li>
        <li><a href="#">ActiveTuts</a></li>
        <li><a href="#">Design</a></li>
        <li><a href="#">Logo</a></li>
        <li><a href="#">Flash</a></li>
        <li><a href="#">Illustration</a></li>
        <li><a href="#">More...</a></li>
       </ul>   
      </div>
     </div>
    </li>
    <?php } else { ?>
    <li class="menu_right"><a href="http://x.<?php echo $base?>/search/search.php" class="drop">Log in</a>
     <div class="dropdown_2columns align_right">
      <div class="col1_2">
      <div class="col_1">
       <p><b>Name:</b></p>
      </div>
      <div class="col_1">
       <input class="v2" name="name" placeholder="John Davis" style="width:98%" type="text" value=""/>
      </div>
     </div>
    </li>
    <?php ?>
But The way you made the code, eighter you'll never need to use the "ELSE -> 'YOU'" or "IF ->'name'", deepending if you use isset() or !isset() on the $_COOKIE["name"]


Follow me on twitter @Mortenrb

W3Fools - Read and learn

Please AT LEAST read the 10 bolded lines of the TOS at:
http://www.000webhost.com/includes/tos.php

Last edited by Leder678; 07-20-2012 at 06:48 AM.
Reply With Quote
(#6 (permalink))
Old
NievesCorp's Avatar
Senior Member
NievesCorp is on a distinguished road
 
Posts: 930
Join Date: Jun 2009
Location: Sabana Hoyos, Arecibo, PR.
Send a message via MSN to NievesCorp Send a message via Skype™ to NievesCorp
Default 07-20-2012, 07:13 AM

Well, Leader I must say, I ow you one. It worked very well after I removed the -$_COOKIE["name"] = "John";- bit, because that bit was preventing the user from being able to enter their credentials.

Now my next task would be to create the actual "Mass Log in" processor and link it, work for tomorrow alongside the custom radio player.

Now let's talk about that "bad habit" of <? ?> tags, why is it a bad habbit, in your opinion?


Best regards;
- Miguel de la Nieves

Founder, Headmaster & Chief Executive Officer at The Spirit Fonds (Lebensborn).
Learn to speak Japanese like a pro by clicking here!
- Request a professional web template construction miguelnieves.phoenixwarez@gmail.com (Skype).
- We make templates at whatever cost suites your demands!
Reply With Quote
(#7 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 07-21-2012, 12:50 AM

On 000webhost.com server php.ini setting for short_open_tag is on. So, <? ?> is working
in this hosting. However, if you use short_open_tags with xml declaration something like
<? xml version="1.0" encoding="UTF-8" ?>, it causes error as php tags and xml declaration
tags are same.

Last edited by grace1004; 07-21-2012 at 10:42 AM.
Reply With Quote
(#8 (permalink))
Old
Leder678's Avatar
Senior Member
Leder678 is on a distinguished road
 
Posts: 1,615
Join Date: Jan 2009
Location: Norway
Send a message via MSN to Leder678
Default 07-21-2012, 08:29 AM

well, shorttags doesn't work on every server, but the normal tags do.
That's the main reason I'd advice everyone to use the normal tags, pluss, drupal standards work that way, and they have some pretty smart standards


Follow me on twitter @Mortenrb

W3Fools - Read and learn

Please AT LEAST read the 10 bolded lines of the TOS at:
http://www.000webhost.com/includes/tos.php
Reply With Quote
(#9 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 07-21-2012, 09:29 PM

Quote:
Originally Posted by Leder678
well, shorttags doesn't work on every server, but the normal tags do.
Go to your Cpanel - >> Software/Services - click 'View PHP Configuration', you will get
a table showing configuration of php, Apache and MySQL for your hosting server. In the
table under PHP Core, you will see short_open_tag is On, in which case <? ?> is working.
If you test a php file with short_open_tag, you will see it is working.

Last edited by grace1004; 07-21-2012 at 09:33 PM.
Reply With Quote
(#10 (permalink))
Old
Leder678's Avatar
Senior Member
Leder678 is on a distinguished road
 
Posts: 1,615
Join Date: Jan 2009
Location: Norway
Send a message via MSN to Leder678
Default 07-22-2012, 11:06 AM

Quote:
Originally Posted by grace1004 View Post
Go to your Cpanel - >> Software/Services - click 'View PHP Configuration', you will get
a table showing configuration of php, Apache and MySQL for your hosting server. In the
table under PHP Core, you will see short_open_tag is On, in which case <? ?> is working.
If you test a php file with short_open_tag, you will see it is working.
I'm talking about servers in general, not only 000webhost servers.
And whenever you move to a different host, there is a slight chance that the shorttags won't work.
And if you are ever planning to make a CMS or any public scripts, you'll end up having a lot of people whom cannot use your script IF you use shorttags, allthough a lot of people could fix it, a lot of people have no idea how to open a Php file.

Just sayin' it's kinda a bad habit to use shorttags.


Follow me on twitter @Mortenrb

W3Fools - Read and learn

Please AT LEAST read the 10 bolded lines of the TOS at:
http://www.000webhost.com/includes/tos.php
Reply With Quote
Reply

Tags
cookie, isset, members area, multiple, php

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com