Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Scripting

  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Scripting

    The script on this http://forre.st/storage page is python(source at the bottom), but I dont know it and dont really have time to learn it right now. Is there a way to make a similar script but with html or php? I am pretty good with html and know some php.
    Thanks for any help.

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Ya absolutely.

    You can do the graph in Javascript and CSS (or Flash). You'll only need php if you want to store the data in a SQL database (which would be wise) or if you're grabbing the data from another website.

    The Python script is creating a nifty little image, which is nice for data encapsulation, but really uneccessary unless you're trying to protect your data.

  • Users who have thanked itsallkizza for this post:

    arthur92710 (11-03-2008)

  • #3
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    WOW 5 min response time! Thats awsome, I have never seen that before! The best part is that my question wasn't denied!

    I just have one question, how can I automatically grab the prices from the site?

  • #4
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Hm... you mean the prices listed under each image? Well assuming they don't have an API they're willing to let you use, then one sloppy way to do that is use PHP/ASP to grab the page's source code and parse through it's DOM.

    If you need any help with that let me know.

  • #5
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hum, that sounds not to hard, Ill try it out and see how far I can get.
    Thanks.

  • #6
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Here's a quick php API for you:
    Code:
    <?php
    $url = $_GET["url"] ? $_GET["url"] : null;
    if ($url) include($url);
    else echo("null");
    ?>

  • #7
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Uh, Im sorry
    Can you explain how it works?

  • #8
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Open up a blank txt document and copy and paste that php snippet into it, save it as something like "get_src.php"

    Upload that to your server (I have a temporary example for you: http://ebonyaura.com/get_src.php) and that can serve as your page source API.

    get_src.php accepts a single input called url and outputs that URL's source code. For example, "http://ebonyaura.com/get_src.php?url=http://www.google.com" will display google's homepage.

    Now all you need to do is call get_src.php from your project's page using Javascript (if you like), something like this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title></title>
    <style type="text/css">
    </style>
    <script type="text/javascript">
    <!--
    function getXMLHttp()
    	{
    	var xmlHttp;
    	try // Firefox, Opera 8.0+, Safari
    		{
    		xmlHttp = new XMLHttpRequest();
    		}
    	catch(e)
    		{
    		// Internet Explorer
    		try
    			{
    			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    			}
    		catch (e)
    			{
    			try
    				{
    				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    				}
    			catch (e)
    				{
    				alert("Your browser does not support AJAX!");
    				return false;
    				}
    			}
    		}
    	return xmlHttp;
    	}
    
    function getAnotherPage(url)
    	{
    	var xml_http = getXMLHttp();
    	if (xml_http)
    		{
    		xml_http.onreadystatechange = function()
    			{
    			if (this.readyState == 4)
    				{
    				doYourStuff(this);
    				}
    			}
    		xml_http.open("GET","http://ebonyaura.com/get_src.php?url="+url,true);
    		xml_http.send(null);
    		}
    	}
    
    function doYourStuff(xml_http)
    	{
    	alert(xml_http.responseText);
    	}
    // -->
    </script>
    </head>
    <body>
    
    <input type="button" value="click me" onclick="getAnotherPage('http://www.google.com');" />
    
    </body>
    </html>
    Of course you'll need to change ebonyaura.com to your domain, but here's a working example of the page I just typed up for you: http://ebonyaura.com/project.html

    Altogether, this is essentially a fast workaround for the same-origin policy constraint on ajax.

  • #9
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hum, that does not want to work on my server. I replaced ebonyaura.com to my domain.
    Ill check on something.

    And I have a question why is the "<input type="button" value="click me" onclick="getAnotherPage('http://www.google.com');" />"
    http://www.google.com?
    Last edited by arthur92710; 11-03-2008 at 08:23 PM.

  • #10
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    The whole point of that JS function and PHP api is that you can input any url any where, regardless of same-origin security sandbox issues.

    google.com is just an example


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •