...

View Full Version : Specific incorporating problem - easy



deaf_digit
01-11-2006, 04:39 PM
Hi.. this is kind of a very specific problem.
I have a login-script on my site and it's working like a charm.
Only problem is that when you log in you are directed to a very boring site, log.php:


<?
// This is the main part, log.php

// Constants
include("cons.php");
// If the user exists
if ($user) {
echo "Welcome ".$user."! "; // Welcome message
echo "Menu: "; // shows the menu
echo "(<a href=\"inbox.php\">Inbox</a> | "; // creates inbox button
echo "<a href=\"login.php?out=yes&user=$user\">Logout</a> | ";// Logout button
echo "<a href=\"edit.php\">Edit Account</a>";
if ($admin) {
echo " | <a href=\"admin.php\">Admin Centre</a> | ";
}
if ($mod) {
echo " <a href=\"mod.php\">Moderator Centre</a> | ";
}
echo ")";
echo " ";

/****************************************************/
/***** This shows how many users are active and *****/
/*********** it shows their names too! **************/
/****************************************************/

$ro = mysql_query("SELECT * FROM active_users");
$active = mysql_num_rows($ro); // sets $active as the number of active users
echo "Currently active users: ".$active.", "; // lists the number of active users

// Actually lists the users
while ($ra = mysql_fetch_array($ro)) {
$name = $ra['name']; // Sets $name as the users' names

// Lists the users names
if ($i != ($active - 1)) { // if $i doesn't equal $active minus 1
echo $name." | ";
}
else {
echo $name;
}

$i++; // increase temp variable
}
/******************************************/
/********** End of active users! **********/
/******************************************/
}
else {
if ($reg) {
echo $reg;
}
/********** Show the login form ************/
?>
<html>
<head>
<style type="text/css" media="screen">
<!--
#regi {
position: absolute;
width: 130px;
top: 135px;
left: 435px;
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 3;
}
--></style>


<body bgcolor="#e0eeee">
<div id="regi">
<form action="login.php">
<input type="text" name="name"> Username<br>
<input type="password" name="pass"> Password<br>
<input type="submit" value="Login!">
</form>
Er du endnu ikke registreret? Så <a href="reg.php">klik her</a> og bliv det!
</div>
<br><br><br>
<a href="index.php" target="_self">Tilbage til forsiden</a>
</body>
</html>
<?
/*********** End of login form ************/
}
?>

Now, I would like to incorporate the most essential things from this script into the main site, which would be like a members-index.php for members that are logged in. The codes for the main site are here:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">



<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>The Official Site of The Dingodism</title>
<script>
var oLogmeImg = new Image();
oLogmeImg.style.visibility="hidden";
oLogmeImg.src=
"http://www.Website-Tracking.com/Logme/FoxLog.dll/logme.logme.Logme?dingodism,"
+ escape(document.location.href.substr(document.location.href.lastIndexOf("/") + 1))
+ " ," + escape(document.referrer) + " ," + window.navigator.appVersion
+ " ," + window.screen.width;
</script>

<style type="text/css" media="screen">
<!--

html>body { /* just for the little image on top right */
background-image: url(t2_45x44_grey.gif); /* take your image or remove */
background-repeat: no-repeat;
background-position: top right;
}

body {
margin-top: 60px; /* take care - if changed - all boxpositions must be changed too */
margin-right: 10px;
margin-bottom: 10px;
margin-left: 10px;
border: 0 none; /* border: 1px solid #fff; for proof only - if - box-positions will change */
padding: 0px;
background-color: #ccccff;
color: #555;
font-size: 10px;
line-height: 16px;
font-family: Verdana, Geneva, Helvetica, Arial, sans-serif;
z-index: 1;
}

h1 {
font-size: 12px;
line-height: 16px;
font-family: Verdana, Geneva, Helvetica, Arial, sans-serif;
font-weight: bold;
color: #555; /*overskrift*/
margin: 0px 0px 0px 0px; /* top, right, bottom, left */
padding: 0px;
}

p {
font-size: 10px;
line-height: 16px;
font-family: Verdana, Geneva, Helvetica, Arial, sans-serif;
color: #555; /*normal skrift*/
margin: 0px 0px 0px 0px; /* top, right, bottom, left */
padding: 0px;
}

a {
color: #ddd;
text-decoration: none;
}

a:link {
color: #555;
}

a:visited {
color: #777;
}

a:hover {
background-color: #ccc;
color: #999;
font-weight: bold;
}

img { /* affects all images */
border: 0 none;
}

img.w3cimage { /* affects only images with class w3cimage */
background-color: #ccc;
border: 0 none;
vertical-align: middle;
}


.content {
position: relative; /* Position is declared "relative" to gain control of stacking order (z-index). good idear ... */
width: 640px; /*fleksibelt: auto*/
min-width: 150px;
margin-top: -2px; /* because of headliner */
margin-right: 0px; /* width of rightside + position right */
margin-bottom: 61px;
margin-left: 160px; /* width of leftside + position left */
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 4; /* This allows the content to overlap the right menu in narrow windows in good browsers. */
}

.underbox {
position: relative; /* Position is declared "relative" to gain control of stacking order (z-index). good idear ... */
width: 640px; /*fleksibelt: auto*/
min-width: 150px;
margin-top: -52px; /* because of headliner */
margin-right: 0px; /* width of rightside + position right */
margin-bottom: 61px;
margin-left: 160px; /* width of leftside + position left */
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 4; /* This allows the content to overlap the right menu in narrow windows in good browsers. */
}

#member {
position: absolute;
width: 960px;
height: 20px;
top: 220px;
left: 10px;
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 3;
}

#leftside {
position: absolute;
width: 130px;
top: 270px;
left: 10px;
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 3;
}

#leftside ul {
font-family: Verdana, Geneva, Helvetica, Arial, sans-serif;
font-size: 10px;
line-height: 18px;
margin: 0px 0px 0px 0px;
padding: 0px;
}

#leftside li {
list-style-type: none;
border-bottom: 1px dotted #666;
margin: 0;
}

#leftside li a {
display: block;
padding-left: 10px;
color: #555;
text-decoration: none;
width: 120px;
background-image: url(bullets_c_01.gif);
background-repeat: no-repeat;
background-position: 0px 6px;
}

#leftside li a:hover {
display: block;
padding-left: 15px;
color: #ff0000;
background-color: #ccc;
text-decoration: none;
width: 115px;
background-image: url(bullets_c_03.gif);
background-repeat: no-repeat;
background-position: 0px 6px;
font-weight: bold;
}

#leftside li a:visited { /* shows the visited links with other image */
display: block;
padding-left: 10px;
color: #555;
text-decoration: none;
width: 120px;
background-image: url(bullets_c_01.gif);
background-repeat: no-repeat;
background-position: 0px 6px;
}

#leftside li a:visited:hover { /* if you use li a:visited then this */
display: block;
padding-left: 15px;
color: #ccc;
background-color: #999;
text-decoration: none;
width: 115px;
background-image: url(bullets_c_03.gif);
background-repeat: no-repeat;
background-position: 0px 6px;
font-weight: bold;
}


.headliner {
position: relative;
width: 685px; /* is positioned after body, so it gets the right width *//*brug auto for flex*/
top: -60px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
border: 1px solid #000;
background-color: #e0eeee;
color: #ccc;
font-weight: bold;
padding: 10px;

z-index: 6;
}

#underls {
position: absolute;
width: 130px;
top: 410px;
left: 10px;
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 3;
}

#poll {
position: absolute;
width: 130px;
top: 520px;
left: 839px;
border: 1px solid #000;
background-color: #e0eeee
z-index: 3;
}

#login {
position: absolute;
width: 130px;
top: 270px;
left: 840px;
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 3;
}


--></style>
</head>

<body>
<div class="headliner">
<img src="grafik/header_2.jpg" width="960" height="180" border="0" align="middle">
</div>
<div class="content">



<font color="gray">Dingodism.tk<br>----------------</font>
<br><br>
<center>
<h1>Velkommen til DINGODISMENS OFFICIELLE <font color="red">TEST-</font>hjemmeside!!!</h1>
<hr><br>
Som det kan ses er siden stadig under opbyggelse, men bare rolig - i løbet af kort tid bliver her masser <br>
af sjov og spas. <br><br>
Hilsen Disciplene og Den religiøse leder
<br><br><br>
<i>Æret være den Ferske Dingo</i>

</center>

<br>

</div>
<div class="underbox">

<script language="JavaScript">
<!--
document.write("Sidst opdateret: ");
document.write(document.lastModified);
//-->
</script>
<br>
<br>
<u>Webmasters:</u><br>
deaf_digit <br>
DigitalDingo
</div>


<div id="leftside">
<h1>Menu</h1>
<br> <ul>
<li><a href="index.htm">Main <--</a>
<li><a href="info.htm">Info</a>
<li><a href="nyheder.htm">Nyheder</a>
<li><a href="artikler.htm">Artikler</a>
<li><a href="contact.htm">Kontakt</a>
<li><a href="links.htm">Links</a>
<li><a href="http://s14.invisionfree.com/Dingodismen/index.php?" target="_new">Forum</a>
<li><a href="pray_ask.php">Bed en bøn</a>
</ul>
</div>

<div id="poll">
<script src=http://www.mypoll.dk/module/myPoll.php?checkkey=b6e88e086c057871c723b1f69d008742></script>
</div>
<div id="member">










</div>
<div id="login">
<h5>Log ind:</h5>
<form action="login.php">
<textarea name="name" rows="1" cols="15" style="overflow: hidden"></textarea> Brugernavn
<textarea name="pass" type="password" rows="1" cols="15" style="overflow: hidden"></textarea> Kodeord
<br><br><center>
<input type="submit" value="Login!">
</center>
</form>
<h7>
Er du endnu ikke registreret? Så <a href="reg.php">klik her</a> og bliv det!
</h7>
</div>
</body>
</html>




how do I do this in a smart way? .. I would like for the menu-thing from the log.php to be displayed in the <div id="member"></div> that I've made. Also...if you're not identified you should be redirected to index.php


I know this is a big one...please help anyway... thanks a bunch :)

Element
01-11-2006, 08:31 PM
All you need to do is track the with sessions or cookies. I like to use cookies for things I obviously want to keep for a long period of time. Sessions are good in the other case, or even with cookies for the users pass and username.


Anyway, here is a method you might find usefull.




// We checked if they're logged in above using your code...

if($user) { setcookie("user", $user, time()+3600) or die("Unable to set cookie!"); $sc = true; }
if($mod) { setcookie("mod", $mod, time()+3600) or die("Unable to set cookie!"); $sc = true; }
if($admin) { setcookie("admin", $admin, time()+3600) or die("Unable to set cookie!"); $sc = true; }

if($sc) {
header("Location: http://example.com/index.php"); // Take us back to the index where the cookies will be used to define what will be shown on the index.
}



Then on the index you use an if/elseif/elseif/else statement to set the different things that will be shown. The last else will be for a guest. I'm not exactly sure how you work your script but that would probably work.

And in the statements to call the cookie it would be $_COOKIE['user'], $_COOKIE['mod'], $_COOKIE['admin'], so you would need to find out which one is set. This could be done with one cookie but I wasn't sure what is exactly in the variables...

deaf_digit
01-13-2006, 05:03 PM
Hmm... okay.. that sounds reasonable..
uhm.. you talk about a cookie that detects which coockie is set ($admin, $mod or $user). What would the coding of that coockie be? .. I'm not all that good at this :D ..

Oh and the call of the coockies.. could you give me a structure for those?
Thanks a lot :)

Element
01-13-2006, 09:24 PM
no it would just be:



if(isset($_COOKIE['user']) && $_COOKIE['user'] == "Whatever it should") {
// Do Users stuff, if the user cookie is set
} elseif(isset($_COOKIE['mod']) && $_COOKIE['mod'] == "Whatever it should") ) {
// Do Mod stuff, if the mod cookie is set.
} elseif(isset($_COOKIE['admin']) && $_COOKIE['admin'] == "Whatever it should") ) {
// Do Admin stuff, if the admin cookie is set
} else {
// Do Guest stuff, because no cookies were found.
}

deaf_digit
01-13-2006, 11:37 PM
Ahh... I see.. well that makes so much more sence :D

Oh just one more thing - "Whatever it should" ??? .. meaning whatever it should do? .. whatever it should be set to? .. whatever the value of the coockie?.. bear with me.. I'm a noob :D

marek_mar
01-14-2006, 12:39 AM
Is this supposed to be a security measure? I can edit my cookies...

deaf_digit
01-18-2006, 03:48 PM
No.. there is no security in the picture. I very much doubt it that anyone would wanna hack my page... :D ..

marek_mar
01-18-2006, 03:51 PM
Give me a link.

deaf_digit
01-19-2006, 10:47 PM
Okay..

here you go..

http://www.dingodism.frac.dk

it's in danish so you'll probably don't understand any of it but I'll be happy to explain if it helps :)

marek_mar
01-20-2006, 12:04 AM
Hey let me try to translate (I never even tried to learn danish)
So far I've got:
"Welcome to ythe official homepage of dingodsimes.
Some of the pages are constantly in construction(?)..."
Is that "dingodsimes" a religion?

deaf_digit
01-20-2006, 12:23 AM
hehe you catch on quick..

The first couple of lines say

"Welcome to the official homepage of the dingodism. (check the header-picture ;) )
As you can see the page is still under construcktion, but pretty soon there will be losts of fun stuff"

So nice guess :D

dingodismen [da] = dingodism [en]

Yeah it's kind of a religion - purely for the fun of it - I'll have an english version ready soon :p

Anyways...could you help me with my problem? .. It's really buggin' me :o

hehe.. thanks :)

deaf_digit
01-24-2006, 06:45 PM
come on...please guys.. I really need some help with this :confused: ...is it really that difficult?

Element
01-24-2006, 10:43 PM
What more is there to help with? Just do as I instructed. And you may be able to edit your cookies marek_mar, which is why its checking to make sure it equals the parameter the script gave the cookie. Try what I explained, and post back with ay problems that might be in the code, or something you might have done to make it throw a fit.

deaf_digit
01-26-2006, 02:57 PM
uhm... okay.. here we go then.. I modified the log.php to fit with the you gave me above... now it's like this:


<?
// This is the main part, log.php

// Constants
include("cons.php");
// If the user exists
if($user) { setcookie("user", $user, time()+3600) or die("Unable to set cookie!"); $sc = true; }
if($mod) { setcookie("mod", $mod, time()+3600) or die("Unable to set cookie!"); $sc = true; }
if($admin) { setcookie("admin", $admin, time()+3600) or die("Unable to set cookie!"); $sc = true; }

if($sc) {
header("Location: another.php"); // Take us back to the index where the cookies will be used to define what will be shown on the index.
}
else {
if ($reg) {
echo $reg;
}
/********** Show the login form ************/
?>
<html>
<head>
<style type="text/css" media="screen">
<!--
#regi {
position: absolute;
width: 130px;
top: 135px;
left: 435px;
border: 1px solid #000;
background-color: #e0eeee;
padding: 10px;
z-index: 3;
}
--></style>


<body bgcolor="#e0eeee">
<div id="regi">
<form action="login.php">
<input type="text" name="name"> Username<br>
<input type="password" name="pass"> Password<br>
<input type="submit" value="Login!">
</form>
Er du endnu ikke registreret? Så <a href="reg.php">klik her</a> og bliv det!
</div>
<br><br><br>
<a href="index.php" target="_self">Tilbage til forsiden</a>
</body>
</html>
<?
/*********** End of login form ************/
}
?>

BTW the first couple of lines are the changed ones..

Then I tried to use the cookies on my member's index:


<div id="member">
<?
if(isset($_COOKIE['user'])) {
echo "Welcome ".$user."! "; // Welcome message
echo "Menu: "; // shows the menu
echo "(<a href=\"inbox.php\">Inbox</a> | "; // creates inbox button
echo "<a href=\"login.php?out=yes&user=$user\">Logout</a> | ";// Logout button
echo "<a href=\"edit.php\">Edit Account</a>";
} elseif(isset($_COOKIE['admin'])) {
echo " | <a href=\"admin.php\">Admin Centre</a> | ";
} elseif(isset($_COOKIE['mod'])) {
echo " <a href=\"mod.php\">Moderator Centre</a> | ";
} echo ")";
echo " ";

?>

</div>

This is what I've tried - it seems logical to me, but the problem is, that no matter who logs in they are treated as "user". That's the problem right now..
Really hope you can help me :)

marek_mar
01-26-2006, 04:16 PM
The code in the last php section. Change the elseif to if. Admins have all 3 cookies set and mods two. You could use only one cookie with a user level stored. But you don't have to.

deaf_digit
01-26-2006, 05:24 PM
Okay.. &#180;with that settled answer me this... Why the heck didn't I think of that? .. that logical damn it hah.. thanks Marek_Mar and Element



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum