Blade Maker Posted July 24, 2011 Share Posted July 24, 2011 I would like to know how I would secure a js with php in it such as: Menu Links refresh every x seconds, I would need to send the id of the user to the one file/function that refreshes and such, but anyone could easily edit the ID, how could I check? Thanks. Quote Link to comment Share on other sites More sharing options...
Danny696 Posted July 24, 2011 Share Posted July 24, 2011 Sstore the userid in a session. Pritty sure anyone cannot edit them Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted July 24, 2011 Share Posted July 24, 2011 You cannot edit a session indeed however you may usually hijack it and take the one of somebody else. Depends how the sessions are built. Anyhow it's a lot lot harder to do than simply changing an id ;) Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted July 24, 2011 Author Share Posted July 24, 2011 Okay, now a little off topic, is there a javascript function to load a file contents? Kind of like require(''); but I am trying to make a div refresh with javascript, not jquery. I originally used the php function require but now I realize its not going to work at all :p So would there be a way to load a file content weather its a txt file or php file in javascript. Thanks. Quote Link to comment Share on other sites More sharing options...
Dayo Posted July 24, 2011 Share Posted July 24, 2011 there is in jquery but not javasript (to my knoladge) Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted July 24, 2011 Share Posted July 24, 2011 Why would you like to load a PHP or TXT file inside your javascript? You may load javascript either by adding a <script> tag somehow either via dom or by modifying somehow your document, or via AJAX and use eval. But javascript will not be able to directly use the PHP source... you should explain more your goal if you want that we help you. Quote Link to comment Share on other sites More sharing options...
runthis Posted July 24, 2011 Share Posted July 24, 2011 Actually a friend showed me this script but i havent needed to use it yet. It basically can let you include anything, even php (or js/php) into the head dynamically, like i said though i haven't used it yet but here it is along with the original note he left me with it. /* This comes in quite useful.. It basically includes PHP into the page when the page has already loaded It cant feed any information into the page but it can run scripts in the background.. : D */ script = document.createElement( 'script' ); script.src = file; document.getElementsByTagName( 'head' )[0].appendChild( script ); Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted July 24, 2011 Author Share Posted July 24, 2011 I am trying to refresh a div which is suppose to echo out what is in a php file or text file, so I have it change the inner html of it and I am trying to load the page into the inner html, so when I change the text or php file then the text in the div would change to what I changed it to, so it needs to refresh, I have the refresh going but I just need to know how to make it check the file every time it executes. Correct me if I am wrong, but Jquery is Javascript but in an easier language? So therefor Javascript needs to have a function to load the content of another file. Quote Link to comment Share on other sites More sharing options...
runthis Posted July 24, 2011 Share Posted July 24, 2011 (edited) Yes you are correct and you do not need jquery at all ... at all! to do what you want to do, here is a simple script that loads a page into a div. Also the native function for javascript is "innerHTML" example "document.getElementById('elementid').innerHTML=("");" Here is the ajax function replace(id,file){ var xmlhttp; if(window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest() }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4&&xmlhttp.status==200){ document.getElementById(id).innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET",file,true); xmlhttp.send(); } Although i cannot confirm the compatibility for all browsers, it works pretty good for me. use this function like this <a onClick="replace('elementtochange','yourfile.php');">Click me</a> <div id="elementtochange">I will be changed</div> to still have the cursor you can add a href to the "a" element, however i find its alot better to just use style a { cursor : pointer; } Edited July 24, 2011 by runthis because MWG parses for smileys in code Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted July 24, 2011 Author Share Posted July 24, 2011 Okay now is ajax a more advanced js? For some reason I just wanted to do this only with js and not jquery, but if ajax is js also then that is fine. Also does Jquery use ajax? Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Danny696 Posted July 24, 2011 Share Posted July 24, 2011 (edited) AJAX is just JavaScript, jQuery is a libaray for JavaScript, Pritty much like a php function e.g. Username($userid) is a php function and contains all the stuff to grab a username, $.get(page) is a jQuery function that contains all the stuff to grab the page with get parameters Edited July 24, 2011 by Danny696 Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted July 24, 2011 Author Share Posted July 24, 2011 Hey thanks Danny for answering my question, I will use ajax as I do not want to use a library for javascript, I knew jquery was a library but still thanks for answering. Quote Link to comment 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.