Welcome! Log In Create A New Profile

Advanced

Tips And Tricks using php

Posted by gcobani 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Tips And Tricks using php
January 29, 2010 11:41AM
guys lets share php scripts and any other useful codes ralated to software and web development!

Here is how to re-direct a website from non existing one to the working one
<html>
<?php
//this will NOT work, the browser received the HTML tag before the script
header( 'Location: http://www.yoursite.com/new_page.html'; ) ;
?>

please delete every content on the website and put this code

gbakamela [77234715]
avatar
Mac
Re: Tips And Tricks using php
January 29, 2010 12:00PM
Ahem.... as described in the welcome post, try and add your code in a code tag. Like this:

Here is how to re-direct a website from non existing one to the working one
Language: PHP
<?php //this will NOT work, the browser received the HTML tag before the script header( ';Location: [http://www.yoursite.com/new_page.html]'; ) ; ?>

Now which reads better - yours or mine?
avatar Re: Tips And Tricks using php
January 29, 2010 12:48PM
hah hah yours ofcossmile how did you do it? by the way abt that MySql installation the real problem was that before i started with PHP i had JavaNetbeans running on my system and Microsoft visual studio 2008 .net frame that with MySql so when i try to install xampp it detect that apache is already runing also MySql, so wat i did i bought new hard drive then installed new windows 7 pro on it a dual booting and done as you instructed then everything now its working thanks

gbakamela [77234715]
avatar
Mac
Re: Tips And Tricks using php
January 31, 2010 04:00PM
mac Wrote:
-------------------------------------------------------
> Ahem.... as described in the welcome post, try and
> add your code in a code tag. Like this:

Ahem again...!
avatar Re: Tips And Tricks using php
February 01, 2010 09:17AM
I wonder what made other guys Choose PHP or Any other programming language at unisa because damn is difficult on your own

gbakamela [77234715]
Re: Tips And Tricks using php
February 01, 2010 09:51AM
Hi there gcobani, well the love for geekery and nerdism pushes people to study wierd codes etc, by the way, how's everyone , I live in Joburg and hope to write an improved social network site wnen I am done with PHP, I'll do something that will leave Facebook looking like a walk in the park...Lol
avatar Re: Tips And Tricks using php
February 01, 2010 02:24PM
Desmond me and you it seems like we are ambitious NEH! I live few kilos outside Kimberley. my thing is that i love C++ but after I started working for government got a small problem that i want to solve All social, entertainment and etc website are blocked and i also heard that PHP scripts are the solution you can write script that bypass local server Proxy! imagine if you can browse the net without any restrictions I mean how NYC is that dudedrinking smiley

gbakamela [77234715]
avatar Re: Tips And Tricks using php
February 02, 2010 12:01PM
working with strings and switch or nested is else statement give me headaches not to forget about boolens
Language: PHP
<?php $name = ';Mary';; $name2 = ';Ana';; $a = ';My friends are called $name and $name2';; print $a . "<br>"; eval("a$\ = \"$a\";"); print a$ . "<br>"; ?>
can anyone explain wats wrong with this code

gbakamela [77234715]
Re: Tips And Tricks using php
February 02, 2010 01:23PM
Getting some parse errors when I try it, I think something is wrong with the variable a$ or $a, will get a solution b4 long
avatar
Mac
Re: Tips And Tricks using php
February 02, 2010 01:54PM
I'm not going to discuss code outside the course (I will but then I will charge you smiling smiley ) BUT

This code is similar to the example code in the PHP manual on the eval function.

Language: PHP
eval("a$\ = \"$a\";"); must be eval("$a = \"$a\";");


In any event, rather focus on the exercises smiling smiley
avatar Re: Tips And Tricks using php
February 07, 2010 10:06AM
Hi,

Just a little correction,
Language: PHP
eval("$a = \"$a\";");

must be

Language: PHP
eval("\$a = \"$a\";");

You need to escape (\) the $ for the first variable in the eval().

My suggestion on using eval() is using single quotes and do in-line concatenation of variables:

Language: PHP
eval(';$a = "';.$a.';";';);

Much less confusing.

Regards


Unitam logica falsa tuam philosophiam totam suffodiant - May faulty logic undermine your entire philosophy
avatar Re: Tips And Tricks using php
February 23, 2010 11:48AM
here's other site that will help http://www.developertutorials.com/tutorials/php/

gbakamela [77234715]
avatar Re: Tips And Tricks using php
May 04, 2010 11:23AM
cache a file
Language: PHP
<?php class Cache { const DIRECTORY = ';../cache/';; const TIME = 600;   protected $cache_directory;   private $using_cached_file = false;   public function __construct( $cache_directory = null , $cache_time = null ) { ob_start(); $this->cache_directory = isset( $cache_directory ) ? ( is_string( $cache_directory ) ? $cache_directory : self::DIRECTORY ) : self::DIRECTORY; $cache_file = $this->get_cache_name(); if ( file_exists( $cache_file ) && ( time() - ( isset( $cache_time ) ? ( is_int( $cache_time ) ? $cache_time : self::TIME ) : self::TIME ) < filemtime( $cache_file ) ) ) { include( $cache_file ); $this->using_cached_file = true; exit; } }   public function __destruct() { if ( !$this->using_cached_file ) { $file_buffer = fopen( $this->get_cache_name() , ';w'; ); fwrite( $file_buffer , ob_get_contents() ); fclose( $file_buffer ); } ob_end_flush(); }   protected function get_cache_name() { return $this->cache_directory . sha1( $_SERVER[';REQUEST_URI';] ) . ';.html';; } } ?>

gbakamela [77234715]
Sorry, only registered users may post in this forum.

Click here to login