Jump to content


Photo

PHP problem.. getting REALLY mad!! [-SOLVED-]


  • Please log in to reply
10 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 August 2006 - 03:54 PM

I have a  login form on my site that, when the user logins in, it turns into a panel of controls they have.. it worked until i tried to put things into functions.. but now it displays the login form even if the person logins in...which its not supposed to! here is the file that has the function: (the function is called "navBar")

<?php
function DisplayLinks(){
?>
<div align=left>
<a href="home">Home</a> | <a href="register">Register</a> | <a href="contact">Contact Us</a> | <a href="http://www.forums.zycogaming.xerodefect.com">Forums</a>
</div>
<?
}
?>

<?php
function show_errorPage(){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ZycoWorld</title>
<link rel="stylesheet" href="files/3col_rightNav.css" type="text/css">
</head>
<body link="#FF3333" vlink="#FF3333" alink="#000000"> 
<div id="masthead"> 
  <h1 id="siteName"><IMG SRC="files/zyLogo1.jpg"></h1> 
  <div id="globalNav"> 
 <? DisplayLinks(); ?></div> 
  <br> 
<hr align="left" width=55%>
<h2 id="pageName">Home</h2>
<!-- end masthead --> 
<div id="content"> 
<hr>
  <div><span class="feature"> 
    <h3>You Must Be Logged In</h3> 
    <p> 
    You cannot view this page, you need to Login at the <A HREF="main.php">HOME</A> Page, or <A HREF=register>REGISTER</A> to be able to view.
  </div> 
   
</div> 
<!-- end content --> 
  <? navBar(); ?>
  </div> 
</div> 
<!--end navBar div --> 
<div id="siteInfo"> 
  <? siteInfo() ?>
  </div>
</div> 
</body>
</html>
<?
}
?>

<?
function getVideos(){

	$path = $_ENV['DOCUMENT_ROOT'];
	$d = $path.'/uploads/uVideos/';
	$dir = opendir($d);
	while ($f = readdir($dir)) {
	 if (eregi("\.swf",$f))
			$files[]=$f;
	}
	return $files;
}

function navBar(){
if($logged_in){
?>
<div id="navBar"> 
  <div id="search"> 
<form action="http://www.zycogaming.xerodefect.com/cgi-sys/entropysearch.cgi" target="searchwindow">
Zyco SiteSearch: <br><input name="query" value="" type="text">
<input name="user" value="zyco" type="hidden">
<input name="basehref" value="http://zycogaming.xerodefect.com" type="hidden">
<input name="template" value="default" type="hidden">
<input value="Search" type="submit">
</form>
  </div> 
  <div id="sectionLinks"> 
    <h3>Your Controls</h3>
    <ul> 
      <li><a href="home">Home</a></li> 
      <li><a href="uVid">Video Upload</a></li> 
      <li><a href="uPic">Picture Upload</a></li> 
      <li><a href="editProfile">Edit zPage</a></li> 
      <li><a href="/newlayout/<?php echo "$_SESSION[username]"; ?>.html ">View zPage</a></li> 
      <li>Games</li> 
    </ul> 
  </div> 
  <div class="relatedLinks"> 
    <h3>Affiliates</h3> 
    <ul> 
      <li><a href='http://flamelicker.com'><img src='http://flamelicker.com/newsite/affiliates/flamelicker.png'></a></li> 
	  <li><a href="http://www.xerodefect.com">XeroDefect Studios</a></li> 
    </ul> 
  </div> 
  <div class="relatedLinks"> 
    <h3>Other</h3>
    <ul> 
      <li><A HREF="http://www.zycogaming.xerodefect.com/brenden">Brenden's zPage</A></li>
	  </li> 
    </ul> 
  </div> 
</div> 
<?
}else
?>
<div id="navBar"> 
  <div id="search"> 
<form action="http://www.zycogaming.xerodefect.com/cgi-sys/entropysearch.cgi" target="searchwindow">
Zyco SiteSearch: <br><input name="query" value="" type="text">
 <input name="user" value="zyco" type="hidden">
<input name="basehref" value="http://zycogaming.xerodefect.com" type="hidden">
<input name="template" value="default" type="hidden">
<input value="Search" type="submit">
</form>
  </div> 
  <div id="sectionLinks"> 
    <h3>Please Login</h3>
    <form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td >Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td >Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td colspan="2" align="left" ><input type="checkbox" name="remember">
<font size="2">Remember</td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr>
<tr><td  colspan="2" align="right"><a href="register">Register</a></td></tr>
</table>
    </form>
  </div> 
<?
}
?>

<?  
  function siteInfo(){  
  ?>  
  <div id="siteInfo">   
    <p><a href='http://flamelicker.com'><img src='http://flamelicker.com/newsite/affiliates/flamelicker.png'></a> &copy;2006 ZycoWorld.com</p>  
    <div align=center>  
    <ul>  
    <A HREF=home>Home</A> |   
    <A HREF=/contact>Contact Us</A>  
    </ul>  
    </div>
  </div>   
  <?  
  }  
  ?>

<?
function editProfile(){
?>
<div align=center>*You are curently updating the profile for User: 
<?php echo '<a href="' . $_SESSION['username'] . '.html">' . $_SESSION['username'] . '</a>'; ?>.
 Click the name to see your profile.</div></b>
<p>
<hr>
<p>
<?php
$currentUser = "$_SESSION[username].html";
$loadcontent = "$currentUser"; 
    if($save_file) { 
        $savecontent = stripslashes($savecontent); 
        $fp = @fopen($loadcontent, "w"); 
        if ($fp) { 
            fwrite($fp, $savecontent); 
            fclose($fp); 
print '<div align=center><font color=red><b>Profile has been updated! Click <a href='.$_SERVER[PHP_SELF].'>HERE</a>to refresh the Editor.</b></font></a></div>'; 

} 
} 
    $fp = @fopen($loadcontent, "r"); 
        $loadcontent = fread($fp, filesize($loadcontent)); 
$lines = explode("\n", $loadcontent);
$count = count($lines);
        $loadcontent = htmlspecialchars($loadcontent); 
        fclose($fp); 
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a\n";
}
?> 

<form method=post action="<?=$_SERVER[PHP_SELF]?>"> 
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="97%" align="center" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px" name="savecontent" cols="100" rows="25" wrap="OFF"><?=$loadcontent?></textarea></td>
  </tr>
</table> 
<div align=center>
<input type="submit" name="save_file" value="-Save-">  |  <input type="submit" name="save_file" value="-Update Profile-">
</div>    
</form>
<p>
<hr>
<p>
<b>Want a profile like mine? Don't know HTML? No worries!! Copy the code below into the box above, edit it and BAM! You have a snazzy profile!! Just edit the CAPITAL PHRASES to match yourself.</b>
<br>
<textarea cols=100 rows=25>
<html>
<head>
<title>ENTER A TITLE TO YOUR PAGE HERE</title>
</head>
<body bgcolor=#F0E68C>
<div align=center>
<h1><u>YOUR USERNAME HERE</u></h1><br>
<A HREF=http://www.zycogaming.xerodefect.com/index.php>[HOME]</A>
<A HREF=http://www.zycogaming.xerodefect.com/register.php>[REGISTER]</A>
<A HREF=http://www.zycogaming.xerodefect.com/contactus.php>[CONTACT US]</A>
</div>
<p><p><p>
<hr>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 BGCOLOR=FFCC66 ALIGN=CENTER>
<TR>
 <TD ALIGN=left HEIGHT=25>
YOUR NAME HERE
</TD>
</TR>
<TR>
 <TD ALIGN=left HEIGHT=100>
<img src ="YOUR IMAGE HERE" align ="left"><br>
Name: YOUR NAME HERE<br>
Age: YOUR AGE HERE<br>
Location: YOUR LOCATION HERE<br>
</TD>
</TR>
</TABLE>
<p>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 BGCOLOR=FFCC66 ALIGN=CENTER WIDTH=350>
<TR>
 <TD>
<i>About Me</i>:<br>
ENTER YOUR BIO OR FACTS HERE, ANYTHING YOU LIKE
</TD>
</TR>
</TABLE>
<br>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 BGCOLOR=FFCC66 ALIGN=CENTER WIDTH=350>
<TR>
 <TD>
<i>Music</i>:<br>
ENTER THE MUSIC YOU LISTEN TO, HERE
</TD>
</TR>
</TABLE>
</textarea>
<p>
<p>
<b>Want to add more sections?? Just modify this code and paste into your profile!!</b>
<br>
<textarea cols=100 rows=25>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 BGCOLOR=FFCC66 ALIGN=CENTER WIDTH=350>
<TR>
 <TD>
<i>ENTER HEADER HERE</i>:<br>
ENTER CONTENT HERE</TD>
</TR>
</TABLE>
</textarea>
<?
}
?>

<?
function headerLinks(){
if($logged_in){
?>
  <span class="relatedLinks">Hello,
  <strong><?php echo "$_SESSION[username]"; ?></strong>
.</span> | <A HREF=logout>Logout</A> | <a href="http://www.zycogaming.xerodefect.com/newlayout/<?php echo "$_SESSION[username]"; ?>.html">View zPage</a> | <a href="editProfile">Edit zPage</a> |<br> 
<span class="feature">Your zPage URL: http://www.zycogaming.xerodefect.com/newlayout/<?php echo "$_SESSION[username]"; ?>.html<br><br>
<?
}
?>
</span>
<?
}
?>

is there any errors?? i dont see why its showing the login form and not the controls.....
Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 August 2006 - 03:56 PM

here is the site:

http://www.zycogamin...t.com/newlayout
Link shortener with advanced, detailed statistics:

http://tyny.us/

#3 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 12 August 2006 - 03:57 PM

try doing a check
<?php
if($_SESSION[username]) == null){
?>
show the form
<?php
}
?>


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 August 2006 - 03:58 PM

Is the variable $logged_in being created out side of the functions. If it is you want to add
global $logged_in;
in each function that uses the $logged_in variable. As functions have there own variable scope and so PHP cannot access variables out side of the function unless you declare them as global.

#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 August 2006 - 04:01 PM

well $logged_in is already global.. its declared in my login.php page.... or somethin i just know its already global.. sorry im just really frustrated and dont know whats wrong
Link shortener with advanced, detailed statistics:

http://tyny.us/

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 August 2006 - 04:13 PM

How are you defining $logged_in as global. AFAIK you cannot define a variable as global out side of function.

#7 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 12 August 2006 - 04:19 PM

Generally speaking using globals to solve problems like this is considered bad programming in many quarters - you should pass the variables in as parameters to the functions that need them.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#8 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 12 August 2006 - 04:25 PM

What he's stating is that a variable outside the function() can't be accessed without actually declaring it as a global variable. Like this:

Won't work:

<?php
$life = 42;
function meaningOfLife()
{
print "The meanin of life is being $life<br>";
}
meaningOfLife();
?>


When it prints it doesn't print the value of the $life variable. BUT, if you do this:

<?php
$life = 42;
function meaningOfLife()
{
global $life;
print "The meanin of life is being $life<br>";
}
meaningOfLife();
?>

Then it will work and print the value. You may think that $life is a 'global' variable already. But not within a function it's not unless you declare it.

Hope this helps!

#9 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 August 2006 - 09:51 PM

Well after about an hours worth of changing things.. I fixed what was wrong! :)
Link shortener with advanced, detailed statistics:

http://tyny.us/

#10 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 12 August 2006 - 10:09 PM

Please share

#11 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 August 2006 - 10:25 PM

I kinda redid my entire layout in Dreamweaver and in stead of having a function that did this: "if user is logged in, show controls, else show login form" i added two seperate functions, one that shows the controls and one that shows the login form, and in my page i put...

<?php
if($logged_in){
 navBar();
}else{
loginBar();
}
?>

which is if the user is logged, show the "controls" function, otherwise shhow the loginform function.

Link shortener with advanced, detailed statistics:

http://tyny.us/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users