Page 1 of 1

...Noobie $PHP_SELF question

Posted: Mon Mar 21, 2005 9:12 pm
by theda
I've been fiddling around and came up with the idea: "Hmm... when I switch skins, why don't I just stay on the page I originally was on, instead of being redirected to the index.php page"

But I've been fiddling around *of course* and haven't seemed to have found the answer. I'm sure it's something simple, and I'm sure you're all getting annoyed with having to deal with the same person every day ^_^, with the same code (plus the changes of a previous question).

Right now, as it is, if I am on "gallery.php" and decide to switch "skins" by clicking ?index.php?ver=blah... it then redirects to index.php... My question, as I kind of stated above, is that I want to be able to view index.php?id=gallery while at the same time changint the skin. I've noticed that doing index.php?id=gallery&ver=blah changes it and all, but I need a way to input a variable instead of gallery, so that I can click a link from any page and click index.php?id=anypage&ver=blah so that I switch versions, but not pages...

As I said earlier, I'm sure it's something really obvious, but it escapes me... But you'll be happy to know that I did something on my own in php, and didn't have to rely on someone else for help! For once, heh. This is not one of those situations, however! All help is appreciated. And feyd... You still rock for your rescripting of my original code ^_^... Edit: Well actually, not all of my original code, just the "page identification" part ^_^;

Posted: Mon Mar 21, 2005 9:30 pm
by John Cartwright
This thread is all but too general.

In your index.php, before you have your function to include the requested page, or any page for that matter, have a function something along these lines..

Code: Select all

if (!empty($_GET['vers']))
{
     echo '<link href="'.$_GET['vers'].'.css" rel="stylesheet" type="text/css">';
}
else
{
     echo '<link href="default.css" rel="stylesheet" type="text/css">';
}
For each different style you want, have a different style sheet.

edit| forgot to mention you'll need to set the session for it to remember to use your "remembered" style.. beat me too it though feyd :wink:

Posted: Mon Mar 21, 2005 9:31 pm
by feyd
you can use a session variable to record the current/last page a person was on. Then redirect back to it when processing an event which would need a redirection... Or, you can link to the current URL with added variables to make the switch transparently (sorta)

viewtopic.php?t=30090

Posted: Tue Mar 22, 2005 6:43 am
by theda
Well, my original question (although it probably wasn't worded right..) was how to get a current url (like http://www.blah.com/index.php?id=blah) and make a variable equal that, so that the code

Code: Select all

<a href=&quote;$variable&ver=blah&quote;></a>
Edit: And I tried to fiddle with that session thing... It doesn't work on my server (something about globals being off and such...)

Posted: Tue Mar 22, 2005 6:48 am
by Pyrite
On a simular note, I use cookies to store the theme, then when the user comes back to my site like a few days later, it will remember what theme he last used. And I do the simular, check for the cookie and if not, set one with the current theme and set the stylesheet accordingly.

pysquared.com

Posted: Tue Mar 22, 2005 6:58 am
by theda
Pyrite, that is exactly what I did ^_^; But now I want to be able to, while the user is on the website, can change the "skin" to another while staying on the page he was originally...

Posted: Tue Mar 22, 2005 7:15 am
by traherom
theda wrote:Edit: And I tried to fiddle with that session thing... It doesn't work on my server (something about globals being off and such...)
If you did it this way:

Code: Select all

<?php
    session_start();
    session_register("variable name");
?>
and got an error about automatically registered gloabals or such... that's good. :)

Try doing it the "new" way:

Code: Select all

<?php
    session_start();
    $_SESSION['variable name'] = 123123123;
?>
The $_SESSION array is restored to it's previous state each time the user returns during that session (while their browser is open).

So, for your style sheet thing:

Code: Select all

<?php
    session_start();

    if(isset($_GET['skin']))
    {
        $_SESSION['skin'] = $_GET['skin'];
    }

    if(!isset($_SESSION['skin']))
    {
        $_SESSION['skin'] = 'default';
    }

    // Then you'd use $_SESSION['skin'] as the name of your style sheet in the link tag. Sorry, got to go...
?>

Posted: Tue Mar 22, 2005 7:20 am
by Pyrite
theda, take a look at my website (pysquared.com) and let me know if that is what you are looking for. You can change the themes at the bottom of the page from the select dropdown.

Posted: Sun Mar 27, 2005 3:58 pm
by theda
Pyrite, that's kind already what my script does (with the skins)... The only difference now is that I want to change a skin on page (blah.com/?id=BLAH) and still remain on that page after I change the skin. Currently, How it is coded, it redirects back to the blah.com page.

Edit: Traherom, I don't want to use Sessions. I am using cookies and only cookies. Thanks for the help though.

And excuse the late response, I was in Seattle and had limited access to computers (argh! vacations!...)

Posted: Sun Mar 27, 2005 9:17 pm
by Pyrite
Yes, when you change themes on my site, it sets a new cookie to the theme you choose and refreshes the page you are on.

Posted: Mon Mar 28, 2005 6:40 am
by theda
Well then, mind sharing what to do then? This thread wasn't here just to for chatting :lol:

Posted: Mon Mar 28, 2005 5:55 pm
by theda
I found another website that does exactly what I want my script to do:

http://www.spoono.com <-- Awesome site indeed! Well, on their website, you'll notice "Flavors" at the top right. If you click one of them, it changes colors... But if you go to one of their tutorials, and then click a "Flavor", it'll stay on the page that you were viewing (the tutorial). That is what I want it to do...