Darkmatter5 Posted November 11, 2008 Share Posted November 11, 2008 If my URL would be index.php?page=nothing.php, how can I print or use the "page" variable? Link to comment https://forums.phpfreaks.com/topic/132343-how-to-get-variable-passed-in-url/ Share on other sites More sharing options...
trq Posted November 11, 2008 Share Posted November 11, 2008 I believe you'll need to parse window.location yourself. Link to comment https://forums.phpfreaks.com/topic/132343-how-to-get-variable-passed-in-url/#findComment-688094 Share on other sites More sharing options...
webster08 Posted November 12, 2008 Share Posted November 12, 2008 split the "page=" variable of your window.location; then call key[1] from the array that the split creates. Link to comment https://forums.phpfreaks.com/topic/132343-how-to-get-variable-passed-in-url/#findComment-688192 Share on other sites More sharing options...
Darkmatter5 Posted November 12, 2008 Author Share Posted November 12, 2008 I used var page=document.location.search.substring(5) But the I need to call the page variable into the location function. Here's my code: var page=document.location.search.substring(5) if(page==undefined) { location='gateway.php'; } else { location="page"; } How do I get it to output the value of page instead of http://mydomain.com/page Link to comment https://forums.phpfreaks.com/topic/132343-how-to-get-variable-passed-in-url/#findComment-688510 Share on other sites More sharing options...
RichardRotterdam Posted November 12, 2008 Share Posted November 12, 2008 this is one I found there are more out there try a search on javascript querystring get http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx Link to comment https://forums.phpfreaks.com/topic/132343-how-to-get-variable-passed-in-url/#findComment-688800 Share on other sites More sharing options...
Darkmatter5 Posted November 12, 2008 Author Share Posted November 12, 2008 Let me repost my full code. <?php if(isset($HTTP_COOKIE_VARS["resolution"])) { if(!isset($_GET )) { header("Location: gateway.php"); } else { header("Location: $_GET "); } } else { ?> <script language="javascript"> <!-- writeCookie(); function writeCookie() { var today=new Date(); var the_date=new Date("December 31, 2023"); var the_cookie_date=the_date.toGMTString(); var the_cookie="resolution="+ screen.width +"x"+ screen.height; var the_cookie=the_cookie + ";expires=" + the_cookie_date; document.cookie=the_cookie var page=document.location.search.substring(5) if(page==undefined) { location='gateway.php'; } else { location=page; } } //--> </script> <?php } ?> This code mostly works, the page variable in the javascript works great, but the line "else { location=page; }" doesn't work right. It's output in the address bar is http://mydomain.com/=res_maint.php. res_maint.php is what the page variable is set to, but it's putting in that "=" and causing the browser to not find the page. How can I fix this? Link to comment https://forums.phpfreaks.com/topic/132343-how-to-get-variable-passed-in-url/#findComment-688858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.