Passing data between pages

  LeadingMNMs 16:29 15 Feb 05

For my university project I've got to design an online library system (well at least part of it), using CGI written in C.

I need to be able to pass the user's username between pages, rather than it having to be entered all the time. Now, I know that this can be done with hidden fields in a form, or by using cookies, but are there any other ways it can be done. If not then which way would you recommend ?

The idea of using cookies seems the easiest, but is that likely to work with people choosing to block them ?

The idea of using hidden fields strikes me as a problem because surely everything would have to go through a CGI program, rather than static pages linking directly to another static page. Presumably, the first page would have to be read, and then the new page generated with the same hidden field.

Hope that makes sense.

  Taran 17:53 15 Feb 05

I'd hate to be seen to recommend one method over another based on the very brief description of your requirements.

Having said that, have you considered user sessions ?

I love user sessions in any language - they offer so much flexibility to repeat instances of information already entered for your web programs.

Just a thought.

  LeadingMNMs 18:10 15 Feb 05

My lecturer said that sessions were quite difficult to achieve and probably passed the scope of the coursework. I did try to find out more about them to see if they were feasible but I was unable to find much information on them (searching for 'sessions' on Goggle isn't a good idea).

If you've got any links to explain them and how there achieved then I'll be happy to read up about them.

  LinuxPenguin 20:04 15 Feb 05

well ill give a brief idea of each

first of all you can use session cookies

set your cookie text to whatever you want, and it can be called back whenever you want. i use that generally with javascript and php, not c

the other thing is hidden fields

if you partition your page into frames like this

| |
| |
| |
| |
| |
| |
| |

anyway visibly think thats what your frame will look like.

the bottom frame should be set to a height of 0 though, so it wont be seen

in the bottom frame you then put a <form> with some inputs of type hidden

<input type="hidden" name="blah">

you can then use javascript to store values in it in between pages (*reaches for js reference*)

anyway and then the main page you can call with query strings "?var=val&var2=val" while storing data in between pages.

the third is session allocation, the preferred method and not that difficult tbh.

you create a file (or preferably use a db) to store the following

session id | action
and you get a list of them going

then if youre using a db its much easier as you can issue this sql statement "get action where sessid=" + sessionid

where you have taken the session Id from post data or get data otherwise you have to comb a file for it. if youre using the mysql c api, then the third is the easiest method. ill remind you that post data comes from STDIN eg cin>> or scanf() .

good luck if you want any more help, email me with the link above

  LinuxPenguin 20:06 15 Feb 05

damn that frames thing screwed up major time

in essence a big frame stacked over another frame 0px high

  LeadingMNMs 20:11 15 Feb 05

Unfortunately you lost me a bit with the Session Allocation method. If it helps at all the CGI program uses Pro*C to interact with an Oracle database, so I'd use that rather than MySQL.

  LinuxPenguin 20:57 15 Feb 05

as i understand it the oracle database uses a similar style of SQL to MySQL, your lucky to be working with such a high power database ;p

anyway you have someone access your page right

they sent a request for prog.exe you check the post data

class DBstuff SQLr;//will hold return value of sql function calls
char * postdata;

//connect to database (i dont know how you do that for oracle, look it up)

if (postdata=='){//they need an id assigning
//get the number of Ids assigned - replace SQLfunc with your SQL function
SQLr = SQLfunc('select unique id from actions');

cout<<"<form action=\"prog.exe\" method=\"POST\"><input type=\"hidden\" name=\"id\" value=\";
//this function needs replacing with the oracle equivalent too
cout<<num_rows_affected(SQlr);<<"\"><input type=\"submit\" value=\"click here to enter\">";
//connect to the database to get their stats etc.

}//if (postdata==')

if you need any more help, mail me

this is only meant to be a rough guide, im no expert on using C++ and databases, i use c++ on its own, and i use php/mysql lol. i think that ought to do it though

  LinuxPenguin 21:07 15 Feb 05

hmm that wouldve been a lot easier to make out if it hadnt messed about with the spacing

also, on that last cout statement you need to add


or the html will be broken.

now the second bit, if they have a session ID...

i dont know what you plan to do with the data, post more back about that please

  LeadingMNMs 21:23 15 Feb 05

Ok, well the system is fairly complicated. I've got to create a library system, although not everything needs to be implemented.

Basically, what I want to be able to do is allow a user to login, search for a book, reserve a book and then logout. The system may become more complicated, but this seems a simple start point. In this way the usersID needs to be carried over pages so that it doesn't need to be re-entered to reserve the book. This is the basic use though if the system grows there will be a greater need for it.

Connecting to Oracle is not a problem, using Pro*C although I'm using C rather than C++ although I can understand most of your code, its just the 'class' declaration that I don't understand.

  LinuxPenguin 21:29 15 Feb 05

classes are not unique to c++

i put the word class there to comply with ANSI ISO standard C89

to define a variable fo a user specified class you type class classname variablename;

i used it because mysql returns a class when accessed via c(/++)

ill add some more stuff relating to your specifics in a sec

  LinuxPenguin 21:36 15 Feb 05

you need a database looking like this

table users
id mediumint(8) auto_increment
username varchar(30)
password varchar(20)

table books
id mediumint(8) auto_increment //book id
name varchar(30) //name of book
signee mediumint(8) //id of person who has book

table session
id bigint(16) auto_increment //session id
uid mediumint(8) //user on that session

AFAICS that should do, next ill post some code to utilise it

This thread is now locked and can not be replied to.

How to watch Surface PC live stream | Surface PC release date, price, spec rumours: All-in-one…

1995-2015: How technology has changed the world in 20 years

Best Photoshop video tutorials: 8 video tutorial websites for Photoshop

Apple's event invitations decoded: A look back at 16 of Apple's most cryptic invites | Clues in…