Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Conditional Login..


I have a form with a username & password field along with 3 radio buttons.

What I basically want to achieve is if radio button A is checked it will post the username & pass to a.php, If button B is checked it will post the username & pass to b.php and so on for button C.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Conditional Loop
I have one table, "players" that has player info including start season (year). I then have a table for each season with player stats, i.e. games played etc called stats200X where X is the year obviously.

I have no problem with extracting data from the current year, but what I would like to do is get data from previous years too. I was thinking about doing something like:

(year) - (startyear), which for example could be 3.

I don't know where to begin, but I want to be able to loop though previous years so that, if tables exist of course, I could do

select * from stats{Y -1}
display
select * from stats{Y -2}
etc

Would I need to hard code this or is there a way of doing this though a conditional loop?


Checkboxes,conditional
Basically I have what seems to be a very small problem but I am driving ny self mad trying to figure out what the problem is. Here is what I have: I have a form with two checkboxes:

<input type="checkbox" name="medicalcheck" >
<input type="checkbox" name="dentalcheck" >

the form is posting the a php file, decision.php, that simple checks to see if the boxes have been checked and performs an operation in either case. Here is the code:

Once Conditional Causes Error, The Other Doesn't...why?
There are 2 if statements at the beginning of this code snippet.  The one that is currently commented out works while the one that is not commented out yields this error

Parse error: syntax error, unexpected '{' in C:xampphtdocsench2index4.php on line 106

I am just not seeing why. Code:

Conditional Structures
I am wondering about conditional structures and the depth of nesting allowed, if at all. For example I know I can do this: Code:

Conditional Form
I want to condtionally display an HTML form. I havnt got a clue how it can be done, I suppose its the same way as putting html tables in php, but I cant get it to work. Here is the condtion:

<?php 
 if (!empty($pk))
  {    

And here is the form:

<form action="google.php" method="GET" name="deleteForm" >
<input type="hidden" name="pk" value="<? echo $pk;?>">
<input type="submit" value="Delete">
</form>

Conditional Third Expression In For Loop
Is it possible to make expr3 $i++ under one condition and $i-- under another? Instead of having the condition outside the loop and having two loops. Or I could just use a while loop, I guess.

Sessions + Conditional Include
I am having a little problem in trying to figure out why my session state is not expiring after I close the browser window. Having been used to the ASP way of doing things I am trying to get my head around this slightly different method of handling sessions in PHP....

What happens is that I log on to the site, do various things and then close it when I am finished. I return the next day to find that the 'logged in' menu is displayed first which shouldnt happen until you have logged in again.

I assumed that the session was been stored as a cookie but wasnt been released after the session terminates by default, but found I was wrong when I deleted all my internet files and went back to the site.

My code for the first page is as follows..

Conditional PHP Cookies; If Cookie = 1 Do This...
I've figured out cookies ... now I'm trying to combine them with if conditions.

For cookie 'bandwidth1' I want to echo that it is set to 1 by the cookie to confirm this in the brower through regular html.

My if/else statements don't seem to be working though...heres the code I have now.

<?php
setcookie("bandwidth1","0",time()+2592000,"/");
setcookie("bandwidth2","1",time()+2592000,"/");
setcookie("bandwidth3","2",time()+2592000,"/");
?>

<?php
if (isset($_COOKIE["bandwidth1"])=="1")
echo "Bandwidth is 1!";
else
echo "Bandwidth is unknown";
elsif
echo "Cookie was not set?";
?>

MySQL Conditional Statement
What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are

1) Author
2) Language
3) Type (Hardback or Paperback)

Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:

Writing Conditional Statement
I'm trying write a conditional statement that updates the database in 1 of 2 ways depending on the values given. I'm only 2 weeks into learning PHP/MySQL so I realize the way I've written it out is probably sloppy and more inefficient than what it could be. I've just been winging it from examples and trial and error and have gotten everything working except for this. I'm not sure if I have my logic or syntax wrong.

Application-specific details:
This is a simple invoicing application. Every invoice is in either 1 of 3 states:

- pending (default state when a new invoice is entered)
- paid (state when invoice is paid in full)
- partial (state when only partial payments have been made on the invoice)

What I'm trying to do is this:

1. If a partial payment is made on an invoice, the status is set to 'partial' (this is working)
2. If the payment posted was the full amount of the invoice or the final amount needed to pay it in full, the status is set to 'paid' (this is not working)

My processing logic works like this:
1. There is a total invoice amount stored in the invoice table represented by $total variable (working)
2. When payments have been made to that invoice (stored in the payments table), I show the remaining balance on their invoice by calculating the sum of those payments and subtracting them from the total (this is represented by the $diff variable and is working)
3. The part not working: When the remaining balance ($diff) minus the payment amount posted ($_POST['amount']) is equal to 0, the status is set to paid. PHP Code:

Conditional Statements And Loops
Not long ago I was asked to give PHP lections to some private IT
school. I'm on second lection now, and will be teaching my :) students
conditional statements (if..else and switch) and loops (while and for).
That was my story, now the question.

Can you give me an advise on some geeky use of those statements to stir
up some enthusiasm in students.

Mutlipart And/or Conditional Form
I have a form that needs to have conditional statements, and I am not sure how to "fix" this. The existing form is split in two parts - the form, and the processor. I would think that I will need to combine them, but..

Anyways - what I need is somewhat simple - if a certain option (from a <select>) is chosen, force another field to be completed. I also have 2 other fields that if the radio button is set to YES, require new fields. Ideally, the optional fields would only be shown to the user IF they are required.

Conditional Select From Mysql
I have a mysql database which stores race data that I want to open up to users for viewing. I want the user to be able to select various subsets of the data according to the parameters: race, gender, age, and type (and maybe sometime, by name as well). This is BOTH a mysql question and a php one, as I ask for a more efficient solution (see bottom this post).

Here is a snippet of how I am implementing the mysql statements to select only the exact subset of data. PHP Code:

Conditional Preg Match
The following bit of code does a preg match and does something if true
(sets $browser to ppcie)

Without using if then and else's how do I code it so it does not equal
what it is testing for? So if it does not find ppc in the $agent then
it does something else/sets it to something else?

$agent = getenv("HTTP_USER_AGENT");
if (preg_match("/PPC/i", "$agent")) {
$browser = 'PPCIE'
}

Question On Conditional Statements
I'm a perl programmer and am trying to learn PHP.

So far I have figured out most of the differences, but have not been able to
find out how to do the following:

When running through a loop, how can you test two separate conditions
against the same $element of an array. For example, this is how I thought it
would be done (similar to Perl), but it did not work:

if (eregi("apple", $line) and (eregi("orange", $line) {

do whatever;

}

Basically testing each line of an array to see if both the words "apple" and
"orange" are present.

Also, is there any equivalent to the following from Perl while running
through a loop:

next if (whatever conditions);
last if (whatever conditions);

Help With Posting Conditional If Statement
I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit.

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method="POST" action="some.php">";

}

if ($holdchk == 0 ){
echo "<form method="POST" action="other.php">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

Conditional List Boxes
I am attempting to create a list box that is dynamically populated based on the selection of another list box.  I am in way over my head..only way to learn I guess.  The code below has a year listbox and then based on the year selection, the page should either show another listbox (show industry selection when year <> 2005) or it should render the main form (when year=2005). I cannot get the main form to appear. Code:

Conditional Email Text To Hyperlink
I am trying to write a content management section for a web site.

I have managed so far to use htmlarea to give users a basic, but user
friendly interface by which to edit the page content.

The user can add emails by symply typing john@example.com - IE automatically
converts this to a hyperlink. The trouble is sometimes the users use plain
text. I have been using the following line to convert plain text to a
hyperlink:

$pagetext=ereg_replace('[A-Za-z0-9_]([-._]?[A-Za-z0-9])*@[A-Za-z0-9]([-.]?[A-Za-z0-9])*.[A-Za-z]+',
'<a href="mailto:?subject=Email%20from%20web%20site"></a> ',
$pagetext);

This works well - BUT it completely screws up any existing hyperlinks. Is
there a way to convert the plain text email address in to a hyperlink only
if it is NOT part of a hyperlink.

Basically I need some way of checking
* If it's plain text > convert to a hyperlink
* If it's already an email hyperlink leave it alone.

I have tried looking up and testing everything I can think of - but am
finally asking around before I go mad.

Simplifying A Basic If Statement Conditional
Is there a more efficient way to write this:
if($var=1 || $var=4 || $var=27 || $var=28 || $var=30 || $var=37||
$var=38){echo "true";}

Avoiding Endless Conditional Statements
Here is my problem. I want to make a webapp that will basically take
the work out of finding what tool works for what situation. There are
5 factors that go into tool selection. 1)Material Group, 2)Insert
Radius, 3)Insert Type and Size, and 2 others that I can't remember
off-hand. There are probably about 1000 different scenarios that I
have to code for..(there are several blank table cells and it's not
setup as you might imagine, there is a lot of overlapping), and I
desperately want to avoid making a gigantic conditional statement. I'm
afraid that I really have to provide a picture of what I'm doing here,
so I will do that. Here is the link.
You only see 3 of the 5
factors on this page, and the other 2 have to do with whether this
table or one of many other tables (not pictured) will be used.

So, now that I've confused everyone. That's my table. What's a good
way to go about programming that sucker in so that people don't have to
do all the "work" involved to figure out what tools they need. They
should just be able to choose selections from 5 dropdown boxes and get
one tool back. A tool is something like "10.655.600".

Cascade Dropdown Or Conditional List
I would like to create a conditional cascade form.  based on the selection, it can display or not display an input form for the user to enter an string of text. then at the bottom of the page (or when a user submit) connect all the sections including the input field all together (it's like a story maker?)

Conditional Statement For Default Case
I'm trying to create a conditional statement for my menu that will check to see if the page is on the default case. Code:

Session Problem - Login Screen Continually Reloads After Pressing The Login Button
I am trying to get sessions to work on a log in screen to give certain
users access to certain pages/directories. The problem is that when
the login button is pushed (or the enter key pressed) the login screen
redraws, never loading the next page. I don't get any error messages.
I am using FreeBSD-5.1/Apache-2.0.46/MySQL-4.1.0.1/PHP-4.4.3.4

I have pasted the code below:

Login Lgout And Login Without Closing Session Gives Redirection Error
I am stepping through a text book that sets up different websites. The
one I am testing is user registration.

I set up the scripts and this is what I observe:

Login (verifying against a mysql db) - no problem.
Logout - no problem.

Close the browser and try again - no problem.

Login > Logout > Login WITHOUT closing browser I get:

An error occurred while loading http://login.php when it should redirect
me to http://localhost/index.php.

I read somewhere on the news group that the
header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname
($_SERVER['PHP_SELF']) . "/index.php") (in my example code) is called
once and so the error?

The logout.php destroys the $_SESSION variables, session itself and any
cookies so I thought it would be "like new" the second time around?

It appears to be linked to sessions but don't know enough to know how to
correct.

Syntax Issue With Form And Conditional Statement
Is it possible for a <form ... action="program.php"> to contain a conditional statement for the action? For example, I want to call one PHP program if variable $a="screen" and another program if variable $a="download". I have been struggling with this for some time and cannot seem to get it to work.

PHP Conditional Setting Of Radio Button Default
I'm working on an edit inventory form, and I'm pulling a field from my database that's going to be a 'Y' or 'N'.  Based upon this, I want to default the 'customizable' radio button to either checked="Y" or checked="N". Code:

Make Function Equal To String In Conditional
I can usually figure something out, but I CANNOT figure this one out: This is a classified word ad script to count the words in a text area ($wrdad) and multiply it by the rate for how many times the ad will run in the newspaper.  I know my code is messy and ameture, don't be too critical, but it works - everythign except one part. We have a 15 word minimum. I have this area commented out as //Problem Area/// in the code below.

In a nutshell, I want function wordcount($wordad) to be equal to 15 if there are fewer than 15 words in the $wordad textarea. It just seems to ignore the wordcount($wordad) == 15; in my conditional. Code:

Login Script Forcing Me To Login Twice?
I have built a login script and for some strange reason its forcing me to login twice. Not saying the user/pass is wrong first time, it moves the headers fine, it just show the old page with the login any ideas? Code:

Login Page Not Redirecting After Login
I've used this same snippet of code in other login forms without a problem (with some slight modifications from script to script) but this one seems to baffle me.

Basically it takes the login and validates the entries (validation works, error messages display if left blank), then checks the database for a match. If there's a match then it is supposed to forward the person onto the proper page using the 'header' function. Problem is it's not. Basically it's reverting back to the 'index.php' page (login page) and the display is completely blank. Here's the code for index.php: Code:

Php Login And MySQL Login
can anyone tell me the advantages of a login created with mySQL over just using php and writing to text files(if this is posible)?is mySQL safer and more secure in any way or just easier?

Conditional "implements"
Currently i'm thinking about how to solve this problem:

if (t3lib_div::int_from_ver(phpversion())<5000000) {
// php4
class tx_lib_object extends tx_lib_selfAwareness {...}
//
} else {
// php5
class tx_lib_object extends tx_lib_selfAwareness implements ArrayAccess, Iterator {...}
//
}

The question is now how to make this conditional "implements" in php?
Of cause i do not want to copy the code for both php versions and then
switch between the whole classes.

Help With Login
The problem is that the very last part of the code is not working the last if..else condition that has been set doesnt work, ie, when session remains and cookie expires...whenever there is such a condition a few notices are displayed and nothing else..

} else if (!isset($_COOKIE['user'])) {
if (session_is_registered("password")) {
echo "else if part";
}
}?>

PHP Login
I am creating a new site which will include a few pages that only registered memebers of our organization can view. Our host supports PHP and MySQL but I am unsure how to go about creating such a login area. If possible, can I asign each member a username and temp password where then can then login and change their password? I do not need a registration page because only the members I select can go ahead and use our members only area. Can anyone give me advice. Kind of new at this but I have been reading up. Have never used PHP but willing to learn.

Login
Now im trying to make a login page, so that people who have lost the cookie on there computer can retrieve it, any ideas?

This is the setcookie command I use: setcookie("CookieID", mysql_insert_id(), time()+94608000, "/"); I need the cookie to set the user specif information based on their username and password.

Login
how to login ...

<form name="form1" method="post" action="">
<input type="text" name="user">
<input type="password" name="id">
<input type="submit" name="Submit" value="Submit">
</form>

In the above form..i want to fetch data from database of mysql ..to
the field of name and id .....when
will enter to the name and id it will compare to mysql fields how to
write to this form code in mysql queries through php..........

Login
I have created this very simple way to log in to a site.If I log in as an admin (status=100) everything works fine and I'm redirected to admin.php. But if I log in as a regular user (status!=100) I'm not being redirect to admin.php. So I guess that there's something wrong with the session I set for a typical user.

I haven't found out what could be the problem, so therefore I would appreciate it if someone could take a quick look at my code. I'm sure it's a pretty easy error by me (although I'm too blind to see it myself). PHP Code:

SSL Login
Recently, my company has decided that session-based login isnt secure enough (Layoffs are coming, they probably expect lots of angry people) and have decided that encrypted login is necessary, even on internal networks.

Can someone please give me somewhere to start on implementing this? I have a pretty solid understanding of encryption in general, but the articles I have read are cryptic.

Login Box
I'm having a bit of trouble with a login box. My website has all the common stuff - news etc. and it has a login box up the top.

What I want to do is have it linked to a database and you can login, and when you login it says something like:

Welcome, *User*.

Type thing. How would I go about doing this?

LOGIN
my login allows you to login with for example 'steven' when your username is 'Steven' this throws off some things. how do i make it so when they login its an exact match also the cookies dont set if anyone wants to take a stab at that! Code:

Php Login
I have a script which use the following php code to login - code is before administration code:
<?php

include('config.php');

if(!isset($_SERVER['PHP_AUTH_USER']) or strcmp($_SERVER['PHP_AUTH_USER'],$login) or strcmp($_SERVER['PHP_AUTH_PW'],$password)) {
    header("WWW-Authenticate: Basic realm=Secured area");
    header("HTTP/1.0 401 Unauthorized");
    die("No entry. Goodbye!");
}
else {
    //
}
?>

in cofig.php I have:
$login = "admin";$password = "admin";

But when my provider changed php 4 to 5, i cannot login into administration anymore.

Last Login
I would like to show the list of last login members on my web page. How do I do it?

After Login In
I am trying to create a basic login page in PHP whitout using a database to reduce complexity at the moment ,but after I get the login successful, I have no idea on how to redirect the page to lets say a folder or page. Code:

Login
How is it possible, to have my login, so that when the username equallys staff 01 staff 02 or admin it opens a different page.

PHP Login
Im trying to make a login form (Username / Password Authentication) and for each user that has a login / password they will be redirected to a specific page..

for example if the user "Mike" log's in he will be directed to page1.  If the user "Jon" log's in he will be directed to page2.

And really the only login i know how to do is to direct all users to one location..

Login Script
i need help bad. I have been trying to make a login script for my site but it is driving me nuts! here is what i got so far:

This is tha page that is supposed to check the input from the form and set session variables:
<?PHP
if (session_is_registered(user))
{
die("You Already are logged in");
}

$fp = fopen("users" , "r");

$contents = fread($fp, filesize ("users"));

fclose($fp);

if (strstr($contents, $user)) {

if (strstr($contents, $pass)) {

session_start();
session_register(user);
header("location: Post.php");
}
else {
die("<H1>Password was not found!</h1>");
}
}
else {
die("<center><H1>That name was not found!</h1></center>");
}
?>

okay here is the posting page that is supposed to check for the session variable:

<?php

if (session_is_registered(user) == FALSE )
{
Header("Location: Poster.php");
}

echo "<form action=$PHP_SELF method=POST>Put the name of your article here:<br><input type=text name=title><br><br><br>";
echo "Type you text here:<br><textarea name=body rows=16 cols=67>";
echo "</textarea><br><br><input type=submit name=submit value=Submit></form>";

if ($submit) {

$lenght = strlen($body);

if ($title == "" || $body == "") {
die("Sorry you left a field blank");
}

$fp = fopen("$title", "w");

fwrite($fp, $body, $lenght);

fclose($fp);

$lenght = strlen($title);

$fp = fopen("articles", "w");

fwrite($fp, $Title, $lenght);

fclose($fp);
}
?>

New Problem With Login...
Alright I have a new problem...i tried to print out the error but it wont print it out. It says the warning is on line 14....I will indicate what line 14 is....let me know what you think Thanks.


body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="91%" id="AutoNumber1">
<tr>
<td width="100%">
****LINE 14 ***** <img border="0" src="http://www.mountclubsports.com/dance/Images/bckgrnd_logo.jpg" width="900" height="110"></td>
</tr>
</table>
</center>
</div>


<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="91%" id="AutoNumber2">
<tr>
<td width="100%">
<img border="0" src="http://www.mountclubsports.com/dance/Images/bckgrnd_green.JPG" width="900" height="350">
<DIV STYLE="position:absolute; top:180px; left:156px; width:655px; height:25px">
<center><FONT SIZE="+02" COLOR="000000">Admin Log In</FONT>
<br>
<FORM METHOD="POST" ACTION="login.php">
Username: <INPUT TYPE="TEXT" NAME="Username"><BR>
&nbspPassword: <INPUT TYPE="PASSWORD" NAME="Password"><BR>
<br>
<INPUT type = "submit" name = "Login" value= "Log In!">
</FORM>


<?php

$hostname = "*****";
$username = "*****";
$password = "*****";
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$URL = "*****";

// Check to see if the form has been posted
if (isset($_POST['Login']))
{
// It has, now lets check to make sure they filled in all fields
if (isset($_POST['Username']) && isset($_POST['Password']))
{
// Open a MySQL Connection & Select Database
$dbh = mysql_connect ($hostname, $username, $password) or die ("I cannot connect to the database because: " . mysql_error());
$db = mysql_select_db("*****", $dbh);
// Perform Query to see if the user exists
$CheckUser="SELECT * FROM Admin_Users WHERE Username='".$Username."' AND Password='".$Password."'";
$CheckUser_Result=mysql_query($CheckUser) or die(mysql_error());
// Check the Result
if (mysql_num_rows($CheckUser_Result)==1)
{

***LINE 63*** header("$URL") or die(mysql_error());
}else
{

$Error="Sorry your Username & Password were not found, please try again.";
}
}else
{
$Error="Please enter both your Username & Password.";
}
}
// Check to see if we need to display any error message
if (isset($Error))
{
echo "$Error<BR><BR>";
}
?>

</DIV>


</body>

ERROR: Warning: Cannot modify header information - headers already sent by (output started at /home/mountclu/public_html/dance/login.php:14) in /login.php on line 63

I have gotten this on all the scripts I have tried...what does it mean? I tried putting "the domain name" instead of the $URL and that didn't work either

Login Questions
I have 2 books 1.) MySQL/PHP Database Applications and 2.) PHP4 Bible. My problem is that in both books the only way they show how to use a login form is to use the HTTP_AUTH. Which I don't want to use, I want my script to do the login and log out Like VB does. Where or how would I go about doing this? I can enter data into MySQL, but I know i am missing some steps, such as Md5ing the Password and sessions and such. Any info would be great.

Login Sessions
I am trying to creat a simple login system using sessions, I have the form working which passes onto the following code, the if/else statement works but it is not creating sessions as I want it to so I can check on other pages to see i they have loged in or now. PHP Code:

Remote Login
I m working on a module where i want to write a script which when run should allow me to login to a perticular site, which i call remote login (dont know if its right or wrong). Can we do this in PHP? I heard something called CURL...can we do it using this?

e.g.
suppose i have www.yahoo.com
and i want to login to yahoo from my program..may be passing some username and password in a string and then I want to retrieve inner page content.
I have valid username and password of the site I want to work.


Copyright © 2005-08 www.BigResource.com, All rights reserved