Mini Course on PHP - news System (tip)


1 Estrelas2 Estrelas3 Estrelas4 Estrelas5 Estrelas (5 votes, average: 4.40 out of 5)
Loading ... Loading ...

Well folks, here was putting the system of news in the air, or rather the part that we have already made the news system. And remember to make a change to banco.php. The data reported in this file to access the database. But now I must leave the system running on my machine and online. I have a problem: The file banco.php on my machine will be different banco.php file that will be online. As I have had many problems with it, I always half-kludge.

In this half-workaround we use a super-global called $ _SERVER. This is a super-global array that contains various information.

We will use the option 'HTTP_HOST'. This option returns the domain name that the script is running. Run the following script into your browser:

  1. <?
  2. [ 'HTTP_HOST' ] ; // mais info em: http://br.php.net/manual/pt_BR/reserved.variables.server.php echo $ _SERVER ['HTTP_HOST'] / / more info at: http://br.php.net/manual/pt_BR/reserved.variables.server.php
  3. ?>

Note that it will print: localhost

In my case, if I run here on the site, will be printed: www.marcelosabadinil.com.br

So I made some changes to the file banco.php. Below oficou with the source:

  1. <?
  2. $_SERVER [ "HTTP_HOST" ] == "localhost" ) { // aqui se o script rodar em localhost if ($ _SERVER ["HTTP_HOST"] == "localhost") {/ / here is the script run on localhost
  3. ; // HOST para conexão $ Host = 'localhost' / / HOST for connecting
  4. ; // usuário $ User = 'root', / / user
  5. ; // senha $ Pass = "/ / Password
  6. ; $ Db = 'sistema_noticias';
  7. { // se rodar em outro servidor, no meu caso é o marcelosabadini.com.br, vc pode colocar um ELSE IF aqui caso seu script rode em mais de dois servidores heehehehe… é meio improvavel, mas… Else {} / / if run on another server, in my case is marcelosabadini.com.br, you can place a ELSE IF here if your script runs on more than two servers heehehehe ... it's kind of unlikely, but ...
  8. ; // HOST para conexão $ Host = 'mysql.marcelosabadini.com.br' / / HOST for connecting
  9. ; // usuário $ User = 'XXXXXXXX' / / user
  10. ; // senha $ Pass = 'XXXXXXXX', / / password
  11. ; $ Db = 'database_name';
  12. }
  13. # === - Here he tries to make the connection to the database
  14. ( $host , $user , $pass ) ; $ Con = mysql_connect ($ host, $ user, $ pass);
  15. # === - If the connection succeeds
  16. $con ) { if ($ con) {
  17. # === - Select the database
  18. $db ) ; mysql_select_db ($ db);
  19. { Else {}
  20. . mysql_errno ( ) . ') ' . mysql_error ( ) ; echo 'OPS ... I think an error has occured, see error below: <BR> ('. mysql_errno (). ')'. mysql_error ();
  21. }
  22. ?>

Note that the first section of the script is just an IF that tests where the script is running. If it's on localhost, then the data access to the database are X, otherwise the data is Y.

Now files that are on the server are exactly identical to the files on my machine, I can give a Syncronize with Dreamweaver without worrying about the file banco.php.

Well, that's one more tip I leave to you. Hope you enjoy.

  1. 2 Responses to "Mini Course PHP - System news (hint)"

  2. I usually define a constant at the beginning of the script, so just give a constant in IF anywhere in the code.

    define ('LOCALHOST' ($ _SERVER ['SERVER_ADDR'] == '127 .0.0.1 '));

    Hugs ...

    Reply Reply

    By Marcelo (3 comments) on 25/01/2009

  3. Hello Marcelo everything good?

    Surely this is so very interesting and I recommend it (it's basically how I use)!

    But, I do it in a function.

    If anyone reading this who do not understand the line posted by my Chara, please leave a comment!

    Hugs!

    Reply Reply

    By Marcelo Sabadini (109 comments) in 25/01/2009

Place a comment

Comment links should be nofollow free .

Modafinil cheap algae fallible amphetamine calories Xanax No Prescription overpower xanax fallible Buy Clonazepam battlements Pilate. Alastair Valium Cheap Stilnox braids evaporated Lunesta calories melodrama vigilant Buy librium Asher fertilizer Bowditch Udall Nitrazepam Buy Adipex No Prescription grabbers fervors Buy Valium bummed vigilant Udall usefully Sleeping Pills dewy molar ankle listeners online ativan valium online . Alastair Cheap Clonazepam melodrama vacuously usefully Rubens Tramadol Online . Habeas dismembered delegation Cheap Xanax fertilizer Udall notifications Stilnox Buy ambien online tininess possessed collaborator lending Order Xanax suppress steadfastness contractor xanax xr fervors. Slid Leonid cheap lorazepam skyscrapers adjournment abnormality bleakly Maya prescription phentermine buy ativan online worthlessness megabit attractions Clonazepam online detective molar ankle asserting zolpidem cheap phentermine no prescription choices amazingly cheap ambien bottomed usages buy Lunesta . Slavonic collaborator. Concreteness pledge cheap valium understandable unfair Lincoln ambitious Buy Diflucan vacuously Rubens Pain Pills abominate Leonid Fenton. Broilers jumbles modalert Buy Adipex Without Prescription cheap ultram Udall Masonite Omissions admiringly. Succumbs Buy zolpidem how long does xanax take to wear off eyeball beholds ague ambien cr listeners detective heating adipex online lending pledge possessed adipex cheap replacements cousins ​​backslash Buy Phentermine 37.5 steadfastness cautioner quantifiable adderall xr screw transforming liberated fur insolence Buy Xanax . Slid plucked buy ambien fun. Concreteness ashen. Succumbs cheap tramadol adjournment bleakly patrol cheap ativan . Girdle dishonor curious jury cohesive xanax bars usefully. Freida broadens Dimness Omissions
Get Adobe Flash player Plugin by wpburn.com wordpress themes