Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1] 2   Go Down

Author Topic: another question (regarding user album urls)  (Read 38998 times)

0 Members and 1 Guest are viewing this topic.

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« on: September 25, 2003, 05:38:01 pm »

Hi..
I am trying to use coppermine as a Yahoo Photo style online album for students in our university. However, the urls for the users' personal albums are hard if not impossible to remember... Is there a way to make a simpler url for users' albums using just their usernames and not their userid numbers? for example instead of

http://photo.enctu.org/index.php?cat=10002
I would like it to be accessible by http://photo.enctu.org/album/oasis

any help would be appreciated
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
another question (regarding user album urls)
« Reply #1 on: September 25, 2003, 05:59:37 pm »

It depends on how adept you are with PHP, I will roughly outline what it will entail for having URL like http://photo.enctu.org/album/oasis

1) the album will have to be a PHP file instead of a directory - this PHP file should take the username from PATH_INFO query the database and redirect the page to correct location

2) use .htaccess to for album (even without .php extension) to be interpreted as a PHP file
Logged
SANIsoft PHP applications for E Biz

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #2 on: September 25, 2003, 10:11:58 pm »

thanks!

I can see what you're getting at... I think that would probably do, but I'm not too good at php. At most, I can do simple changes to the scripts, but I can't start from scratch...

Could anyone write such a file, or could it be added into the release?



Also, I was thinking whether it could be done with the mod_rewrite module in apache. I know rewritemap can check flatfiles but is there any way it could be tweaked to read from an sql database to match the category number to the corresponding username?
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
another question (regarding user album urls)
« Reply #3 on: September 26, 2003, 05:20:13 am »

Quote from: "oasis"
Also, I was thinking whether it could be done with the mod_rewrite module in apache. I know rewritemap can check flatfiles but is there any way it could be tweaked to read from an sql database to match the category number to the corresponding username?

mod_rewrite cannot get information which is not already there in the URL

eg: http://photo.enctu.org/index/cat/10002 can be rewritten as http://photo.enctu.org/index.php?cat=10002

Nothing more
Logged
SANIsoft PHP applications for E Biz

gtroll

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 618
    • CPG-Nuke
mod for nicer url's
« Reply #4 on: September 26, 2003, 09:51:35 am »

This type of url rewriting is used in php-nuke all the time, let me explain how the same method might be used for your need.
You have a header file with a function that rewrites the urls and include it at the top of the page.
A footer file is used to call it, which is included at the bottom of the page. And rewrite the url as proposed by tarique in your htaccess
Excerpts from my php-nuke header.php
Code: [Select]

ob_start();
function replace_for_mod_rewrite(&$s)
{
$urlin =
array(
"'(?<!/)index.php?cat=([0-9]*)'",
"'(?<!/)photos/([0-9]*)&'")
$urlout = array(
"photos/\\1",
"index.php?cat=\\1&"
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}

footer.php
Code: [Select]

$contents = ob_get_contents(); // store buffer in $contents
ob_end_clean(); // delete output buffer and stop buffering
echo replace_for_mod_rewrite($contents); //display modified buffer to screen

in htaccess
Code: [Select]

RewriteEngine On
RewriteRule ^photos/([0-9]*) index.php?cat=\\1

Now to get this to work with your user names instead of the number you'd have to write a mysql query to look up the user name for a given gallery number and have a rewrite map to each one.

moorey

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 404
another question (regarding user album urls)
« Reply #5 on: September 26, 2003, 10:31:37 am »

Very nice.  I love mod_rewrites!

*hugs* Apache
Logged

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #6 on: September 26, 2003, 12:46:47 pm »

Quote from: "tarique"

mod_rewrite cannot get information which is not already there in the URL


rewritemap can get information which is saved in a flatfile or external script. Could it be possible for this flatfile be generated on the fly by querying mysql for the corresponding username of the provided ID number?

EDIT: sorry, i have ideas but i'm not a programmer and I can't put them into code or even know whether it is possible, so forgive me if the question sounds stupid
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

xarumanx

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 61
    • http://gallery.webtips.at
another question (regarding user album urls)
« Reply #7 on: September 26, 2003, 01:55:37 pm »

From a developers point of view, this shouldn't be a big problem, but AFAIK not much hoster support rewritemap...
Logged

<?php echo signature(); ?>

gtroll

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 618
    • CPG-Nuke
More about mod for nicer URLs
« Reply #8 on: September 26, 2003, 02:10:51 pm »

Most free hosts don't support mod_rewrite but the better budget ones do...
In reality it might be easier to rewrite the coppermine code to user the user name as the parameter than to do extensive rewrite tables with sql queries and ecetera. Your right you're beyond your coding knowledge with your questions and will probably have to rely on someone else to implement this if you do, but there are no stupid questions... (except those answered in the manual or FAQ)  :wink:

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #9 on: September 27, 2003, 02:41:48 pm »

OK unfortunately rewritemap doesn't seem to like windows, but I have managed to simplify the problem a bit.
So far I have managed to use RewriteRule to shorten the url to
http://photo.enctu.org/10002
this is my .htaccess:
Quote
RewriteEngine On
RewriteRule ^([a-z0-9&=]+)$ index.php?cat=$1

It's good enough, but is there any where I could add some code in coppermine that will let me do this:

First I will change htaccess into:
Quote
RewriteEngine On
RewriteRule ^([a-z0-9&=]+)$ index.php?username=$1

That should turn requests for: http://photo.enctu.org/oasis
into: http://photo.enctu.org/index.php?username=oasis

so when a request for http://photo.enctu.org/oasis gets sent to the server, it obviously calls index.php and gives it the username variable. I have a feeling that the username variable could then be used to query mysql for the corresponding user_id (which would be 10002) and set a variable $cat with that value, which will call the correct albums of that user.

Am I correct? And if I am, how should I continue now?
I don't know where to put the part for the query
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
another question (regarding user album urls)
« Reply #10 on: September 27, 2003, 02:55:46 pm »

Quote from: "oasis"
That should turn requests for: http://photo.enctu.org/oasis
into: http://photo.enctu.org/index.php?username=oasis

:idea:  http://photo.enctu.org/oasis will return a 404 - so instead of going thru all the hassle of rewrite - why not just write a custom 404 document extract the username and redirect using header ( )

Yeah it messes up the Web Server logs - but a small price I would say
Logged
SANIsoft PHP applications for E Biz

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #11 on: September 27, 2003, 03:27:56 pm »

Quote
http://photo.enctu.org/oasis will return a 404 - so instead of going thru all the hassle of rewrite - why not just write a custom 404 document extract the username and redirect using header ( )


actually it doesn't. Try clicking on it~  :)
Now it just goes to the homepage, because cat=oasis doesn't exist. If, however you link to http://photo.enctu.org/10002 it goes straight to my album (oasis' album).. So that means that index.php IS processing the variable...... now i just need it to process it one more step... query the user_id from the username.
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
another question (regarding user album urls)
« Reply #12 on: September 27, 2003, 03:34:06 pm »

Quote from: "oasis"
actually it doesn't. Try clicking on it~  :)

Thats because you already got rewrite going ....
Logged
SANIsoft PHP applications for E Biz

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #13 on: September 27, 2003, 03:42:48 pm »

oh, heh... :P  I see what you mean now..

So how do I make index.php recognize the username and retrieve the corresponding user_id?

by the way, I should remind you that I will be redirecting(rewriting) the shorter url to index.php?USERNAME=XXXX instead of index.php?cat=XXXX
so the original code shouldn't have to be change much, just have some lines added to it....
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
another question (regarding user album urls)
« Reply #14 on: September 27, 2003, 05:47:40 pm »

OK this is not tested out but the cat for user album is "1"+user_id padded with enough zeros to make it 4 digit

so if your user_id is 2 then the cat for you will be 10002 BUT if your user_id is 12 then the cat for you will be 10012

Also to keep the compatibility between the future versions of CPG do not write any code into index.php by just redirect to it after calculating the correct cat

IMPORTANT : Share your complete code once you finish it :)
Logged
SANIsoft PHP applications for E Biz

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #15 on: September 27, 2003, 06:16:06 pm »

You can do that by adding 10000 to the user_id (I doubt I'll ever have more than 9999 users so it should be ok), but now... I can call it out from the cpg11d_users table using the $username, but how do I replace $cat with the value that is returned? where do I put the code to tell it to use the value pulled out from the database as $cat?
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
another question (regarding user album urls)
« Reply #16 on: September 27, 2003, 06:21:55 pm »

I suggest take a break,  the solution will hit you in the morning :)

Dont make changes to index.php and don't rewrite URL to directly point to index.php but a different script which in turn uses the header function to redirect to index.php?cat=1000x
Logged
SANIsoft PHP applications for E Biz

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #17 on: September 27, 2003, 06:39:31 pm »

oh gosh that's a good idea.. I'll give it a shot
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #18 on: September 27, 2003, 08:49:37 pm »

woah.... finally got it going...

now http://photo.enctu.org/oasis redirects to http://photo.enctu.org/index.php?cat=10002  :D

One last question though... Is there a way I could do it so the the url doesn't change automatically? What I mean is that currently when the page loads the url in the address bar is changed... what should I do to keep it there? Is there any other function other than header(location: URL) ? One that will keep the shortened url in the address bar.

by the way, here are the files:

Quote
HTACCESS FILE

RewriteEngine On
RewriteRule ^([a-z0-9&=]+)$ album.php?username=$1


Quote
ALBUM.PHP FILE

<?php

/**************************************************************************
   Database functions
 **************************************************************************/

// Connect to the database
function db_connect()
{
        global $CONFIG;
        $result = @mysql_connect(host, user, pass);
        if (!$result)
                return false;
        if (!mysql_select_db(coppermine))
                return false;
        return $result;
}

// Perform a database query
function db_query($query)
{
        global $query_stats;

        $query_start = getmicrotime();
        $result = mysql_query($query);
        $query_end = getmicrotime();
        $query_stats[] = $query_end - $query_start;

        if (!$result) db_error("While executing query \"$query\"");

        return $result;
}

// Error message if a query failed
function db_error($the_error)
{
        global $CONFIG;

        if (!$CONFIG['debug_mode']) {
            cpg_die(CRITICAL_ERROR, 'There was an error while processing a database query', __FILE__, __LINE__);
        } else {

                $the_error .= "\n\nmySQL error: ".mysql_error()."\n";

                $out = "<br />There was an error while processing a database query.<br /><br/>
                    <form name='mysql'><textarea rows=\"8\" cols=\"60\">".htmlspecialchars($the_error)."</textarea></form>";

            cpg_die(CRITICAL_ERROR, $out, __FILE__, __LINE__);
        }
}

// Fetch all rows in an array
function db_fetch_rowset($result)
{
        $rowset = array();

        while ($row = mysql_fetch_array($result)) $rowset[] = $row;

        return $rowset;
}

function getmicrotime(){
        list($usec, $sec) = explode(" ",microtime());
        return ((float)$usec + (float)$sec);
}

function cpg_die($msg_code, $msg_text,  $error_file, $error_line, $output_buffer = false)
{
    $ob = ob_get_contents();
        if ($ob) ob_end_clean();
        exit;
}


db_connect() || die("<b>Coppermine critical error</b>:<br />Unable to connect to database !<br /><br />MySQL said: <b>".mysql_error()."</b>");
$username = $HTTP_GET_VARS['username'];
$results = mysql_query("SELECT user_id FROM cpg11d_users WHERE user_name = '$username'");

list($row) = mysql_fetch_row($results);
if (!$row) {
$row = 0;
}
$idnum=$row+10000;
$catid = $idnum;
    Header("Location: http://photo.enctu.org/index.php?cat=".$catid);
    exit;
?>
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Oasis

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 252
  • iNSiGNiA
    • Pixnet Gallery
another question (regarding user album urls)
« Reply #19 on: September 27, 2003, 09:04:57 pm »

i know practically no php, and these are just bits and pieces I taken from other files, edited, and put together, so the code is probably pretty messy... If someone can clean it up for me that would be great!
Logged
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org
Pages: [1] 2   Go Up
 

Page created in 0.033 seconds with 19 queries.