|
Need some help with PHP
|
View this Thread in Original format
| nekholm |
I'm making some kinda personal page with PHP, and there's one thing I don't know how to do. It should be really simple, but I just can't figure out how to do it..
The thing is, I use include("$view.php"); => nek.php?view=whatever, and if someone goes to mypage/whatever.php, I want it to forward/redirect the visitor to mypage/nek.php?view=whatever.
I tried it with javascript (if (top.location.href != nek.php?view=test ) top.location.href = nek.php?view=test). It didn't work tho, it kept refreshing the page over and over again. But it almost worked ;) So it could be done in a quite similar way I guess.
Anyone with ideas on how to make this work with either PHP or javascript? |
|
|
| nekholm |
| Noone with any ideas? |
|
|
| DJ RozzeR |
| I dont think it is possible to run a Javascript in a php script, i maybe wrong i know i had problems when i used js with php, i would look at php dev sites and on google too. |
|
|
| DJ RozzeR |
| I dont think it is possible to run a Javascript in a php script, i maybe wrong i know i had problems when i used js with php, i would look at php dev sites and on google too. |
|
|
| DJ RozzeR |
| quote: | Originally posted by Rostros
I dont think it is possible to run a Javascript in a php script, i maybe wrong i know i had problems when i used js with php, i would look at php dev sites and on google too. |
wtf it posted it twice , wierd |
|
|
| loconet |
in whatever.php, assuming theres no ouput b4..
code:
$fname = basename($_SERVER['PHP_SELF']);
$view = substr($fname,0,strpos($fname,"."));
header("Location: mypage/nek.php?view=$view");
|
|
|
| Mr Game+Watch |
| Not sure of the PHP implementation (I'm a ColdFusion programmer myself)... but can you have a page that extracts the URL paramater (in this case "view"), and then $include(URL Paramater) dynamically... You shouldn't even need to worry about javascript. |
|
|
| nekholm |
| quote: | Originally posted by DJ RozzeR
I dont think it is possible to run a Javascript in a php script, i maybe wrong i know i had problems when i used js with php, i would look at php dev sites and on google too. |
Maybe not, I don't know. I've tried to search, but the problem is I don't really know what to search for..
| quote: | Originally posted by DJ RozzeR
wtf it posted it twice , wierd |
And instead of edit the second post, you post a third time ;)
| quote: | Originally posted by loconet
in whatever.php, assuming theres no ouput b4..
code:
$fname = basename($_SERVER['PHP_SELF']);
$view = substr($fname,0,strpos($fname,"."));
header("Location: mypage/nek.php?view=$view");
|
Inside I assume? What else, I tried it but it didn't work.. :(
| quote: | Originally posted by Mr Game+Watch
Not sure of the PHP implementation (I'm a ColdFusion programmer myself)... but can you have a page that extracts the URL paramater (in this case "view"), and then $include(URL Paramater) dynamically... You shouldn't even need to worry about javascript. |
Did I mention I'm quite new to PHP, I only know some very simple stuff? In other words, I have no idea how that would work.. :sadgreen: |
|
|
| loconet |
| quote: | Originally posted by nekholm
Inside I assume? What else, I tried it but it didn't work.. :(
|
Yes inside .
I tested having test.php as:
code:
it redirects to /index.php as:
/index.php?view=test
do you get an error message? |
|
|
| nekholm |
| That actually works :D I tested it, but I used $p instead of $view on another page, so I just forgot to change $view to $p. But yes it works. Thanx alot :happy2: |
|
|
|
|