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




How To Persist Objects From Page To Page


I just started getting into PHP5. I'm thrilled that it has moved more toward OOP. However, conceptually, i don't understand how, when you instantiate a class, that instance can persist from web page to web page. How does the web application know that a new instance has been created and to keep the object alive until te end of the user session or when explicitly made null? Do session variables come into play?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Passing Objects Form One Page To Another
Is it possible to transfer objects derived from a class form one page to
another?

I made 2 testscripts:

person.php
-------------------------------------
<?php

class person {

private $_name;

public function setName($name) {

$this->_name = $name;

}

public function getName() {

return $this->_name;

}

}

$p = new person();

$p->setName("Jim");

$safep = urlencode(serialize($p));

header("Location:person2.php?data=".$safep);

exit;

?>

person2.php
---------------------------------
<?php

class person {

private $_name;

public function setName($name) {

$this->_name = $name;

}

public function getName() {

return $this->_name;

}

}

$x = unserialize(urldecode($_GET['data']));

echo $x->getName();

?>

But this does not work for me....

Page Expired After Going Back From Del. Pageto Form Page Where Comment Is Submitted..
i've made a submit comment form with php and mysql, the form has an action to itself with a hidden var like this: input type=hidden action=add

When i delete a comment on the page i go to a page called delete.php3 and there is a link with a javaline which goes -1 back in my history..

When ive added a comment, the comments page contains action=add and when i delete a comment, i want to click on the link to go back to the comment page, but then, it doesnt work and it says:

Page has expired.

I wondered how to deal with this kind of problems........

Page Has Expired Message In Between The Php Page When I Click Back In Explorer Menu
I have a php script page, which is basically quiz. Visitors (after login in
with their email address) are supposed to answer each question, and when
they click the button at the bottom, the next page will show which problems
they got right or wrong.

Now my visitors, after seeing some problems they got wrong, click Back
button at the Explorer menu, and if they do, they get the below message:
=========================
Warning: Page has Expired The page you requested was created using
information you submitted in a form. This page is no longer available. As a
security precaution, Internet Explorer does not automatically resubmit your
information for you.

To resubmit your information and view this Web page, click the Refresh
button.
========================
Below are the script that I am using. This scripts are after initial login
page, which asks for visitor's email address. I have authorized visitors
already in my MySQL table, and only the visitors whose email address is in
my MySQL table are allowed to login......

Session Var Is Setting ONLY AFTER I Reload Page, Form Var Displays First Page Load
Page1 has a form that calls Page2. The beginning of Page2:
<? php session_start();
$s=$_POST['sSelected'];
session_register("s"); ?>

in the middle of Page2 I have a form varaible:
<?php echo $_POST['stateSelected']; ?>
<?php echo $_SESSION['s']; ?>

The form var displays the first time the page loads. The session var
displays only after reloading the page2.

Transfer Session_id() Between A Secure Page To An Unsecure Page - SSL
I am having problems understanding how to transfer session_id() between a
secure page to an unsecure page. When I move from the secure page to the unsecure page the session_id changes.

Here is the script:

Secure page:
<?php
session_name('thename');
session_start();
echo session_id();
..
..

[refreshing A Php Page Resulting Page Cannot Be Found Error]
i have a php page that will refresh by itself by using a meta tag and meta timer. however, without a clear indication, my page will just go "Page cannot be found". bizzarre but when i press refresh, the page can be found!. i am not sure whether this is an IE problem or issit my script problem. i don't encounter this problem if it's just a plain file.html.

perhaps is my session string? i am passing my session thru the URL and i constantly refreshing it. is that the problem? my url looks like this: domain.com/myfile.php?authorize=mike&token=f5c0f7edd785a6a9448c50249bad18ed

Page Control - Next/previous Or Select Page Number
I'm looking for php script examples that will help me control page layout. Using a table with 12,000 records, would like to be able to display only 5 records per page with page controls at the bottom of the page. The bottom edge would have next/previous or an optional insert desired page number.

Launch New Page And Refresh Exisiting Page
I know about not being able to change header info after output to the browser but what are the workarounds if any?

I have a basic form where a user logs in - the details they submit are verified in supportlogin.php and then if successful I launch another browser window with Javascript but the window in that they logged in at remains on supportlogin.php and is blank... How can I launch the new window and send the first window back to the login page? PHP Code:

If Value =1 Direct To Page Otherwise Show Data On Page
In the member account area there is a button saying (list) when the member clicks this they are redirected to add.php here i am wanting to check if a members account is limited, if it is direct them to a page saying you must pay your bill. if its not display the info on the page.

in the database there is a field called limited which is tiny in if its not limited the value of the field would be 0 if it is limited the value would be 1.

Keeping Lots Of Values From Page To Page
I am doing an online questionnaire which is going to have 5 questions per page and upto 100 questions.

If somebody hasn't completed the entire questionaire I do not want their data stored in the DB. I was wondering if anybody can tell me the best way to either use sessions to store the data and do a final update at the end, or use a temporary db table to hold the data.

Page Rotator Without Leaving The Actual Page...
I'm trying to write a homepage page rotator. The home page is default.php and I want 3 pages to rotate in that file without leaving default.php or directing to the actual pages I'm rotating... Basically, a content rotator but I want the content to be individual pages.

Here is what I have but it seems I have a bug somewhere:

<?
$pages = array(
include(page1.php),
include(page2.php),
include(page3.php)
);

shuffle($pages);
$i=0;
$number=2; while(list(, $page) = each($pages)) {
if ($i>=$number) { break; }
echo "$page";
echo '<br>'
$i++;
}
?>

For some reason the pages aren't coming up right in the default.php page.

Passing A Parameter From An HTML Page To A PHP Page
I want to pass a language value (EN/FR/DE etc.) from an Index HTML page to a PHP page with a language code in the call, so that the PHP page can select texts in that language. I would like to to it from an unordered list item if possible by extending the link ... <li><a href="scripts/pricelist.php???>Pricelist[/url]</li>

Login Page Produces Blank Page
What I get when I enter username/password and hit submit is a blank page and the URL never changes. In other words, the login page is 'index.php' and when submitted it should redirect to 'admin.php'. Instead the url/address stays at 'index.php' and the page turns completely blank.

In the previous thread, the problem turned out to be some missing indicator to the md5 encrypted password. Well, in this version, that's there! In fact, I used the ending scripts for that project in creating this project. So, why it won't work is a real mystery. Code:

Displaying Parts Of A Page While The Page Is Not Complete Yet
A script I'm writing outputs a HTML table with many rows. Each row is the result of a query which takes about one minute to perform. When I run the script in a browser, the page takes several minutes to load and then displays the entire table. Is it possible (using PHP) to display the table as it gets constructed, one row at a time?

PHP Sessions Not Carrying From Page To Page
I have a website that allows a user to sign up. Then they can login. Now when they login it creates a session in the C:PHPsessiondata but once it loads a new page.. The session doesn't carry over to it. IT just reloads the login page.

Using PHP To Load Another Page Or Html Page
Ive got a PHP script, which if it ends correctly, i want load another
PHP file or an HTML page automatically, ie without user intervention.
The new page shoud replace the current page on the browser. Is there a
PHP command or function which does this?

HTML Web Page Hyperlink To Php Web Page
I am still having a problem parsing a html page with php. Code in my HTML
is
<? php
echo '<a href="index.php">Home</a><br />
<a href="login.php">Login</a><br />
'
?>
However the link is to the Login page is:
file:///C:/Program%20Files/Apache%20Group/Apache2/htdocs/TeeJayUu/login.php

I am using PHP 5.0.2, Apache 2.0.52, MySQL 4.0.21, and Windows XP SP2. All
pages are in the htdocs folder and the following instructions have been
followed:
- Copy php5apache2.dll to Apache's module dir and rename it to mod_php5.so;
- Copy php5ts.dll to Apache's bin dir.
Finally, add the following line to your httpd.conf file:
LoadModule php5_module modules/mod_php5.so
Apache has been stopped and restarted.
Help - I am lost for what else to do. I want to keep this local until I
have got it working.

Log In Page That Goes Back To REFERRING Page
I am using the following code to initialise a session, depending on
whether-or-not the users' log in attempt has been successful.

if ($session_ok == "TRUE") {
//open the session
session_start();
//assign user details to session
$_SESSION[txt_user] = $user_id;
$_SESSION[user_pass] = $user_pass;
$_SESSION[ses_state] = "TRUE";
header("Location: ../index.php");
}

as you can see the script then refers back to my index.php page, after the
session is ok'd.

What I would like to do is change this so that is goes back to the referring
page, instead of the index.php page, which requires the user to then
navigate to their previous page again.

I have attempted to use $HTTP_REFERER, although for me (on IE6) for some
reason their is no value in the variable!

Php Page Will Not Process Link To Different Page
I have just installed RH Linux ES 3.0 (basic) kernel 2.4.21-9.EL, i686,
Apache 2.0.X, and php 4.2.X. I have made no changes to the php.ini.

I am trying to use the following page (code listed here) to click on
link, and display 1 of three pages. The code does not seem to work, it
only shows the "else" condition of the php code, which is page:
"stuff.php". What do I need to do to my apache/php config to get this
to work? Of course I copied this code from a php site tutorial somewhere.

Page code below:
<?
if ($link == page2){
$page="files/page2.html";
}
elseif($link == page3){
$page="files/page3.html";
}
else{
$page="files/stuff.php";
}
?>
<html>
<head>
<title> index.php </title>
</head>
<body bgcolor="#999999">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="3"><h1>The Template (index.html)</h1></td>
</tr>
<tr>
<td align="center" valign="top"><a href="index.php?link=index">
Page 1 </a></td>
<td align="center" valign="top"><a href="index.php?link=page2">
Page 2 </a></td>
<td align="center" valign="top"><a href="index.php?link=page3">
Page 3 </a></td>
</tr>
</table>
<? include($page); ?>
</body>
</html>

I Want To Create Something Like AMAZON: Those Who Liked Page A Also Liked Page B
I want to create something like AMAZON: those who liked page A also liked
page B (I am going to apply the concept to a few different selections, but
to keep it simple I will talk about page popularity here - like AMAZON talks
about purchase patterns: those who bought A also bought B, C and D).

In my mysql table, I record everytime a visitor looks at a particular page
(I keep track of people with sessions and they can only look at a page
once).

Next, what I want to do is to show a small list of similar likes. That is,
people who had an interest in page A also had an interest in page B.

The structure of my table is:
id
timestamp
session_id
page_name

There is a unique index on the combination of session_id and page_name.

To work out similar likes for page X, my idea was to make an array of all
the session ids that looked at page X and then select the top 10 of pages
that these folk looked at.

My question is, should I do this in PHP with a bunch of arrays, adding total
counts while looping through an array or shall I use SQL statements. I
could even make a really long string of WHERE session_id = A or session_id =
B, etc..... Although this seems really inefficient.

Another question I have is whether you think this will be a self-fulfilling
prophecy (e.g. if you say that page Y is also popular then people will check
it out and therefore make it more popular).

Calling A Function Or Page To Another Page
I have two pages that are part of a user registration script. For simplicity's sake I will call one registration.php and the other validate.php What I basically would like to do is instead of going from registration.php to validate.php, I would like to call the script from validate.php and use it without leaving registration.php

The following code is a portion of the validate.php code. Here are my questions regarding this page. 1). If I want to call it or include it in registration.php should I make it a function? If so, how would I do that. 2) Can I call the validate page or function through an a href statement? (see registration.php code) PHP Code:

I Want The Page To Go Back To My Login Page.
I want to logoff my application and I have set up a link to do this. I
got it to destroy my session, but I can't get the page to go to the top
of the browser and do a page refresh. Here is the code I am using.

First there is the link I am using.

printf("<a href="%s?logoff=%s">%s</a><br>", $_SERVER['PHP_SELF'],"logoff", "LOGOFF");

Here is piece I use right at the top of the script to destroy the
session and try to refresh the page.

if (isset($_REQUEST['logoff'])){
session_destroy();
$_SERVER['PHP_SELF'];
}

What do I have to do to get the refresh to work?

How Do I Redirect A User From A Page To A Different Page ?
How do i redirect a user from a page to a different page ? i don't want variables to follow behind the url of the pageg being redirected to.

If Page = 'about' Show The About.html Page?
I wanted to do some kind of PHP script so that if the current page the viewer is trying to view is called index.php?page=about then it will use the php script to embed with an i-frame the about.html file into a cell in my web page's table. Basically, so that the whole page stays the same other than one cell of the table which is dynamic depending on the status of the index.php?page=whatever. Code:

Copy A Variable From One Page To Another Page?
How do I copy variable from one page to another page in PHP? For example: I want to put a $var in page A into page B.

Login Page - Previous Page
I have a login page, and instead of going to the index.php page all the time after a successful login, I want the user to be directed to the last page they where at, as long as it is a page on the website.

Sessions Expiring From Page To Page
I just installed a site on a client's server.  I'm using a session based login, and have the session_start() at the top of the pages I need.  However, when I first log in, the session variables I register are all there, but when I click on any page, they are gone. Does anyone have a clue as to what might be set that's cuasing this?

Login Page/members Page
I am having trouble getting my login page and mebers page to work. I believe it has something to do with the way the cookies are set or something because the if(isset($_COOKIE['cookiename'])) area of the code seems to be what is not functioning correctly. Code:

Question About Using "global" On One Page Then Using The Variable On Another Page
I am taking over an exisitng app. I have the following function on one
page:

function check($v) {
global $user;
return $user->validate($v[1], $v[0]);
}

And it reference $user on the next page. Register_globals are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_register('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

Certain Custom "Page Not Found" Page Problem
I have an ISAPI instalation of PHP over IIS5 server
on Windows 2000. Everything works fine but as I am
under website development I would like to keep
PHP error messages turned on - for my development
purpose. Unfortunately, that concludes that in case
somebody types a fake address like: http://www.myurl/xyz.php
the server replies with something like that:

Warning: Unknown(C:Inetpub
ootxyz.php): failed to open stream:
No such file or directory in Unknown on line 0

Warning: (null)(): Failed opening 'C:Inetpub
ootxyz.php' for inclusion
(include_path='C:InetpubPhpIncl') in Unknown on line 0

This is not the kind a message I would like to be presented to anybody.
In this case I would rather like to see a custom "Page not found" message
instead.

Any ideas how can I configure PHP to keep displaying regular errors
and warnings in all situations but in case of "page not found" - to display
custom error message instead ?

Index.htm Going To Login Page And Sending Back To Index Page
1: A visitors visits a.html page. decides to login and post comment. goes to login page and logs in then I want to send him back to a.html page how do I do that? Here is my login page and login.php page.

2: Same as above but I want to send them back after some time... while I make them view the error, why they have not been able to login. Code:

Multi User/ Multi Page Redirect To Particular Clients Page
I need all of my clients to be able to go to ONE login page. based on their user ID number and password be able to login to their particular page, I do not want them seeing any of my other clients information. seems easy... now why cant i figure it out.

I want the back end of it in mySQL, with a way for: admin to easily update the information located in there...ie: go to client 1 add new invoice information, new expiration date, etc. clients to easily update their billing information, etc from their personal page, is a must also. I just want to know if going with PHP is the best bet, or if there is another way..

Cookies From Page To Page
I'm using PHP to create a cookie on my index page, that has an HTML inside the and wanting to carry the variable over to the frames page so I can say Hello to the user. The PHP script is: Code:

Making A .php Page A .cgi Page
I have somebody or some people who are abusing a Perl based .cgi script.
I have written a PHP page which reports this abuse as per
$_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
with this .php script. Problem is these people are coming in with some
web crawler or something like that (i.e. wget
http://myserver.com/thescript.cgi). Now if I replace thescript.cgi with
thescript.php they will not hit it. And if I replace thescript.cgi with
my PHP page, because it's not a Perl script yet ends in .cgi Apache is
saying "Exec format error: exec of '/path/to/script/thescript.cgi'
failed". Is there a way I can configure Apache or otherwise have
thescript.cgi execute PHP code (without crippling other .cgi Perl
scripts on my site)?

Displaying Your Page Url On The Page
I'd like to find the function/method/http_header (not sure how to call this) that will return the full path of a document as.

http://www.domain.com/directory/filename.php

This will display the full url of the document it is written on as I want to use it to dynamically generate links to bobby/w3c to check some pages against html validator and accessibility.

This link will be in an include a the bottom of all the pages on my site (~20 pages)

My SESSION Array Does Not PERSIST?
I am trying to store data in a $_SESSION variable (an array), but it reverts to
empty every time my page is refreshed (due to a submit button click).

I read the answer to the post "$_SESSION comes empty on next page" dated
2/4, whaich seems to be my problem. But the suggestions do not help me at all
<see 1 & 2 below>

1-have you set session.save_path ?
2-if you are using virtualhosts put this at the top of your .php file:
session_set_cookie_params(3200, '/', $_SERVER['HTTP_HOST']);

I have tested the array $_SESSION['list_array'] with both empty and !isset
and it returns true in both cases after a page refresh or when moving to
another page all together.

Is there something that I am missing...here is some of my code:

<?php

if (!isset($_POST['build_it'])) // if this is not the final submit, but
the first form display or redisplay
{
if (isset($_POST['add']))// this is just the posting to the array
{
if (empty($_SESSION['list_array']))
{
$_SESSION['list_array'] = array(1 => $_POST['list_member']);
print "created and added...<br />";
}
else
{
$_SESSION['list_array'][] = $_POST['list_member'];
print "added...<br />";
}
print_r ($_SESSION['list_array']);
}

Why Does $_GET Query String Persist?
If I go to an URL via a link that contains a $_GET query, then how can I clear the $_GET from the address bar when following later links? e.g.

I go to: index.php?action=edit_splash&view=all

... then on that page I click on a form button that self submits via $_POST - but the old $_GET query remains in the address bar.

Adding Php Code Or To Include A Page With Php Code Into A .tpl Page
how would i do this, i am intergrating a phpbb forum system into my site!

Session Variables Do Not Persist Into Included Files
In my index.php file I set a session variable

$_SESSION['product'] = "foo";

and then in my html part of index.php I include a file menu.php using require_once() which I use to build the menu tree. However, the session variable is not available to me inside that include file. It is available to me inside index.php because if I echo it I can see it. If I go to page2.php it is also there. Just not in the include file.

Using Database Objects Within Other Objects. Inefficient?
I've defined a Database class with methods to call mysql_query(), etc. The connect() method makes a persistent connection. I've also defined a Member class to hold functions and data for users. PHP Code:

Php Can Go Anywhere In The Page?
So i query the database and output some stuff, just wondering if it matters at all if i put the main query say above the <head> tag and then output bits of it later throughout the page, the main reason was so i could echo the varible title name. example:

Get Page Name
I am updating a site that used to be in pure HTML.

On the original site each of the 5 or so sections had links on the
front page. When you enter a section the image for the link on the nav
changes to indicate which section you are in (head to
www.yorkshirelaser.co.uk to see what I mean).

I need to replicate this on the new PHP system but am using an include
file for the navigation, so I am unable to hardcode the relevent image
on the navigation. I don't really want to post things to the query
string so wondered if anyone has a solution for figuring out which page
I am on and getting the nav to choose the relevent image for the
current section.

This must be a typical issue in PHP web development so can anyone give
me the typical way of solving this?

Only way I can think of doing this is to set a variable in each page
just before I include the nav.php file, then use this to figure out
which section the user is in - but is there a better way?

PHP And SSI On The Same Page?
Can I have PHP and SSI output on the same page? If so, what do I need to add to my .htaccess file? I've tried various combinations, but so far I've managed to get only one or the other on my page.

New Page?
on a "demo" that im working on with PHP i have somewhere where people can write. How do i make it so only 40 things show up? and how would i make the rest appear on a new page?

Getting The Name Of A Page
Anyone got any idea how to get the name of the page the phpscript is in... for example

rubbishpage.php contains the script <? echo $name_of_page; ?>

and that echos out "rubbishpage.php", so how would i set the variable $name_of_page to be the name of the page "rubbishpage.php".

Log In Page
trying to create a simple login page using php and a post form.

The following requirement holds,
1. there should NOT be any DB.
2. One user and one password is enough (yeah, said it was a simple
one...)

Tried with a function check_user() in a lib php-file, and a post form
in the login page. Code as follow:

<?php

function check_user(){
global $userfield, $pwdfield;

if( strcmp($_POST[$userfield],"user") == 0 ) {

if( strcmp($_POST[$pwdfield],"pwd") == 0 ) {
// Correct user
echo("correctdir/album.htm");
}
else {
// Wrong pwd
echo("../somdir/default.htm");
}
else {
// wrong user
echo("../otherdir/default.htm");
}
}

}
?>

and the login page for is:
<?PHP
require('../somelib/login_lib.php');
?>

....
<form name="form1" method="post" action="<?php check_user();?>">
<input type="text" name="userfield" >
<input type="password" name="pwdfield" >
<input type="submit" name="Log in" value="Log in">
</form>

Log-In Page
Just wanted to know if anyone here could direct me to a site that has something on creating a log-in page. I've made one ( http://ab.abc.com ), but the problem is (I realized), that when you log in and go to the other pages in the site, it's in your cache so you can easily get into the restricted area.

Php Page
lets say i have a form script but I want to just pull the form script into a table on the page how would i do that?

Page
I have a php page that i want to limit the number of items shown on it, i have used a code to generate a previous and next button but for some reson it wont work. Please could someone look at the code bellow and tell me whats wrong and what i need to do to make it work. Code:


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