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




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..




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Using Require/include In Sessions
I have an html frameset which has a php file as one of the frame src's. I then use a switch statement to include()/require() a different php file for the actual content of the frame. Code:

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?


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.

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.

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:

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:

Include Or Virtual Include: Neither Work For Subfolders
my includes files are all in my /ssi directory. I have many subfolders that call those includes files. Let's say I have a file like this:

/news/world/asia/thailand/index.php

In order to (relatively) call a file in the /ssi directory I have to use the following code:

<?php
include ("../../../../ssi/html-lang.htm");
?>

This is ridiculous. Everytime I make a new subfolder I don't want to have to add "../" to it. I heard about "virtual" includes but I'm not sure the syntax I'm using is correct (all I do is put 'virtual' after 'include'). Is there something I'm missing? Do I have to change the .htacess file? Help me please I'm going crazy. I don't want to resort to absolute referencing...

Creating User Sessions W/out Using Sessions
I'm working on a user management system where I can use the benefits of PHP sessions w/out messing with them. Basically, my idea is to have an entry created into a "sessions table" when the user logs in. The table contains such info as the user's id number and the date/time they logged in. When the user logs out, the entry is deleted. In each page/script, it checks to see if the user is logged in by checking the sessions table for an entry w/their IP address and the date, to make sure it is fairly current (unless anyone can think of a better way to check).

Now my delema....obviously, I don't want people that don't properly log out to have a session that could last weeks (depending on when they visit again). I am thinking a script that cleans up entries that are old would do the trick, but obviously I want this script to run say, at least once an hour. Obviously, I am not going to be able to sit at my computer and run this script every hour of every day. I was thinking of using the script and doing a cron job, but I think my host only allows one cron job per day...and only at night. Any thoughts??

Error Says Can't See Include File, Yet Executes Some Code On Include File
I am using an include_once() command to include a file that sits a
level above the file view.php. when the code is run, I have an error
as follows:

Warning: include_once(../common.php) [function.include-once]: failed
to open stream: No such file or directory in C:Program Files..
view.php on line 2

Warning: include_once() [function.include]: Failed opening '../
common.php' for inclusion (include_path='.;C:Program Filesxamppphp
pear') in C:Program Files...view.php on line 2

The include command is simply: include_once(../common.php) - the '../'
before the 'common.php' to indicate a level above the current file
level. Is this right? I could not find a resource to confirm this.

The strange thing is that while the error seems to imply that the
calling file, view.php cannot 'see' the common.php file, other
functions called from the 'common.php' file executes correctly and on
the same calling file/page (view.php).

Appears to the a double take - quite confusing -

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.

From SSI Include To PHP3 Include
Im trying to convert my pages to php and have a problem, how do I change from SSI include (.shtml) to PHP include (.php3) so that I still can have the last line in my script,
(?start=11&end=15 after the .php3)

I have tried this: <?php include ("ssi-top10-15.shtml?start=11&end=15") ?>

and it didnt work, I used to have it like this:

<!--#include virtual="ssi-top15-25.shtml?start=16&end=30" -->

This works, but it leaves out the scipt part: <?php include ("ssi-top10-15.shtml") ?>

Can't Include 'http...foo.php', But Can Include 'http...foo.txt'
This seems weird, but when I use the following code,

include 'http://www.foo.com/includes.php'

includedfunction();

I am told that it is a call to an undefined function, but
'includedfunction' is on the server.

the following includes work fine, and the run the called function with
no trouble:

include 'http://www.foo.com/includes.phtml'
include 'http://www.foo.com/includes.txt'

all three include.php,.phtml & .txt are on the server and are exactly
identical. I am running php version 4.1.1.

Php Include
Hello, i am trying to use the php include command in source code to insert external page when a main page loads, but get the following errors.. can you help?

Php Include
I haven't really understood how to do what I want with PHP Includes. I have read the include section of the PHP manual but still don't understand. I've done one thing with PHP Includes but it's not what I want to do. It was just an example:

(HTML)
<html>
<body>
<form method=get action="condition.php">
What file do you wish to include?
<select name="Choice">
<option value="1">File One</option>
<option value="2">File Two</option>
</select>
<br>
<br>
<input type=Submit>
</form>
</body>
</html>

(PHP)
<html>
<body>
<?php
if ($_GET['Choice']<>"")
{
include ("file".$_GET['Choice'].".txt");
}
?>
<br>
Here is some text.
</body>
</html>

^ That's if you were curious in what example I did.

What I want to do is include the layout. The sidebar headers and contents, ect. It's basically like if I were to use an inline frame for a table. The content is on one page and I don't have to update everything. Every page would use the inline frame for the table so it's always up to date and everything. But that's not what I want. I don't really like inline frames and not all browsers support them. Your help will be greatly appreciated. Thanks for your time.

PHP Include()
I have two servers (say A and B) and I wish to include a PHP script on server A in a script on server B.

I have a test variable in a.php (on Server A) as ..

Php Include
how much serverstrain does php include take? does it take alot? if you have a lot of if else commands does that take the page longer to load? thanks alot.

Include();
I have searched the forum and could not find what I"m looking for. Okay, here is my situation:

I have a website which contains my layout as index.php. I want to seperate my content page into an include file, I can do that, just fine.

But, what I want to do, is have my hyperlinks INCLUDE the file when they click on it. For example

I have the links: Home - Contact - Resources - Services

By default, I have included the Home page

<?php include("date.php"); ?>

So it displays the content.

What I want to do is for my index.php include the other files whenever the user clicks on them.

So if they click on Resources, it will include("resources.php");

Include()
<?
if(!include ("http://forums.devshed.com/newthread.php?s=&action=newthread&forumid=5")){
echo "oops";
}
?>
why won't this work, I cant see the content of the page ....

I want to include a page on a different server and display contents.

Is It Possible To Have... <? Include ?> In <? Include ?>
Well, I'm setting up a script to make it suitable with my site. So, I'm wondering if I can use a sub <?include?> ?

Well, it's like

file1.php
<? include('file2.php') ?>

file2.php
<? include('file3.php') ?>
<? include('file4.php') ?>

Can I do this?

Help With Include Please
I have this code:

<?
required("style.php");
?>

and it wors fine, but when I click view source code in browser, the style properties are shown. Is there anyway to hide them.

Need Some Help In Include....
<?php include ("$id.htm");?>
i use this thing in my page to put other pages in it.. i want to make it like that if some one types a worng page $id he is moved to a 404 page.

Include And Log In
I have a question regarding include files. I'm currently wanting to secure
all of the pages within a directory by having a login script that queries a
MySQL DB, and writes a session variable confirming the user is successfully
logged in.

Now, I've done this many times before, however I'm getting kind of sick of
putting the include file to check the session variable on EVERY page within
a directory. This is especially irritating if I for whatever reason want to
unsecure a directory, or change the structure of the login system - it
forces me to go into each file of the admin area and remove the call to the
file.

My question is: Is there a way to have PHP force an include file per
directory instead of just file? Maybe have a global file inside the
directory that will cascade the include to every page below? Or am I simply
forced to manually include the file on each page?

Include
How can I include another php file into a php file. In HTML you use <?php
include test.php?>. But I want to include test.php somewhere in my php
script. How can I make that work?

Include()
I am running win2k, IIS 5, with php 4.2.2. When I use the php command include on a perl file all it does is out put its content instead of executing the file. Am I doing something wrong here?

URL Include !!!
I just started with php a few hours ago. I'm trying to include a file into the index page based on the url. It includes "home.php" into the content area of the page when http://mydomain.com/ is entered as it should.

However when I try to include another file with the name "test.php" via the url http://mydomain.com/index.php?page=test in includes "home.php" instead. I stole this script from a friends server where it worked fine. Is there something wrong with the script or do I need to change something in my server config?

I'm clueless as to what words to use when searching for a script of this fuction. Is there a resource where I can find something simular? PHP Code:

Include()
I'm forever having include() problems and am sure there is an easy way around this.
Say I have an include directory in the webroot /includes. And that one of the files in the includes directory includes another file in the same directory.

The page that then uses these files is then located from the webroot /level1/level2.
When the file in the includes directory tries to include the other one, it is looking in /level1/level2 and obviously can't find it.

Include
How can I include a file relative to the top level directory from any other
directory ?
I really hate to use absolut url or put all my files in one directory.

eg : include("<symbol for top>/somefile.php"); ?

Outside Include() Possible?
I know that its easy to include a file in a normal PHP file. PHP Code:

Include
I need a .txt file to become part of a php file. Not just as txt, but as php.


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