a simple thing?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vinny199
Forum Newbie
Posts: 8
Joined: Sun Nov 16, 2003 12:58 pm
Location: London

a simple thing?

Post by vinny199 »

Hi,

Being a beginer with php, I'm having a few difficulties...
I am trying to modify a php page form a script.

In the body page there is: <?=loginbox()?> which refers to a block of code in the main.php file and generates a login box.

Instead of having that login box constantly displayed on the page, I'd like to have a simple Admin text link, and only when you click on it, the page reloads and shows the login box in place of the link.

how can I get a link to generate: <?=loginbox()?> when reloading the page?

Can you help please?

thanks,

Vinny
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

To run a function it has to be defined somewhere in the script, then you just need to call it with whatever arguments it needs (in this case none, I think).

So, if login() is defined in a library file somewhere, write a script which includes the library file and then makes a login(); function call. Now you can create a hyperlink to the file you just wrote.

If the file containing the login function definition contains executable code (by which I mean some lines of code which do something rather than just define a bunch of functions) it gets more complicated.

You'd want to remove the login() fn from that file, and put it in its own library file - say login.php. Now you can use the fn anywhere by including login.php (don't forget to add an include in the original file which expects login() to be defined).

The precise action to take depends on the program you're working with but I hope that gives you the general idea.
vinny199
Forum Newbie
Posts: 8
Joined: Sun Nov 16, 2003 12:58 pm
Location: London

Post by vinny199 »

Thanks very much for your reply,
Here is what I tried (still not working, can you see what I’m doing wrong?)

Lert me explain better:

There are 3 files involved:

1/ index.php
all that is in this file is this:

include('./cmsimple/cms.php');

2/ cms.php

here is where the login function is:

function loginbox(){global $uname,$suadm,$sn,$tx;if($uname!=""){$tmp=loginlink();$tmp.='<a href="'.$sn.'?&forum&v=profile">'.$tx['login']['profile'].'</a><BR>';if($suadm)$tmp.=u_e_print(); return $tx['login']['welcome']." ".$tmp; } else {return '
<form name="login" action="../forum/login.php" method="post" style="margin:0"><input type="hidden" name="sendLogin" value=""><input type="hidden" name="md5" value="">'.$tx['login']['name'].': <input type="text" name="name" size="12" class="search"><br><br>'.$tx['login']['pass'].': <input type="password" size="12" name="password" class="search"><br><br>'.$tx['login']['remember'].': <input name="remember" type="checkbox" checked class="search"><br><br><input type="button" name="sendLogin" value="Login'.$tx['login']['button'].'" class="search" onclick = "login.md5.value=hex_hmac_md5(login.name.value,hex_md5(login.password.value));submit(login)"></form><BR><a href="'.$sn.'?&forum&v=register">'.$tx['login']['register'].'</a>';} }

3/ an html file (my page): index.htm

With this in the code:
<?=loginbox()?> the login box is always on display.

I am trying to get this login box to show up on the page only when you click a lik: admin

I have tried to do this:

<? $action = $_GET['action'];
if($action = login)
{
loginbox();
}
?>

to replace <?=loginbox()?> and made a link admin: /cm/index.php?action=login

That just reloads the page but not show the login box on reload.

How do I do this?

Thanks for your help,

Vinny
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

I had to read it quick because i have to leave now but from what I am seeing in your function, your are just returning all the HTML code for the login box. You are not actually echoing it or printing it. To work this way you will need to do.

if($action = login)
{
$loginbox = loginbox();
echo $loginbox;
}
Post Reply