Forum Moderators: coopster

Message Too Old, No Replies

dynamically replace "default" line of code with "member id" w/login?

         

scattdaddy21

8:36 pm on Jul 19, 2004 (gmt 0)

10+ Year Member



wow. i'm not even sure what to say in the title of this post to communicate what i'm looking for. i've searched the forums and googled and when i find examples of code i'm not quite able to understand if the examples i find will work well for me so i thought it best to just ask - so thanks in advance for the help.

basically, i'm building a new simple member-based site and i'd like to be able to create one set of pages that would function as templates i guess.

i'm fine with basic html and a little basic css and the like, but i haven't had any experience making anything dynamic, so here goes...

i want to know how to use some sort of dynamic code to display a member's name on one line of a template page, replacing that name from the default name, and then to also replace a "defaultmemberid" in a <a href>etc.</a> string with a "specificmemberid" in that same string on that same page. that's it really. i know its got to be simple - but i haven't figured it out yet.

and it may sound crazy - but for our purposes, in what we're looking for - i don't even want a real login complete with password and username to trigger those actions.

i only want a to have a list of member organizations on one page of the site that only requires a simple click to generate the above actions of replacing defaults with member-organizations specifics. i don't need the password protection for this area of the site. Users would simply click on their desired organization to trigger the template page, so i would code that single link to trigger the desired replacing actions mentioned above.

i don't know if that should be done with a few lines of code and links to php scripts here and there, or should that single click on member organizations query a simple database or what? (i really have no idea what i'm talking about).

i post here in php land because i've looked at a few php scripts and read that php is growing incredibly in popularity, my host provides it, and i've just starting reading a book about php and mysql databases by kevin yank that i'll use in the future. other than that, i don't even know if php is the thing to use for this situation, but i would like to use it because i will use php in the near future for some database - related activities - once i learn how.

but i would like to get this replace feature done before learning the database stuff for time contraints on the launch date for the site.

i would love any help that you can give - example script locations, help for my vocabulary when searching for help on this topic - anything and everything - i want to learn so i can do all this stuff myself.

thanks a lot!

matt

Philosopher

8:54 pm on Jul 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, if you only need to replace a name and an id, then it would be easy enough to simply pass those two fields via query strings in the URL such as

[domain.com...]

If you are needing to replace more than a simple name and an id, then you would want to setup a simple db. You would then use the unique member id to query the db and pull the information you need to output on your template page.

In that case, you would use a url like

[domain.com...]

Then have a query like

Select * FROM table_name where memberid = $memid

Then output the contents of the query to your template page.

scattdaddy21

9:59 pm on Jul 19, 2004 (gmt 0)

10+ Year Member



hi philosopher -

thanks for fast reply! the first option that you mentioned is really all i need at this point. it seems like i could take the first option now, and then later simply add a table to this first option-ed template page and then set up a database to filter some info into that table. cool. i hope to learn some database stuff soon.

but to make the first option work now, do i need to learn how to write a little php script to perform the actions of replacing the name and id?

as i understand it, you mean the simplest way for me to do it would be to make a link from each organization's name on my organizational listing page to the corresponding:

[domain.com...]

just simply hardcoding that form link to each organization's name - correct? then, when someone clicks on that link, the corresponding specifics will be passed through.

this is where i'm not sure what's next.

you mentioned passing those two fields via query strings in the URL above - but how do i then get that to actually execute the replace function? (this is basic i know - but i haven't got it yet).

do i then insert a link to a php script on each template page that will replace those two strings when someone clicks on that url above to each organization's page? do i need to learn how to make my own script or is there a simple search and replace php script that i could copy and paste into each page that would execute that replace function?

or i am totally wrong and confused on this step of what is actually required to make that work?

thanks again,
matt

scattdaddy21

11:54 pm on Jul 19, 2004 (gmt 0)

10+ Year Member



hi again-

i've been reading and learning a bit more and i'm thinking that what i described above won't actually do the job. i think i simplified it a bit too much.

upon a user entering my site, and clicking on their desired organization's name, they would not simply be taken to a singular page that needed to have the php replace membername and memberberid function, but instead they would be taken to a page that has a search box - with the search essential to our site. the search engine we are using is a simple site search that spiders internally by just following links and generates results - all using a php script. results are then uploaded and the resulting pages for the end user appear in html format.

this is where i want the php replace for a membername heading and memberid in a url string to come into play - replacing the defaults in these search results pages and all other pages after entering the organization's area. each of the pages on the site would in effect be considered a separate template i guess - with the need for the site search to spider them and index them with the php replace function operating on each page.

i am trying to avoid building the exact same pages with the exact same search results over and over again for each organization or member of the site. that's what i'd have to do with simple html. i know its probably not that hard with php, but i'm stuck so far.

using php, i know i could just build one set of pages, spidered and indexed one time, and then with the 'sort-of login" feature as well as the string replace feature, everything would be simplified and all the site activity would be passed through these templates with the php replace working on each one to identify the organization accurately.

when it comes down to it, it seems like what i would need would be all the functions of a login - (in terms of carrying that membername and memberid throughout each and every page after clicking on the desired organization) - but without requiring visitors to actually enter in a login name and password to access the organization's portion of the site - just using a single link instead that carries those membername and memberid values with it to then replace in each instance that those values come up on all other pages. (i don't want users to have to know a username and password for a login- and i don't have any security or privacy issues).

i've been looking through the scripts at hotscripts.com and i've seen lots of things about content menagement and user validation, etc. - i'm sure something over there is what i need - my problem is that i don't really know the specific terms to describe what i need - i can only describe it in my own words. thus, i've found it impossible to actually find help on this so far.

if you could, please give me a few more pointers on what things to look for as a try to find my way through the php scripting world based on what i've described here in my own words. i'm learning the technical terms slowly, but its hard when i don't really know where to begin.

thanks again,
matt

scattdaddy21

12:33 am on Jul 20, 2004 (gmt 0)

10+ Year Member



i found this thing called smarty - a php template engine - is this what i need or is it too complicated for me at this point? does it do what i'm looking for. i know next to nothing.

[smarty.php.net ]

thanks for your help,
matt

Philosopher

3:59 pm on Jul 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok...let me get this straight. Your search function spiders the site and generates a db of somekind that is accessed by users. The result of the query on this db is then output by your search program as html....correct?

If this is correct, then a change would need to be made to your search script as it will need to output the proper membername and member id dynamically along with the search results.

This could be done by passing the variables from the link as I recommended earlier to the search script and incorporating them into the output.

scattdaddy21

9:44 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



yeah - the search program that i'm using allows me to choose either php, asp, or cgi to build my search. so far, i've been using php. the program is on my desktop - then it spiders the site and generates several files such as desriptions, wordmap, pagetext, dictionary, etc. - all with the extension ".zdat" - i'm assuming that's just their software makers extension for their own specific form of little database files - i guess.

then, i simply upload those files with .zdat extensions into the desired folder of my site - (no mysql database stuff or anyting), along with the php search script itself that makes it all happen along with a small settings php file for the search.

the user performs a search on a simple web-based form on my html pages, and that form has a "get" action mydomain/search.php - thus the zdat files are queried and then the results page is generated using an html template page. the user sees and gets only html pages throughout - no actual php extensions on pages at this point.

so basically - what you said in two lines is correct.
i would want the variables to be passed through the search script, and appended to both the template results page, as well as the actual pages on the site that have been spidered previously - the pages that the the user is actually searching for and clicks on after performing their search.

now - what would be my next step in figuring this out? i've got the basic idea for what you are telling me to do with passing the two variable fields through the script and all - but i have no clue how to do set that up.

i opened up the search script with editplus and it was pretty easy to read through as editplus displays colors and breaks everything up nicely.

i just don't know what to change in that script to get started. is there a good little beginner php tutorial on the web that you would recommend for to read through that help me with this problem?

i could send you or anyone else who might be reading this the code for my search script if that matters as to what direction i should go to get this working.

then i would then need to go back and insert some line of code and a default value i suppose on every page of the site that where i want those two variables to be dynamically generated.

i like learning this stuff, so thanks a bunch for your help,
matt

Philosopher

3:11 pm on Jul 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the learning can be fun. I just started with PHP and databases a few months back out of necessity but it is enjoyable.

As to your question, it sounds like, and I am NO expert, that your best option is going to be to use either "sessions" or a cookie because you need something persistant throughout the users visit. I haven't had to mess with sessions at all, so I'm not going to be much help to you on that one, but I'm sure someone else on here can be.

It also sounds like you will need to change ALL of the pages on your site. If you will be needing the unique member id and name displayed on virtually any page on the site, then they all will need to be altered to take advantage of the php session. Now, since most likely all of your pages are .html pages, you have two choices. You can either change all of them to .php to tell the server to parse them for php content or you can modify your .htaccess file to tell the server to parse .html file extensions for php content.

Once on of the above is done, you will need to modify the search engine template and all of the static pages to display the proper member name through the use of the session or cookie.

So then when a user originally clicks enters your site they will click on the proper link. This will either set the cookie with the appropriate data or create a session with same. Then when they visit any page, that information is read and incorporated into the page.

I don't think it will be that hard, it just will take a bit of time to make the necessary adjustments and learn a bit about either the use of cookies or sessions.

As to which is better cookies or sessions, I think they both have their positives and negatives so it's probably best to just read up on them and see which one you feel will work best.

scattdaddy21

3:49 pm on Jul 22, 2004 (gmt 0)

10+ Year Member



thanks philosopher -

that's exactly what i've been looking for - for someone to point me in the right direction so i can start learning.

i appreciate it,
matt