Jump to content

stuartmarsh

Members
  • Posts

    49
  • Joined

  • Last visited

    Never

Posts posted by stuartmarsh

  1. I've echoed session_id and it remains the same at all times.

     

    Only one .htaccess in the root, code below:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^domain.co.uk$
    RewriteRule ^/?$ "http\:\/\/www\.domain\.co\.uk" [R=301,L]
    
    #Route HTML pages through index.php (page.html -> index.php?page)
    RewriteRule ^(.+)\.html$ index.php?file=$1 [NC]
    

  2. Hi all,

    I have two PHP files, one in root and the other in a folder called admin.

     

    If I set $_SESSION in a file in the admin folder and then view $_SESSION in any other file within the admin folder, everything is OK.

     

    However, if I then go to a file in root $_SESSION is blank, and it is blank if I then go back to a file in admin.

     

    This problem only exists on my hosting and doesn't happen on a local dev machine.  I've compared the php.ini session settings and there both the same.

     

    Any ideas?

     

    Files

    admin/test.php

    <?php
    session_start();
    
    if( empty($_SESSION) ) {
    echo "Session not set<br />";
    $_SESSION['test'] = "test";
    }
    
    echo "<pre>";var_dump($_SESSION);echo "</pre>";
    

     

    /test.php

    <?php
    session_start();
    
    echo "<pre>";var_dump($_SESSION);echo "</pre>";
    

     

  3. Still playing around with this.

    I have modified my regex to the following

    /(?=select|from|(left|right) (inner|outer) join|where|group by|having|order by)/im

    Can I make the (left|right) and (inner|outer) optional?

    So that it matches JOIN but also matches if there is any combination of left/right/inner/outer before it?

    Thanks

  4. I'm trying to break up a SQL statement so that I can can work on each segment individually.

    This is the code I have so far.

    $SQL = "SELECT *
    		FROM Table_1
    		INNER JOIN Table_2 ON Table_1.ID=Table_2.Table_1_ID
    		JOIN Table_3 ON Table_1.ID=Table_3.Table_1_ID
    		LEFT OUTER JOIN Table_4 ON Table_3.ID=Table_4.Table_3_ID
    		WHERE Field1='BLAH' AND Field2 IN ('1', '2', '3')
    		GROUP BY Field1, Field2
    		HAVING Field3='CHOO'
    		ORDER BY Field1, Field2 ";
    	$test = preg_split('/(select|from|(.*)join|where|group by|having|order by)/im', $SQL, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
    	var_dump($test);

    This is the result:

    array
      0 => string 'SELECT' (length=6)
      1 => string ' *
    			' (length=
      2 => string 'FROM' (length=4)
      3 => string ' Table_1
    ' (length=10)
      4 => string '				INNER JOIN' (length=14)
      5 => string '				INNER ' (length=10)
      6 => string ' Table_2 ON Table_1.ID=Table_2.Table_1_ID
    ' (length=43)
      7 => string '				JOIN' (length=
      8 => string '				' (length=4)
      9 => string ' Table_3 ON Table_1.ID=Table_3.Table_1_ID
    ' (length=43)
      10 => string '				LEFT OUTER JOIN' (length=19)
      11 => string '				LEFT OUTER ' (length=15)
      12 => string ' Table_4 ON Table_3.ID=Table_4.Table_3_ID
    			' (length=47)
      13 => string 'WHERE' (length=5)
      14 => string ' Field1='BLAH' AND Field2 IN ('1', '2', '3')
    			' (length=50)
      15 => string 'GROUP BY' (length=
      16 => string ' Field1, Field2
    			' (length=21)
      17 => string 'HAVING' (length=6)
      18 => string ' Field3='CHOO'
    			' (length=20)
      19 => string 'ORDER BY' (length=
      20 => string ' Field1, Field2 ' (length=16)
    

     

    As you can see it's sorta doing the right thing but I need it to only split before the keyword, instead of before and after as it is doing.  It is also producing two results when there is an "Inner Join".

     

    Can someone point out what I'm doing wrong?

     

    Thanks,

    Stu

  5. Using your example I changed the sql to

    Code: [select]

    $SQL = "SELECT col1, col2,          col3,col4 , IFNULL(blah, 'foo') AS foolah, foo AS [bar1], COUNT(foo) AS 'bar2'  FROM table WHERE col1='A';";

    and

    Code: [select]

    $str = trim($str," `");

    to

    Code: [select]

    $str = trim($str," `\]['");

    .

    Now it removes the ] and the end ' for array keys 5 & 6 respectively.

    But I'm still left with a [ on array key 5 and a start apostrophe on array key 6.

  6. Using your example I changed the sql to

    $SQL = "SELECT col1, col2,           col3,col4 , IFNULL(blah, 'foo') AS foolah, foo AS [bar1], COUNT(foo) AS 'bar2'  FROM table WHERE col1='A';";

    and

    $str = trim($str," `");

    to

    $str = trim($str," `\]['");

    .

    Now it removes the ] and the end ' for array keys 5 & 6 respectively.

    But I'm still left with a [ on array key 5 and a start apostrophe on array key 6.

  7. Hi all,

    Thanks for the replies and code.

    The code from MadTechie looks good.

    The code looks good but there is just one more consideration.  When using the AS clause I use either ' or [] around the alias name (I.e. col1 AS [foo 1], col2 AS 'foo 2').

    Can I use trim to filter out ', [, & ]?  I tried adding them to the charlist but it only removes the end apostrophe and "]".

     

    Thanks all!

  8. Hi all,

    I'm looking for a regex to extract fields from a SQL string.

    SQL: SELECT col1, col2, col3 FROM table WHERE col1='A';
    Expected results:
    Array[0] = "col1"
    Array[1] = "col2"
    Array[2] = "col3"
    

    Or at the very least a regex to get the string between SELECT and FROM.  Then I split it down and extract them programmatically.

    SQL: SELECT col1, col2, col3 FROM table WHERE col1='A';
    Expected results:
    Array[0] = "col1, col2, col3"

     

    Cheers,

    Stu

  9. I have a main domain on a .co.uk and a parked domain on .com.

    I have a .htaccess setup that redirects the .com and the domain without the www to my main domain.

    However, I can still access pages through domain.com/aboutus.html when I want it to redirect it to www.maindomain.co.uk/aboutus.html.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^Domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.Domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^MainDomain.co.uk$
    RewriteRule ^/?$ "http\:\/\/www\.MainDomain\.co\.uk" [R=301,L]
    #Routes pages through the index.php
    RewriteRule ^(.+)\.html$ index.php?file=$1 [NC]

    Can anybody tell me how to modify this so that it redirects page requests to my main domain?

     

    Cheers,

    Stu

  10. I'm messing with using XML to create a menu system and I am using SimpleXML.

    I'm want to merge several XML files together to produce the final menu XML.

     

    The menu XML looks like this:

    <menu>
       <item title="Home" link="home.php" />
       <item title="Content" link="content.php" />
    </menu>
    

     

    I have another XML called items that looks like this:

    <menu>
       <item title="Page1" link="page.php?id=1" addTo="Content" />
       <item title="Page2" link="page.php?id=2" addTo="Content" />
    </menu>

    I want to loop through the "items" XML and add a new child under the element that has a title that matches 'addTo'.

    Is there a quick way of doing this without looping through the menu XML for each item?  Something like $xmlMenu->item->"title="content"->addChild($name, $value)?

     

    The final output should resemble this:

    <menu>
       <item title="Home" link="home.php" />
       <item title="Content" link="content.php">
          <item title="Page1" link="page.php?id=1" />
          <item title="Page2" link="page.php?id=2" />
       </item>
    </menu>

     

    Thanks.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.