Xtremer360 Posted December 17, 2008 Share Posted December 17, 2008 I'm trying to change: if(isset($_COOKIE['page'])) { ajaxpage("$_COOKIE['page']", "content); } else { ajaxpage("default", "content"); } into its javascript equivilent for the page I have and me nor the person that gave me the code knows how. Does anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/ Share on other sites More sharing options...
Adam Posted December 17, 2008 Share Posted December 17, 2008 Try that.. if (document.cookie.match('page=[\w][\w\-\.]+;') != null) { This will also prevent any XSS injection, make sure the page name only includes chars: 0-9 a-z A-Z _ - . and only starts with 0-9 a-z A-Z _ * Not tested * A Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-717581 Share on other sites More sharing options...
Adam Posted December 17, 2008 Share Posted December 17, 2008 Sorry should be: if (document.cookie.match(/page=[\w][\w\-\.]+;/) != null) { A Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-717594 Share on other sites More sharing options...
Xtremer360 Posted December 17, 2008 Author Share Posted December 17, 2008 But that doesn't involve what the default page should be for inside the content div Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-717915 Share on other sites More sharing options...
Adam Posted December 18, 2008 Share Posted December 18, 2008 I'd only changed the condition in the IF .. if(document.cookie.match(/page=[\w][\w\-\.]+;/) != null) { ajaxpage("$_COOKIE['page']", "content); } else { ajaxpage("default", "content"); } A Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-718574 Share on other sites More sharing options...
Adam Posted December 18, 2008 Share Posted December 18, 2008 Jeez, not with it today. Get what you mean now: var page = document.cookie.match(/page=[\w][\w\-\.]+;/); if(page != null) { ajaxpage(page, "content); } else { ajaxpage("default", "content"); } A Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-718853 Share on other sites More sharing options...
Xtremer360 Posted December 18, 2008 Author Share Posted December 18, 2008 Works atleast EXCEPT for the fact that if I load a function and refresh it goes back to the default and doesn't reload what the last page function was. Hopefully that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-719255 Share on other sites More sharing options...
Adam Posted December 19, 2008 Share Posted December 19, 2008 Either in the JS as you call the 'ajaxpage' function, or in the PHP as you load each page, you'll need to update the cookie to the new page... A Quote Link to comment https://forums.phpfreaks.com/topic/137317-changing-php-code-into-js-code/#findComment-719493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.