Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: How to pass arbitrary PHP variables via URL - can this be done?  (Read 9022 times)

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 163
    • domdelimar.com

Don't know if this is the right place to post this, but I hope it won't get unnoticed...

Q1: Is there a way to use sNews and at the same time pass arbitrary PHP variables at the end of the URL?

Example: if I don't use sNews and enter this in URL where example.com is my domain...

http://example.com/index.php?kw=keyword

(You guessed it right: it's for being able to track under which ad group keyword my AdWords ad was shown to the visitor who came on my website)

Then I could access the "keyword" part with:
<?php echo $_GET["kw"]; ?>


Now switch to sNews with all the benefits it offers...

But how do I attach that "?kw=keyword" or "&kw=keyword" so that I can access the "keyword" as in the example above?

I have tried using equilni's SEF switcher but that didn't help which leads me to think playing with .htaccess is the way to go with this, but I'm a complete newbie with .htaccess and if that's the only way to do it, then I'll have to go without sNews for the moment...

Q2: Am I wrong in my assumption or if I'm not, can somebody experienced with .htaccess please help me here?
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #1 on: June 16, 2008, 03:07:19 PM »

Don't know if this is the right place to post this, but I hope it won't get unnoticed...

Q1: Is there a way to use sNews and at the same time pass arbitrary PHP variables at the end of the URL?
      Example: if I don't use sNews and enter this in URL where example.com is my domain... http://example.com/index.php?kw=keyword

Then I could access the "keyword" part with: <?php echo $_GET["kw"]; ?>

Now switch to sNews with all the benefits it offers...

But how do I attach that "?kw=keyword" or "&kw=keyword" so that I can access the "keyword" as in the example above?

Passing arbitrary PHP values at the end of URLs is not something I am familiar with. I don't think we would want this script to have anything to do with index.php.

If we were to use your approach, then the script would need to become part of the snews.php file and it would also need to be integrated into several other functions to display through function center() and... if it's to display data that only the Admin needs to see... I would only want it displaying to the Admin from one of the Admin panels.

My approach (on a default sNews 1.6) would be:
1 - try putting the Adwords tracking script into a separate file... perhaps called adtracker.php.
2 - Include the file at the top of the index.php file, just under the string that includes the snews.php file.
3 - Assuming the script displays its stats through its own template (interface)... and since it only needs to be viewed by the Admin when logged it,
     I would put text-link to the script in one of the panels in the Main Admin page... so it would show the script stats when clicked.
4 - I would put an "Administration" text-link in the script's stats page somewhere so I could return to the main Admin page again when desired.

This may or may not work in practice and has not been tested by me in any way... it is just how I try to do it.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #2 on: June 16, 2008, 04:36:50 PM »

Not sure what you are looking to do with the keyword, but did you try the keyword mod by me? I think the solution you need is there
Logged

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #3 on: June 16, 2008, 09:49:55 PM »

Or maybe what you are looking for is just adding [L,qsappend] at the end of each rewrite rule in htaccess ?
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #4 on: June 16, 2008, 09:59:32 PM »

Is easy to pass arbitrary variables via URL also with standard version of sNews...
Look at my page. Insert few values in form and press "Submit". See the URL then...
Logged

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 163
    • domdelimar.com
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #5 on: June 17, 2008, 12:09:51 AM »

Thank you all for trying to help...

funlw, that's exactly that I want to do! Could you please tell me how you accomplish that?
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #6 on: June 17, 2008, 12:47:05 AM »

I don't know if that will help but I will tell you tomorrow how I did it.
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #7 on: June 18, 2008, 12:13:16 AM »

Ok, is simple what I did.
- you must follow the steps on creating a hardcoded page:
-- define a sef variable (blade, by example)

-- modify title, sitemap, pages functions as is for archive, sitemap, contact, etc.
-- in center function, insert a new case there where you have cases for archive, sitema, contact. etc. :
---- case blade: blade_function(); break;
-- create the blade_function().


Color green mean you must do it.
Color blue mean you must do it only if you want a visible page.

Inside that function, you can deal with any parameters you want.
Code: [Select]
<?php
$param01 
clean(cleanXSS($_GET['prm01']));
if(!isset(
$param01)....){ // <-- be careful at validating data....
  // your code
}
else {
  
// your code
}

So, you can call that like this:
http://yourdomain.com/index.php?category=blade%2F&prm01=3&prm02=15
where:
prm01 = 3
prm02 = 15
are submitted parameters. Or, you can make another function for automated submitting of parameters.

I not discussed about the form because I understand that you don't need a form.

blade_function() function can display what you want, where you want. Or can store data in your mysql, or can do anything or nothing at all :) .
Logged

nvision

  • Newbie
  • *
  • Karma: 1
  • Posts: 5
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #8 on: September 18, 2008, 06:40:35 PM »

funlw65,

Nice website! Looks like you have made a lot of modifications to the standard sNews distribution.

I was trying to follow the URL example you gave here.  Di alter the mod-rewrite to do this? 

 
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: How to pass arbitrary PHP variables via URL - can this be done?
« Reply #9 on: September 19, 2008, 05:02:50 AM »

Hi nvision, thanks!

I just packed all mods I liked from these forums. About modifications, not all are very inspired (though, still functional as desired) and is showing my (low) level of knowledge regarding to sNews.

You don't need to activate mod_rewrite for using something like in my page example... but is working also with mod_rewrite enabled... (using index.php?category=blade..... etc. )


Anyway, is working also in this format http://www.morisca.net/blade/&itsr=5&iid=2.2&ib=5&ialpha=4&icl=0.8&ipstn=5/  (just tried  :P )


-------------------------------
Here is another featured site and you can find many more just exploring sNews forums.
« Last Edit: September 19, 2008, 05:29:31 AM by funlw65 »
Logged