IF else

Links for php scripts

Moderators: macek, egami, gesf

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

IF else

Postby kiwi » Mon Jul 05, 2004 8:19 pm

how to write a code that, if the statement if this, then go to another page, if not go to same page, i use this to check the password, can u do for me, ? thanks

Alex
New php-forum User
New php-forum User
Posts: 180
Joined: Fri Mar 07, 2003 4:59 pm
Contact:

Postby Alex » Tue Jul 06, 2004 5:23 pm

ok if then else statement looks like this:

Code: Select all

if(whatever you are checking goes here)
{
if statement is true execute this;
}
else
{
do something else;
}

but really there are a bunch of programs out there for free that you can use instead of what you write, that would be safer, securer, faster, almost hassle free and do not require any programming experience...
also you can check out a manual on the site of the producers of the zend engine, the very engine that php runs off of, here is the link:
http://www.zend.com/manual/

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Postby kiwi » Tue Jul 06, 2004 6:10 pm

i know how the code structure look like, but i dont know the funtion to use,, if the statement true then go to other page, if false then show message, and go to the current page back, that is what i want, can u help me? thanks

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Postby kiwi » Tue Jul 06, 2004 6:23 pm

can you help ,e to convert this codes to PHP, this is what i want... thanks

<?php
if($password){
if($password==coach){
?>
<script language="JavaScript">
location="http://www.charlottesoccer.com/coach.php3";
</script>
<?php
}elseif ($password==admin){
?>
<script language="JavaScript">
location="http://www.charlottesoccer.com/admin.php3";
</script>
<?php
}elseif ($password==member){
?>
<script language="JavaScript">
location="http://www.charlottesoccer.com/member.php3";
</script>
<?php
}elseif ($password==guest){
?>
<script language="JavaScript">
location="http://www.charlottesoccer.com/guest.php3";
</script>
<?php
}else{
?>
<script language="JavaScript">
location="http://www.charlottesoccer.com/signin.php3";
</script>
<?php
}
}
?>

Alex
New php-forum User
New php-forum User
Posts: 180
Joined: Fri Mar 07, 2003 4:59 pm
Contact:

Postby Alex » Thu Jul 08, 2004 3:53 pm

Ok, there are many ways to do this, but i think the siplest would be to make a page that will say that the user is logged on, and then provide a link to the page that you want them to going to.
Another great way to do this is instead of having the script reroute the user to another page, have the contents of the page show up in the same window, for that all you need to do is combine your pages into functions i.e. put the code of the page inside a function, put all functions in one file say page_fns.php and then require the file in the page that you want me to rewrite.
See, what you have to understand is that PHP is a server side language, so you can't really interact with users browser unless you request a variable from it, send them a form to fill out or pass vars through urls that you provide.
Another point here, what you are doing is really not safe security-wise. You should really store these passwords encrypted in a database or if you dont have one available, in a file that is much harder to access on your server than getting the code for your page.
Ok finally, there is a better way of doing what you are doing (code-wise), cleaner and faster anyhow:

Code: Select all

//this will come out of what i said before about putting the code for the
//pages in functions and then executing them if you need to
require_once['page_fns.php']; //page_fns.php - pages functions file
switch($password)
{
case coach:
coach_page($password); //i would check for the password on the page
//just so noone can try to execute it without a propper password
break;
case admin:
admin_page($password);
break;
case member:
member_page($password);
break;
case guest:
guest_page($password);
break;
default:
default_page; // here you can put the form that you used before
}
//note i do not see where you derive $password from, but i hope
//that you handled it earlier in the script

if you have any questions about the switch function click the link...


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron