[PHP] De GET waarde

Gestart doorDylan6 reacties59 weergaven

7 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hoi,

Ik ben bezig met iets waar ik me eigen websites op kan maken (een framwork). Nu loop ik tegen een probleem aan. Namelijk dit:

[COLOR= #0000BB]<?php
$allow[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]test[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]])) {[/COLOR]
     [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/in_array"]in_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$allow[/COLOR][COLOR= #007700])) {[/COLOR]
            [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700]);
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]403[/COLOR][COLOR= #007700];
        }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]404[/COLOR][COLOR= #007700];
    }
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/index.php[/COLOR][COLOR= #007700]);
}[/COLOR]
?>


Als ik nu naar http://voorbeel.nl/test ga krijg ik die pagina te zien. Maar als ik nu een GET waarde mee wil sturen werkt dat niet. Bijvoorbeeld:

http://voorbeeld.nl/test?say=Hoi

De GET waarde word dus niet mee verstuurd naar de pagina de moet worden opgehaald. Hoe kan ik er voor zorgen dat de GET waarde WEL mee gaat?

toevoeging op 1 januari 2013, 151014:
Of is dit een verkeerde manier om een frame-work te maken?
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Thommity schreef:
werkt http://voorbeeld.nl/index.php?url=test&say=hoi wel?
probleem ligt bij het url rewriten i think
Jep, dat werkt wel maar dat wil ik niet. Ik wil gewoon http://voorbeeld.nl/test?say=hoi

.htaccess:

RewriteEngine On

RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
RewriteEngine on
RewriteRule ^(.*).htm$ $1.php
0
Berichten
308
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Eerdere citaten tonen
probleem ligt bij het url rewriten i think

Jep, dat werkt wel maar dat wil ik niet. Ik wil gewoon http://voorbeeld.nl/test?say=hoi

.htaccess:

RewriteEngine On

RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
RewriteEngine on
RewriteRule ^(.*).htm$ $1.php

Dan moet je volgende code gebruiken.

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]say[/COLOR][COLOR= #007700]]))[/COLOR]
?>


Nu ga je checken voor de param url in je url, maar je geeft de param say mee, en vraagt url op.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Ik wil niet voor elke GET een aparte code in index maken. Ik zat te denken aan explode.

[COLOR= #0000BB]<?php

$allow[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]test[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]])) {[/COLOR]
     [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/in_array"]in_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$allow[/COLOR][COLOR= #007700])) {[/COLOR]
            
         [COLOR= #0000BB]$more[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]&[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]QUERY_STRING[/COLOR][COLOR= #007700]]);[/COLOR]
         
         [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$more[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]QUERY_STRING[/COLOR][COLOR= #007700]];[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$more[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php?[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$more[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]);
            }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            
            [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700]);
            }
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]403[/COLOR][COLOR= #007700];
        }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]404[/COLOR][COLOR= #007700];
    }
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/index.php[/COLOR][COLOR= #007700]);
}[/COLOR]
?>


Werkt nog niet helemaal

toevoeging op 1 januari 2013, 171543:
Oké, ik heb nu dit:

[COLOR= #0000BB]<?php
$allow[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]test[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]])) {[/COLOR]
     [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/in_array"]in_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$allow[/COLOR][COLOR= #007700])) {[/COLOR]
            
         [COLOR= #0000BB]$more[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]?[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_URI[/COLOR][COLOR= #007700]]);[/COLOR]
         
    [COLOR= #FF8000]//     echo count($more[1]).$_SERVER[REQUEST_URI];[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$more[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]) >=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php?[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$more[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]);
            }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            
            [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700]);
            }
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]403[/COLOR][COLOR= #007700];
        }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]404[/COLOR][COLOR= #007700];
    }
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Templates/index.php[/COLOR][COLOR= #007700]);
}[/COLOR]
?>


Als k nu http://voorbeld.nl/test?a=hoi heb krijg ik:

Warning: include(Templates/test.php?a=hoi) [function.include]: failed to open stream: No error in C:xampphtdocsindex.php on line 13

Warning: include() [function.include]: Failed opening Templates/test.php?a=hoi for inclusion (include_path=.;C:xamppphpPEAR) in C:xampphtdocsindex.php on line 13


Hoe los ik dat op?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Je kan geen bestanden includen met GET variables eraan vast..
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Nielsie schreef:
Je kan geen bestanden includen met GET variables eraan vast..
Jammer, weet iemand hoe je dat wel kan doen? Ik zat zonet ff te kloten met dit:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] save[COLOR= #007700]([/COLOR][COLOR= #0000BB]$value[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$value[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/return"]return[/URL][COLOR= #007700];
}
function[/COLOR] open[COLOR= #007700]([/COLOR][COLOR= #0000BB]$open[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$open[/COLOR][COLOR= #007700]];
}[/COLOR]
?>


En dan op index.php voor elke GET save laten doen, alleen dat werkt ook niet.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren